[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

Re: Client Activated .NET Remote Object

Ken Kolda

9/13/2004 7:15:00 PM

First, start off by understanding that there is no guaranteed way using
remoting to have the remoted object be destroyed as soon as the client app
terminates. If there's some server-side cleanup that needs to occur when the
client terminates, you should create a method, e.g. Logout(), on your
remoted object which the client would call when terminated normally.
Typically, this code would clean up any server-side state held for that
client (and could disconnect the current remoted object from the remoting
framework by calling RemotingServices.Disconnect()).

However, you will have to make accomodations for the fact that not every
client will terminate normally. To handle this scenario and have your
remoted object live approximately for the lifetime of your client is to use
a client-side sponsor. A sponsor (which is an object the implements
ISponsor) is called on a regular basis by the server to see if the remoted
object it sponsors is still needed or not. If so, the sponsor "renews" the
object for a specified period of time (e.g. 5 minutes). If no sponsor renews
the object, it's disconnected from the remoting framework and becomes
eligible for GC (assuming the server holds no other references to the
object).

Use a client-side sponsor for a remoted object whose lifetime should
correspond to the lifetime of the client. When the client first activates
the remote object, it registers a sponsor. This sponsor should simply renew
the remote object whenever it is asked. When the client app dies (either
normally or abnormally), it will no longer be able to renew the remoted
object. Thus, the object will become eligible for GC the next time the
object's lease comes up for renewal.

Note, however, not that this will not occur as soon asthe client dies -- it
will happen the next time the object's lease needs to be renewed, which will
be determined by your sponsor. Also note that an object is not destoryed
when its lease expires -- it is simply disconnected from the remoting
framework (i.e. RemotingServices.Dicsonnect()).

For more info on sponsors, leases and object lifetimes, see:

http://msdn.microsoft.com/library/en-us/cpguide/html/cpconlifetimeleases.asp?...

Regards -
Ken


"Shreyash B. Patel" <Shreyash B. Patel@discussions.microsoft.com> wrote in
message news:E9C027AB-F1C7-44B8-8E3A-3A6F90457628@microsoft.com...
> I have an application where the Client App creates the .NET Remote Object
but
> when the application shuts off the .NET Remote Object destructor is not
> called. Instead when I shutdown the Server Application the Object
destructor
> is called. I need a way to delete the .NET Remote Object once the client
> application that has created the object is closed.
>
> Shreyash B. Patel


1 Answer

Ken Kolda

9/13/2004 9:44:00 PM

0

You can't (from the client). So, in this case, your object would just get
disconnected and, eventually, garbage collected after the sponsorship
expires. If there's more to it than simply allowing this object to be
cleaned up (e.g. your server holds other state information for the client),
then you'll need to take one of a couple of approaches to manage this:

1) Implement a pinging mechanism, so that your server checks from time to
time if your client is alive by invoking a method on some remoted object
that the client passed to the server. This is tricky and probably not your
best bet, but gives you good control.

2) Register a "tracking handler" object on the server which will be notified
whenever an object is remoted or disconnected. Then when you see your client
object diconnected, clean up whatever other stuff is associated with the
client.

3) Use a third-party component like GenuineChannels
(www.genuinechannels.com) which provides server-side events for client
connection and disconnection. Use these events to manage the client state.

Ken


"Shreyash B. Patel" <ShreyashBPatel@discussions.microsoft.com> wrote in
message news:5E52A992-7C49-4E21-A3FD-C1B447C340A8@microsoft.com...
> In the abnormal case when the client is disconnected since the sponsor is
not
> available then how do I call the Log Out function in that case.
>
> Shreyash B. Patel
>
> "Ken Kolda" wrote:
>
> > First, start off by understanding that there is no guaranteed way using
> > remoting to have the remoted object be destroyed as soon as the client
app
> > terminates. If there's some server-side cleanup that needs to occur when
the
> > client terminates, you should create a method, e.g. Logout(), on your
> > remoted object which the client would call when terminated normally.
> > Typically, this code would clean up any server-side state held for that
> > client (and could disconnect the current remoted object from the
remoting
> > framework by calling RemotingServices.Disconnect()).
> >
> > However, you will have to make accomodations for the fact that not every
> > client will terminate normally. To handle this scenario and have your
> > remoted object live approximately for the lifetime of your client is to
use
> > a client-side sponsor. A sponsor (which is an object the implements
> > ISponsor) is called on a regular basis by the server to see if the
remoted
> > object it sponsors is still needed or not. If so, the sponsor "renews"
the
> > object for a specified period of time (e.g. 5 minutes). If no sponsor
renews
> > the object, it's disconnected from the remoting framework and becomes
> > eligible for GC (assuming the server holds no other references to the
> > object).
> >
> > Use a client-side sponsor for a remoted object whose lifetime should
> > correspond to the lifetime of the client. When the client first
activates
> > the remote object, it registers a sponsor. This sponsor should simply
renew
> > the remote object whenever it is asked. When the client app dies (either
> > normally or abnormally), it will no longer be able to renew the remoted
> > object. Thus, the object will become eligible for GC the next time the
> > object's lease comes up for renewal.
> >
> > Note, however, not that this will not occur as soon asthe client dies --
it
> > will happen the next time the object's lease needs to be renewed, which
will
> > be determined by your sponsor. Also note that an object is not destoryed
> > when its lease expires -- it is simply disconnected from the remoting
> > framework (i.e. RemotingServices.Dicsonnect()).
> >
> > For more info on sponsors, leases and object lifetimes, see:
> >
> >
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconlifetimeleases.asp?...
> >
> > Regards -
> > Ken
> >
> >
> > "Shreyash B. Patel" <Shreyash B. Patel@discussions.microsoft.com> wrote
in
> > message news:E9C027AB-F1C7-44B8-8E3A-3A6F90457628@microsoft.com...
> > > I have an application where the Client App creates the .NET Remote
Object
> > but
> > > when the application shuts off the .NET Remote Object destructor is
not
> > > called. Instead when I shutdown the Server Application the Object
> > destructor
> > > is called. I need a way to delete the .NET Remote Object once the
client
> > > application that has created the object is closed.
> > >
> > > Shreyash B. Patel
> >
> >
> >