[omniORB] omniORBpy: Pickling Objects
Robert Sander
omniorb@beteigeuze.cs.tu-berlin.de
Thu, 10 Feb 2000 21:14:30 +0100
On Fri, Jan 14, 2000 at 04:30:11PM +0000, Duncan Grisby wrote:
> On Friday 14 January, Robert Sander wrote:
>
> > I am working with omniORBpy and ZOPE (www.zope.org), which is
> > mainly a object database. The ZOPE mechanism relies on
> > pickling the objects to store them. For now, the storing
> > of CORBA objects is not possible, because they have no pickle
> > interface. Could that be made possible? IMHO it is only
> > necessary to store the IOR string retrieved by
> > orb.object_to_string when pickling. At unpickle the IOR must
> > be resolved, but that should work if the object on the other
> > side is still alive.
>
> The following patch allows pickle to work for object references. Note
> that if you hold a reference to an object in your own address space,
> pickling the object reference just pickles the reference, not the
> servant object itself. This may or may not be what you expect.
>
> RCS file: /project/omni/cvsroot/omniORBpy/python/omniORB/CORBA.py,v
> retrieving revision 1.15
> diff -u -r1.15 CORBA.py
> --- CORBA.py 1999/12/07 12:35:33 1.15
> +++ CORBA.py 2000/01/14 16:27:48
> @@ -586,6 +586,15 @@
> def __del__(self):
> pass
>
> + def __getstate__(self):
> + return ORB_init().object_to_string(self)
> +
> + def __setstate__(self, state):
> + o = ORB_init().string_to_object(state)
> + self.__dict__.update(o.__dict__)
> + def dummy(): pass
> + o.__del__ = dummy
> +
> def _get_interface(self):
> # ***
> raise NO_IMPLEMENT
>
Sorry for answering that late and the resulting fullquote, but I was busy
writing some theoretical aspects on my work down to paper ;-)
As long as I can tell it seems to work. Testing to the bone is not so easy to
me because my server object I want to pickle is an object in real use, so I
cannot let it die.
This must be somewhere caught, the case when the pickled object is no more. I
think this generates an exception with the first use and then you have to
reinit the reference (if the object now "lives" on another host or port). But
this must be done individually, because the unpickled object itself is not
able to tell or handle this situation.
The other thing I notice is that a TCP connection is still open when the
request is ready and ZOPE should have dumped the object to its database. I do
not know if this is a problem or not (at least not to me until now) but I
think it could be better to cut this connection and to reestablish it when the
object is unpickled. This implies that the object is pickled just before it is
deleted, which may not be the normal case, so I see no solution yet.
Keep up the good work!
Greetings
--
Robert Sander www.gurubert.de