[omniORB] ServantActivator never destroyed?

Adam Groszer adamg@mailbox.hu
Thu Mar 27 09:33:02 2003


This is a multi-part message in MIME format.

------=_NextPart_000_0004_01C2F44B.BE792490
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Yes, Duncan you're right, I figured it out last night also.
I'm just a beginner.

But here comes an extended ServantActivator example fully commented.
Is it maybe good to include it in the distribution to help other beginners?

BR,

Adam

-----Original Message-----
From: omniorb-list-admin@omniorb-support.com
[mailto:omniorb-list-admin@omniorb-support.com]On Behalf Of Duncan
Grisby
Sent: Wednesday, 2003 March 26. 6:31 PM
To: Adam Groszer
Cc: Omniorb-List@Omniorb-Support. Com
Subject: Re: [omniORB] ServantActivator never destroyed?


On Monday 24 March, Adam Groszer wrote:

> My problem is that it looks like, ServantActivator of childPOA never gets
> destroyed, so all objects kept in the objects dict also never get garbage
> collected.

Your ServantActivator is itself activated in the Root POA. You don't
deactivate it, either explicitly or by destroying the Root POA, so the
servant is never released.

Cheers,

Duncan.

--
 -- Duncan Grisby         --
  -- duncan@grisby.org     --
   -- http://www.grisby.org --
_______________________________________________
omniORB-list mailing list
omniORB-list@omniorb-support.com
http://www.omniorb-support.com/mailman/listinfo/omniorb-list

------=_NextPart_000_0004_01C2F44B.BE792490
Content-Type: text/plain;
	name="servantactivator_ext.py"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="servantactivator_ext.py"

#!/usr/bin/env python=0A=
=0A=
# Example of using a ServantActivator.=0A=
#=0A=
# This program behaves just like the echo server, except that the=0A=
# servant object is not activated until the first request on the=0A=
# object.=0A=
#=0A=
# If you run with a -l command line argument, the program will make a=0A=
# number of local calls to the object, showing that the activator runs=0A=
# in the local, as well as the remote, case.=0A=
=0A=
=0A=
import sys, time=0A=
from omniORB import CORBA, PortableServer, PortableServer__POA=0A=
=0A=
import _GlobalIDL, _GlobalIDL__POA=0A=
=0A=
class Echo_i (_GlobalIDL__POA.Echo):=0A=
    def __init__(self):=0A=
        print "Echo_i created.",self=0A=
=0A=
    def __del__(self):=0A=
        print "Echo_i deleted.",self=0A=
=0A=
    def echoString(self, mesg):=0A=
        print "Echo_i.echoString() called with message:", mesg=0A=
        return mesg=0A=
    =0A=
    def _incarnate_called(self):=0A=
        print 'Echo_i._incarnate_called',self=0A=
    =0A=
    def _ether_called(self):=0A=
        print 'Echo_i._ether_called',self=0A=
=0A=
class ServantActivator_i (PortableServer__POA.ServantActivator):=0A=
    def __init__(self, collection):=0A=
        # Remember the object dictionary, we'll look up the servants =
from this=0A=
        self.collection =3D collection=0A=
        =0A=
        print 'ServantActivator created',self=0A=
        =0A=
    def incarnate(self, oid, poa):=0A=
        print "incarnate(): oid:", oid, "poa:", poa._get_the_name()=0A=
        =0A=
        # Look up the servant from the object dictionary=0A=
        servant =3D self.collection[oid]=0A=
        print "  object:", servant=0A=
        =0A=
        servant._incarnate_called()=0A=
        =0A=
        return servant=0A=
=0A=
    def etherealize(self, oid, poa, servant, cleanup_in_progress,=0A=
                    remaining_activations):=0A=
        print "etherealize called"=0A=
        try:=0A=
            name =3D poa._get_the_name()=0A=
        except CORBA.OBJECT_NOT_EXIST, ex:=0A=
            name =3D "<dead poa>"=0A=
        print "  etherealize(): oid:", oid, "poa:", name=0A=
        =0A=
        servant._ether_called()=0A=
    =0A=
    def __del__(self):=0A=
        print 'ServantActivator deleted',self=0A=
