Leasing and sponsoring .net
-
Hi, Nowaday I'm working on .net remoting and I've got some problem with leasing. there is my code:
//RemoteObject
public class X : MarshalByRefObject
{
public int x;
public X()
{
Console.WriteLine("some X object is done...");
}
public void PrintAboutMe()
{
ILease itfILease = (ILease)RemotingServices.GetLifetimeService(this);
Console.WriteLine("CurrentState: " + itfILease.CurrentState);
Console.WriteLine("InitialLeaseTime: " + itfILease.InitialLeaseTime.Minutes +
":" + itfILease.InitialLeaseTime.Seconds);
Console.WriteLine("CurrentLeaseTime: " + itfILease.CurrentLeaseTime.Minutes +
":" + itfILease.CurrentLeaseTime.Seconds);
Console.WriteLine("RenewOnCallTime: " + itfILease.RenewOnCallTime.Minutes +
":" + itfILease.RenewOnCallTime.Seconds);
Console.WriteLine("SponsorShipTime: " + itfILease.SponsorshipTimeout.Minutes +
":" + itfILease.SponsorshipTimeout.Seconds);
Console.WriteLine("x = " + x);
}
public override object InitializeLifetimeService()
{
ILease itfLease = (ILease)base.InitializeLifetimeService();
if (itfLease.CurrentState == LeaseState.Initial)
{
itfLease.InitialLeaseTime = TimeSpan.FromSeconds(10);
itfLease.RenewOnCallTime = TimeSpan.FromSeconds(6);
itfLease.SponsorshipTimeout = TimeSpan.FromSeconds(6);
}
// return null;
return itfLease;
}
public void IncrementX()
{
x++;
Console.WriteLine("\nIncrement x member ...\n");
}
public void ChangeLifetime()
{
ILease itfILease = (ILease)RemotingServices.GetLifetimeService(this);
itfILease.Renew(TimeSpan.FromSeconds(20));
}
}
//SponsorObjectCode
public class MySponsor : MarshalByRefObject, ISponsor
{
public TimeSpan Renewal(ILease il)
{
Console.WriteLine("I've been asked to renew the lease.");
return TimeSpan.FromSeconds(20);
}
}//ClientCode:
public static void Main(string[] args)
{
HttpChannel c = new HttpChannel(null,
new BinaryClientFormatterSinkProvider(),
null);
ChannelServices.RegisterCh -
Hi, Nowaday I'm working on .net remoting and I've got some problem with leasing. there is my code:
//RemoteObject
public class X : MarshalByRefObject
{
public int x;
public X()
{
Console.WriteLine("some X object is done...");
}
public void PrintAboutMe()
{
ILease itfILease = (ILease)RemotingServices.GetLifetimeService(this);
Console.WriteLine("CurrentState: " + itfILease.CurrentState);
Console.WriteLine("InitialLeaseTime: " + itfILease.InitialLeaseTime.Minutes +
":" + itfILease.InitialLeaseTime.Seconds);
Console.WriteLine("CurrentLeaseTime: " + itfILease.CurrentLeaseTime.Minutes +
":" + itfILease.CurrentLeaseTime.Seconds);
Console.WriteLine("RenewOnCallTime: " + itfILease.RenewOnCallTime.Minutes +
":" + itfILease.RenewOnCallTime.Seconds);
Console.WriteLine("SponsorShipTime: " + itfILease.SponsorshipTimeout.Minutes +
":" + itfILease.SponsorshipTimeout.Seconds);
Console.WriteLine("x = " + x);
}
public override object InitializeLifetimeService()
{
ILease itfLease = (ILease)base.InitializeLifetimeService();
if (itfLease.CurrentState == LeaseState.Initial)
{
itfLease.InitialLeaseTime = TimeSpan.FromSeconds(10);
itfLease.RenewOnCallTime = TimeSpan.FromSeconds(6);
itfLease.SponsorshipTimeout = TimeSpan.FromSeconds(6);
}
// return null;
return itfLease;
}
public void IncrementX()
{
x++;
Console.WriteLine("\nIncrement x member ...\n");
}
public void ChangeLifetime()
{
ILease itfILease = (ILease)RemotingServices.GetLifetimeService(this);
itfILease.Renew(TimeSpan.FromSeconds(20));
}
}
//SponsorObjectCode
public class MySponsor : MarshalByRefObject, ISponsor
{
public TimeSpan Renewal(ILease il)
{
Console.WriteLine("I've been asked to renew the lease.");
return TimeSpan.FromSeconds(20);
}
}//ClientCode:
public static void Main(string[] args)
{
HttpChannel c = new HttpChannel(null,
new BinaryClientFormatterSinkProvider(),
null);
ChannelServices.RegisterChFor the first question, this code runs fine for me and the lease is being successfully renewed. :wtf: For the second question, you already are, when you run this code the client is interacting with the remote (ie. proxy) object and the actual object exists and is even outputting text onto the Server's console. I haven't done much with remoting, but that's my two cents, hope it helps.
-
For the first question, this code runs fine for me and the lease is being successfully renewed. :wtf: For the second question, you already are, when you run this code the client is interacting with the remote (ie. proxy) object and the actual object exists and is even outputting text onto the Server's console. I haven't done much with remoting, but that's my two cents, hope it helps.
I'd like to thank you for help, I found the solution for first problem... I didn't know that:
current lease time = MAX(lease time - expired time,renew on call time)
source: http://msdn.microsoft.com/en-us/magazine/cc300474.aspx 2. You wrote: "and the actual object exists and is even outputting text onto the Server's console" yes, I know but I'd like to have a reference to this object (I want to communicate with it), this remote object is working fine (object is created and managed by client) but everything is working on "background". I have got a primitive way to comunicate with every object by static class members but it's not exactly what I want to. -
I'd like to thank you for help, I found the solution for first problem... I didn't know that:
current lease time = MAX(lease time - expired time,renew on call time)
source: http://msdn.microsoft.com/en-us/magazine/cc300474.aspx 2. You wrote: "and the actual object exists and is even outputting text onto the Server's console" yes, I know but I'd like to have a reference to this object (I want to communicate with it), this remote object is working fine (object is created and managed by client) but everything is working on "background". I have got a primitive way to comunicate with every object by static class members but it's not exactly what I want to.For the first response, neither did I! I just changed the renewed lease time to 5 days so I could easily see it was working. For the second, I agree it sounds less than ideal, but I'm not sure how else you would do it. Maybe your design could change a little? Perhaps the client-side object can quietly "phone home" asychronously for some new info? Perhaps the client-side object could raise an event that you handle on the server?