Brendan Tompkins

Sponsors

The Lounge

Wicked Cool Jobs

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Object Persistence and Remoting...

I discovered something interesting this week.  Here's the scenario. I have a windows service which houses a singleton object that has live camera statistics generated from our gate traffic camera here at the port.  What this service does is

  1. Monitors a directory for file changes (camera images updated every minute)
  2. Does some fuzzy image analysis on the image to get a live traffic “count”
  3. Stores a copy of the image in a byte array

The singleton object is marshaled like so:

// Configure Remoting

ChannelServices.RegisterChannel(new TcpChannel(8001));

RemotingConfiguration.RegisterWellKnownServiceType(typeof(VIT.Common.Classes.GateStatusRemotable), "GateStatus", WellKnownObjectMode.Singleton);

RemotingServices.Marshal(m_GateStatus, "GateStatus");

Now, I have need to remote to this object from two places, a windows application that acts as a service controller, and a web control that actually consumes the images and data, and publishes it on the web. 

Everything worked great, except that I found that the singleton object would disappear if I didn't access it!  Yikes!  Well, it turns out that the solution was simple.  MarshalByRefObjects contain a method called InitializeLifetimeService.  You can overload this to control the lifetime of your remotable objects.  To make my object live forever, I overloaded this method and returned null.  Works perfectly!  Here's the code.

public class GateStatusRemotable : MarshalByRefObject
{
 public GateStatusCollection GateStatus;

 public override Object InitializeLifetimeService()
 {
  return null;
 }
}

You can also return an ILease object if you want to get fancy with this.


Posted Wed, Oct 8 2003 10:47 AM by Brendan Tompkins
Filed under:

[Advertisement]

Comments

Rxkfpbgu wrote re: Object Persistence and Remoting...
on Tue, Jul 14 2009 2:46 PM

Rml3Ro

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Devlicio.us