[omniORB] Destroy objects

Michael omniorb at bindone.de
Thu Apr 24 16:21:59 BST 2008


Silly & Chrischi wrote:
> Hello,
> 
> I create an object with a factory-method. What have i had to call on the client, do destroy the object on the server? Every class has an destructor but I don't know what to call to start the destructor.
> 
> Thank you.
> 
> 
> _______________________________________________
> omniORB-list mailing list
> omniORB-list at omniorb-support.com
> http://www.omniorb-support.com/mailman/listinfo/omniorb-list

You have to create an explicit destroy method on the object (also in IDL), that:
- deactivates the object in the poa
- deletes the object

(you might want to use RefCountServantBase and make destroy just decrement the reference
count and set a deleted flag on the object)

Make sure you do not shoot yourself in multi threading scenarios.

Example:
IDL:
interface Xyz
{
  unsigned long getId();
  void destroy();
};

class Xyz_impl: virtual public POA_Test::Xyz, virtual public
PortableServer::RefCountServantBase
{
  ZThread::RecursiveMutex _lock;
  bool _destroyed;
  PortableServer::POA_ptr _poa;

public:
...
  CORBA::ULong getId()
  {
    ZThread::Guard<ZThread::RecursiveMutex> g(_lock);
    if (_destroyed) throw CORBA::OBJECT_NOT_EXIST();
    // do sth useful
  }

  void destroy()
  {
    ZThread::Guard<ZThread::RecursiveMutex> g(_lock);
    if (_destroyed) return; // might also want to throw here
    // .. cleanup
    _destroyed = true;
    if (!_poa->non_existent())
    {
      PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
      _poa->deactivate_object(oid);
    }
  }
}


Please note that this example is out of context and might not work 1:1 in your setup



More information about the omniORB-list mailing list