[omniORB] Object life time
Jerome.Kerdreux at finix.eu.org
Jerome.Kerdreux at finix.eu.org
Fri Aug 15 00:22:23 BST 2003
In my current application (which is my first serious corba code), the servant
have a couple of objects (mainly devices and services). So i wrote too
class Device_i and Service_i. But in fact during the long running process
devices can go on or new device can arrive.
So to avoid the need to recreate a lot of Device_i at each client request, i
maintain a list of already available Device_i in the servant.
This could sound strange but i don't want to create a lot of Device_i since
they are never release (free memory) in the servant ? (perhaps i'm wrong
w/ that)
The previous code was something like this:
----------------------------------------------------------
class Device_i( MyName__POA.Device) :
.....
def __init__(self, device):
self._device = device
class ControlPoint_i(MyName__POA.ControlPoint):
....
def getDevices(self):
r = []
for device in globalDevList:
r.append( Device_i ( dev) )
return [ o._this() for o in r]
-----------------------------------------------------------
As you can see this create a bounch of Device_i .. and
- creation is long
- eat some memory ?
- what to do is the device isn't available anymore because it
will be a valid corba object
So i decide to do something like this:
------------------------------------------------------------
class CtrlPoint_i(MyName__POA.ControlPoint):
def __init__(self,ctrlPoint):
self._devices = []
def getDevices(self):
result = []
real = copy.copy(globalDevList)
# cleaning the device list if need
for dev in self._devices:
if dev._device not in real:
self._devices.remove(dev)
else:
real.remove(dev._device)
# add new device if needed
for dev in real:
self._devices.append( Device_i( dev ) )
return [o._this() for o in self._devices]
------------------------------------------------------------
As you imagine, now if a client request the devices
it will get the previous Device_i () if they are again
valid (still in the globalDevList) and new one if needed.
So my question is :
Is this a common way to do this or i'm going in the wrong way ?
Should i "cache" the previous objectref too ? (._this() ) and if so
how could i find the Device_i instance corresponding for a given
object ref ?
Many thanks for any suggestion.
PS: For my job i need to write a howto use OmniORB and OpenORB
( java ), perhaps some of you may be interested by this
PS: Apologize for my awfull english and many thanks to Duncan for
his previous anser
More information about the omniORB-list
mailing list