Long-Lived IIOP.NET Objects...
I have been working with IIOP.NET, a CORBA toolkit for .NET, a bit more than with Using Multiple Vendor's ORBs with Name Services. While my test application was working great, my actual application was not, however.
The server component started up, instantiated a CORBA object, and saved the IOR into the registry. Then my client component would start up and take the IOR from the registry, send a message to the CORBA server, do some data processing for about 15-30 minutes, and send another message to the CORBA server. This issue I ran into is that usually the first message made it to the server, but the second one rarely did, with the error message:
- CORBA system exception : omg.org.CORBA.OBJECT_NOT_EXIST, completed: Completed_No minor: 0 omg.org.CORBA.OBJECT_NOT_EXIST: CORBA system exception : omg.org.CORBA.OBJECT_NOT_EXIST, completed: Completed_No minor: 0
- Server stack trace:
- Exception rethrown at [0]:
- at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
- at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
- ...
At this level of detail, it would appear that something goes wonky on the client side, since the first message usually gets to the server, however, I also failed to mention that I usually started the server and client at the same time. When I did not start the server at the same time of the client, I would get the exception above.
In light of this detail, it became very obvious that I had an object lifetime issue on the server. Coming from more of a Java CORBA experience, I had assumed that the lifetime of the object would by-default be long-lived, however, it appears that this is not the case. To make your IIOP.NET objects long-lived (or to control the default behaviour), your objects that derive from System.MarshalByRefObject
must override the method InitializeLifetimeService()
. The follow makes the object live forever:
- public class TimeImpl : System.MarshalByRefObject, TimeTools.Time {
- // ...
- public override object InitializeLifetimeService() {
- return null;
- }
- // ...
- }
Since my objects are all long-lived, the above fixed my problem. The documentation for InitializeLifetimeService() does, however, have some other examples in the event that you need more fine-grained control.