next up previous
Next: Activation Mode Per Method Up: Activation Modes Previous: Activation Mode Persistent

Activation Mode Unshared

Unshared servers are similar to shared servers. The difference is that each instance of an unshared server can only serve one object instance. That is for N objects you need N running instances of an unshared server.

Furthermore you cannot use impl_is_ready() and deactivate_impl() but have to use obj_is_ready() and deactivate_obj() instead. Here is the main() function of an unshared account server:

 1: // file account_server2.cc
 2:
 3: #include "account.h"
 4:
 5: class Account_impl : virtual public Account_skel
 6: {
 7:   // unchanged, see section "MICO Application"
 8:   // ...
 9: };
10: 
11: 
12: int main( int argc, char *argv[] )
13: {
14:   // ORB initialization
15:   CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "mico-local-orb" );
16:   CORBA::BOA_var boa = orb->BOA_init( argc, argv, "mico-local-boa" );
17: 
18:   Account_impl* server = new Account_impl;
19:
20:   boa->obj_is_ready (server, CORBA::ImplementationDef::_nil());
21:   orb->run ();
22:   CORBA::release( server );
23:   return 0;
24: }

The exit() method would look like this in an unshared server:

  // account.idl
  class Account_impl : virtual public Account_skel {
    ...
  public:
    ...
    virtual void exit ()
    {
      CORBA::BOA_var boa = _boa();
      CORBA::ORB_var orb = _orb();
      boa->deactivate_obj (this);
      orb->shutdown (TRUE);
    }
  };

Although an unshared server instance can only serve one object instance it can create more than one object instance. Imagine for instance a bank object

  // bank.idl
  interface Bank {
    Account create ();
    void destroy (in Account account);
  };

that can create new account objects and destroy account objects that are no longer neededgif. The implementation of the create() method in an unshared server would look like this:

 1:  // bank_server.cc
 2:  class Bank_impl : virtual public Bank_skel {
 3:    ...
 4:  public:
 5:    ...
 6:    virtual Account_ptr create ()
 7:    {
 8:      Account_ptr account = new Account_impl;
 9:
10:      CORBA::BOA_var boa = _boa();
11:      boa->deactivate_obj (account);
12:
13:      return Account::_duplicate (account);
14:    }
15:  };

Note that line 11 calls deactivate_obj() on the newly created objectgif. This will tell the BOA daemon that you are not going to serve this object, instead a new server instance has to be activated for serving the newly created account object. For this to work you must of course implement saving and restoring for your objects as described in section 4.3.5.

If you need access to the newly created account object from within the server where it was first created you need to take special actions. The reason for this is that the created account object is initially an account object implementation (Account_impl), but in order to access the moved account object in the other server you need an account stub (Account_stub). Here is how to create this stub:

 1:  // bank_server.cc
 2:  class Bank_impl : virtual public Bank_skel {
 3:    ...
 4:  public:
 5:    ...
 6:    virtual Account_ptr create ()
 7:    {
 8:      CORBA::BOA_var boa = _boa();
 9:      CORBA::ORB_var orb = _orb();
10:
11:      Account_ptr account = new Account_impl;
12:      boa->deactivate_obj (account);
13:
14:      // turn 'account' into a stub
15:      CORBA::String_var ref = orb->object_to_string (account);
16:      CORBA::release (account);
17:      CORBA::Object_var obj = orb->string_to_object (ref);
18:      account = Account::_narrow (obj);
19:
20:      // now you can invoke methods on (the remote) 'account'
21:      account->deposit (100);
22:
23:      return Account::_duplicate (account);
24:    }
25:  };

The demo/account3 directory contains a complete example for an unshared server that creates more than one object.



MICO
Tue Nov 10 11:04:45 CET 1998