=0A=
def newobj(objects, poa):=0A=
    childobj =3D Echo_i()=0A=
    =0A=
    corbaId =3D CORBA.id(childobj.__class__)=0A=
    =0A=
    # Generate an OID and object reference this will identify our objects=0A=
    # remember it, we'll need it later=0A=
    childobj._oid =3D str(id(childobj))=0A=
    childobj._objref =3D poa.create_reference_with_id(childobj._oid, =
corbaId)=0A=
    =0A=
    objects[childobj._oid] =3D childobj=0A=
    =0A=
    # uncomment this to have the IOR's printed=0A=
    #print orb.object_to_string(childobj._objref)=0A=
=0A=
=0A=
# Initialise the ORB and activate the root POA.=0A=
orb =3D CORBA.ORB_init(sys.argv, CORBA.ORB_ID)=0A=
rootPOA =3D orb.resolve_initial_references("RootPOA")=0A=
poaManager =3D rootPOA._get_the_POAManager()=0A=
poaManager.activate()=0A=
=0A=
# Create a child POA with the right policies for a ServantActivator=0A=
ps =3D [rootPOA.create_id_assignment_policy(PortableServer.USER_ID),=0A=
        rootPOA.create_servant_retention_policy(PortableServer.RETAIN),=0A=
        =
rootPOA.create_request_processing_policy(PortableServer.USE_SERVANT_MANAG=
ER)]=0A=
=0A=
# Child POA created with the same poaManager as the rootPOA's=0A=
childPOA =3D rootPOA.create_POA("MyPOA", poaManager, ps)=0A=
=0A=
# Start with an empty object dictionary=0A=
objects =3D {}=0A=
=0A=
# Create the ServantActivator and set it as the child's ServantManager=0A=
# the ServantActivator is activated on the rootPOA=0A=
sai =3D ServantActivator_i(objects)=0A=
sao =3D sai._this()=0A=
childPOA.set_servant_manager(sao)=0A=
=0A=
# Create object references with servants=0A=
for i in range(10):=0A=
    newobj(objects, childPOA)=0A=
=0A=
# Run, or do some local calls...=0A=
if not (len(sys.argv) > 1 and sys.argv[1] =3D=3D "-l"):=0A=
    orb.run()=0A=
=0A=
time.sleep(1)=0A=
=0A=
print "Calling..."=0A=
=0A=
# Select any object from the dictionary=0A=
eo_obj =3D objects.items()[5][1]=0A=
eo =3D eo_obj._objref=0A=
=0A=
# On this invocation, the servant will be activated=0A=
print eo.echoString("Hello from same address space")=0A=
time.sleep(1)=0A=
=0A=
# This invocation uses the local case optimisation, since the servant=0A=
# is now active=0A=
print eo.echoString("Hello again")=0A=
time.sleep(1)=0A=
=0A=
# Deactivating the object causes a call to etherealize(), and the=0A=
# servant is deleted.=0A=
print "Deactivating the object..."=0A=
childPOA.deactivate_object(eo_obj._oid)=0A=
print "Deactivated."=0A=
time.sleep(1)=0A=
=0A=
# This invocation activates the servant again=0A=
print eo.echoString("Hello again again")=0A=
time.sleep(1)=0A=
=0A=
# Remember the servant activator's oid=0A=
manager =3D childPOA.get_servant_manager()=0A=
manager_id =3D rootPOA.reference_to_id(manager)=0A=
=0A=
# Destroying the child POA causes the servant to be etherealized again=0A=
print "Destroying POA..."=0A=
childPOA.destroy(1, 1)=0A=
print "Destroyed."=0A=
=0A=
# deactivate the servant activator object=0A=
print "Destroying ServantActivator..."=0A=
rootPOA.deactivate_object(manager_id)=0A=
print "Destroyed."=0A=
=0A=
# Clean up the ORB=0A=
orb.destroy()=0A=

------=_NextPart_000_0004_01C2F44B.BE792490--