Discussion:
[omniORB] Question about passing arguments to preinvoke()
Michael Shearer
2006-06-13 20:25:12 UTC
Permalink
Hi!



I'm trying to figure out a nice and clean way of passing arguments to
the preinvoke primitive when using a CORBA servant locator. I have an
object that needs two parameters in the constructor when creating the
instance. Obviously I could add a primitive to initialize this data
separately but ideally I'd like some way of passing the 2 arguments to
the preinvoke. What I'm doing right now is basically setting 2 member
variables in the servant locator which are used in the preinvoke. These
2 member variables are currently locked with a mutex as I'm not sure if
the POA ensures that no other object references will be requested before
the previous one has been dispatched. Is that the best I can do or am I
missing something? Here's what it looks like in a nutshell:



Class Line :

public POA_LineInterface,

public PortableServer::RefCountServantBase,

{

public:

Line(string mac, string userAgent);

virtual ~Line();



private:

Line();

};



class LineMgr :

public POA_PortableServer::ServantLocator

{



public:

// CORBA servant locator

PortableServer::Servant

preinvoke(const PortableServer::ObjectId& oid,

PortableServer::POA_ptr adapter, const char* operation,

PortableServer::ServantLocator::Cookie& the_cookie)

{

lines[macM] = new Line(macM, userAgentM);



return lines[macM];

}



void

postinvoke(const PortableServer::ObjectId& oid,

PortableServer::POA_ptr adapter, const char* operation,

PortableServer::ServantLocator::Cookie the_cookie,

PortableServer::Servant the_servant)

{

the_servant->_remove_ref();

}



LinePtr getLine(string mac, string userAgent)

{

mutex.lock();



macM = mac;

userAgentM = userAgent;



CORBA::Object_var obj =
root_poaM->create_reference("IDL:LineInterface:1.0");



Mutex.unlock();



return lines[mac];

}



private:

string macM;

string userAgentM;

map<string, LinePtr> lines;

};



Note: LinePtr is a reference counting class.



I would appreciate any help!



Thanks,



Mike





Michael Shearer

New Product Development

Aastra Telecom US, CVX Division

8 Federal Street

Billerica, MA, USA, 01821-3570
* Phone (978) 436-4248

* Fax (978) 436-4233
* Internet Mail ***@aastra.com
* Web www.aastra.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20060613/85c846df/attachment.htm
Duncan Grisby
2006-06-14 20:27:15 UTC
Permalink
Post by Michael Shearer
I'm trying to figure out a nice and clean way of passing arguments to
the preinvoke primitive when using a CORBA servant locator. I have an
object that needs two parameters in the constructor when creating the
instance. Obviously I could add a primitive to initialize this data
separately but ideally I'd like some way of passing the 2 arguments to
the preinvoke. What I'm doing right now is basically setting 2 member
variables in the servant locator which are used in the preinvoke. These
2 member variables are currently locked with a mutex as I'm not sure if
the POA ensures that no other object references will be requested before
the previous one has been dispatched. Is that the best I can do or am I
I'm confused about what you're trying to do. The whole point of a
servant locator is that the servant is created/located on demand, when a
client calls an operation on the object. preinvoke can thus be called at
any time, as determined by the clients. How do you set the member
variables at the right time? I suspect that you perhaps don't want to
be using a servant locator at all.

Can you explain what you are doing that makes you think you need to do
this?

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Michael Shearer
2006-06-14 21:00:01 UTC
Permalink
Hi Duncan,

Thanks for the quick response. I guess I didn't really need a servant
locator after all. The problem I was having was that my server
application was sometimes deleting the servant before the client was
done with it. Even when using PortableServer::RefCountServantBase
reference counter.

When I saw the servant locator and servant activator models, it seemed
to make more sense at the time because it would tell you when the client
was done so you could then in turn cleanup and delete the resource.
However, after much research I found this great website that explains
this whole issue. http://www.lenholgate.com/archives/000343.html. All
I really needed was a reference counter wrapper in my own class that
calls deactivate_object and _remove_ref() on the RefCountServantBase
class when it is done. Works like a charm now.

Thanks,

Mike

-----Original Message-----
From: Duncan Grisby [mailto:***@grisby.org]
Sent: Wednesday, June 14, 2006 10:27 AM
To: Michael Shearer
Cc: omniorb-***@omniorb-support.com
Subject: Re: [omniORB] Question about passing arguments to preinvoke()
Post by Michael Shearer
I'm trying to figure out a nice and clean way of passing arguments to
the preinvoke primitive when using a CORBA servant locator. I have an
object that needs two parameters in the constructor when creating the
instance. Obviously I could add a primitive to initialize this data
separately but ideally I'd like some way of passing the 2 arguments to
the preinvoke. What I'm doing right now is basically setting 2 member
variables in the servant locator which are used in the preinvoke.
These
Post by Michael Shearer
2 member variables are currently locked with a mutex as I'm not sure
if
Post by Michael Shearer
the POA ensures that no other object references will be requested
before
Post by Michael Shearer
the previous one has been dispatched. Is that the best I can do or am
I
I'm confused about what you're trying to do. The whole point of a
servant locator is that the servant is created/located on demand, when a
client calls an operation on the object. preinvoke can thus be called at
any time, as determined by the clients. How do you set the member
variables at the right time? I suspect that you perhaps don't want to
be using a servant locator at all.

Can you explain what you are doing that makes you think you need to do
this?

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Duncan Grisby
2006-06-14 21:42:05 UTC
Permalink
Post by Michael Shearer
When I saw the servant locator and servant activator models, it seemed
to make more sense at the time because it would tell you when the client
was done so you could then in turn cleanup and delete the resource.
Possibly you understand this now, but to be clear, servant locators do
not tell you then the client is "done", as in finished with the object,
merely when it has finished the particular method it is calling. The
servant locator is invoked used on every single call the client makes.
Post by Michael Shearer
However, after much research I found this great website that explains
this whole issue. http://www.lenholgate.com/archives/000343.html. All
I really needed was a reference counter wrapper in my own class that
calls deactivate_object and _remove_ref() on the RefCountServantBase
class when it is done. Works like a charm now.
Hmm. Len updated those articles based on some feedback he received when
he wrote them, but I still think they confuse at least as much as they
enlighten. You might like to read the discussions that arose when Len
wrote the articles. Look for messages with the subject "From COM to
CORBA" in these two months of mailing list archive:

http://www.omniorb-support.com/pipermail/omniorb-list/2001-February/
http://www.omniorb-support.com/pipermail/omniorb-list/2001-March/


If you haven't got it already, I strongly advise that you get "Advanced
CORBA Programming with C++" by Michi Henning and Steve Vinoski. It does
quite a good job of explaining the CORBA object model, which will help
you understand these kinds of issues.

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Loading...