AW: [omniORB] Destroy objects
Silly & Chrischi
christian83 at gmx.li
Fri May 9 12:29:33 BST 2008
Hello,
what do I have to include to use ZThread::RecursiveMutex?
Andi t doesn't work. I tested your code send to me and I put in the destructor of my object the following:
Administrator_impl::~Administrator_impl(void) {
cout << "destroy";
delete mysql_;
}
But I don't see the "destroy" in my console. And the next, if I set my object in the client to admin->destroy(); I can woork with this object later on, but I thought it doesn't exists anymore. So what do I do wrong?
Thanks.
-----Ursprüngliche Nachricht-----
Von: Michael [mailto:omniorb at bindone.de]
Gesendet: Donnerstag, 24. April 2008 15:22
An: christian83 at gmx.li
Cc: omniorb-list at omniorb-support.com
Betreff: Re: [omniORB] Destroy objects
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