????: [omniORB] Object lifetime/release & Java GC confusion

Jelle jelle at defekt.nl
Wed Sep 17 00:10:55 BST 2003


Quoting wanghongling at PAIC.com.cn:
> please see the example of Borland visibroker ,maybe it can help you!

First of all I'd would like to thank you for your time, this did help
me, but I still have some questions... sorry ;-)

I've looked at the example but this only shows creation of the Account
servants (?), how are the Account servants deleted?


  void put(const char* name, PortableServer::ServantBase_ptr servant)

Why is there a ServantBase_ptr used where, and not a Account_ptr?


  servant->_add_ref();

What does this do? is this a reference counter for the client references?
Does _this() on the Servant implementation do the same thing?



    Bank::Account_ptr open(const char* name) {
      // Lookup the account in the account dictionary. 
      PortableServer::ServantBase_var servant = _accounts.get(name);
     
      if (servant == PortableServer::ServantBase::_nil()) {
        // Make up the account's balance, between 0 and 1000 dollars.
        CORBA::Float balance = abs(rand()) % 100000 / 100.0;
  
        // Create the account implementation, given the balance.
        servant = new AccountImpl(balance);

        // Print out the new account
        cout << "Created " << name << "'s account." << endl;

        // Save the account in the account dictionary.
        _accounts.put(name, servant);
      }

      try {
        // Activate it on the default POA which is root POA for this servant
        PortableServer::POA_var default_poa = _default_POA();
        CORBA::Object_var ref = default_poa->servant_to_reference(servant);
        Bank::Account_var account = Bank::Account::_narrow(ref);

        // Print out the new account
        cout << "Returning " << name << "'s account: " << account << endl;

        // Return the account
        return Bank::Account::_duplicate(account);
      }

Can you explain why the piece of code with default_poa->servant_to ...
is used? Why not return servant->_this() right after _accounts.put()?

thanks a lot,
Jelle



More information about the omniORB-list mailing list