/// <summary> /// 取一个远程对象接口 /// </summary> /// <param name="_interfaceName"></param> /// <returns></returns> public static object GetRemotingInterface(string _interfaceName) { if (serverObjectLib.ContainsKey(_interfaceName)) { object _icsObject = serverObjectLib[_interfaceName]; try { MarshalByRefObject _mo = _icsObject as MarshalByRefObject; ILease lease = (ILease)_mo.GetLifetimeService(); if (lease.CurrentState == LeaseState.Active) { return(_icsObject); } } catch (Exception e) { string errmsg = e.Message; } sponsorLib.Remove(_interfaceName); serverObjectLib.Remove(_interfaceName); } IServiceFactory _serviceFactory = (IServiceFactory)RemotingClientSvc.GetAppSvrObj(typeof(IServiceFactory)); RemotingClientSvc.BindTicketToCallContext(SessionClass.CurrentTicket); MarshalByRefObject _ret = _serviceFactory.GetInterFace(_interfaceName) as MarshalByRefObject; ILease clease = (ILease)_ret.GetLifetimeService(); SinoSZClientSponsor _sp = new SinoSZClientSponsor(); clease.Register(_sp); //为自己注册生存期租约主办方 sponsorLib.Add(_interfaceName, _sp); serverObjectLib.Add(_interfaceName, _ret); return(_ret); }
public void Dispose() { MarshalByRefObject mbr = (MarshalByRefObject)controller; ILease lease = mbr.GetLifetimeService() as ILease; lease.Unregister(this); }
public static object GetLifetimeService(MarshalByRefObject obj) { if (obj == null) { return(null); } return(obj.GetLifetimeService()); }
public new object GetLifetimeService() { createInstance(); object GetLifetimeService = BaseMashalByRef.GetLifetimeService(); tr.Dispose(); return(GetLifetimeService); }
public ProcessHost(IProcessHostController controller) { this.controller = controller; MarshalByRefObject mbr = (MarshalByRefObject)controller; ILease lease = mbr.GetLifetimeService() as ILease; lease.Register(this); }
/// <summary>Empties the list objects registered with the current <see cref="T:System.Runtime.Remoting.Lifetime.ClientSponsor" />.</summary> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Infrastructure" /> /// </PermissionSet> public void Close() { foreach (object obj in this.registered_objects.Values) { MarshalByRefObject marshalByRefObject = (MarshalByRefObject)obj; ILease lease = marshalByRefObject.GetLifetimeService() as ILease; lease.Unregister(this); } this.registered_objects.Clear(); }
public void Unregister(MarshalByRefObject obj) { if (!registered_objects.ContainsKey(obj)) { return; } ILease lease = obj.GetLifetimeService() as ILease; lease.Unregister(this); registered_objects.Remove(obj); }
// ... public static void DoStuff() { // Before doing stuff, check if the remote object is still reachable try { remoteClass.GetLifetimeService(); } catch (RemotingException) { CreateRemoteInstance(); // Re-create remote instance } // Now we are sure the remote class is reachable // Do actual stuff ... }
public bool Register(MarshalByRefObject obj) { ILease lease = (ILease)obj.GetLifetimeService(); if (lease == null) { return(false); } lease.Register((ISponsor)this); lock (this.sponsorTable) this.sponsorTable[(object)obj] = (object)lease; return(true); }
public void GetSaoWithLifetimeService() { IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.Services.Tests/Spring.Data.Spring.Remoting/saoLifetimeService.xml"); ContextRegistry.RegisterContext(ctx); MarshalByRefObject obj = (MarshalByRefObject)ctx.GetObject("remoteSaoCounter"); ILease lease = (ILease)obj.GetLifetimeService(); Assert.AreEqual(TimeSpan.FromMilliseconds(10000), lease.InitialLeaseTime, "InitialLeaseTime"); Assert.AreEqual(TimeSpan.FromMilliseconds(1000), lease.RenewOnCallTime, "RenewOnCallTime"); Assert.AreEqual(TimeSpan.FromMilliseconds(100), lease.SponsorshipTimeout, "SponsorshipTimeout"); }
/// <summary> /// 通过Remoting 接口创建远程接口对象 /// </summary> virtual protected void CreateObject() { IServiceFactory _serviceFactory = (IServiceFactory)RemotingClientSvc.GetAppSvrObj(typeof(IServiceFactory)); RemotingClientSvc.BindTicketToCallContext(SessionClass.CurrentTicket); MarshalByRefObject _ret = _serviceFactory.GetInterFace(InterfaceName) as MarshalByRefObject; ILease clease = (ILease)_ret.GetLifetimeService(); sponsor = new SinoSZClientSponsor(); clease.Register(sponsor); //为自己注册生存期租约主办方 remoteObject = _ret; }
public DebuggerServer(IDebuggerController dc) { this.controller = dc; mdbObjectValueAdaptor = new MdbObjectValueAdaptor(); MarshalByRefObject mbr = (MarshalByRefObject)controller; ILease lease = mbr.GetLifetimeService() as ILease; lease.Register(this); max_frames = 100; ST.Thread t = new ST.Thread((ST.ThreadStart)EventDispatcher); t.IsBackground = true; t.Start(); }
public bool Register(MarshalByRefObject obj) { ILease lifetimeService = (ILease)obj.GetLifetimeService(); if (lifetimeService == null) { return(false); } lifetimeService.Register(this); lock (this.sponsorTable) { this.sponsorTable[obj] = lifetimeService; } return(true); }
/// <summary> /// 撤销远程接口 /// </summary> virtual public void Dispose() { if (remoteObject != null) { try { MarshalByRefObject _mo = remoteObject as MarshalByRefObject; ILease lease = (ILease)_mo.GetLifetimeService(); lease.Unregister(sponsor); } catch (Exception e) { string errmsg = e.Message; } } }
public bool Register(MarshalByRefObject obj) { if (registered_objects.ContainsKey(obj)) { return(false); } ILease lease = obj.GetLifetimeService() as ILease; if (lease == null) { return(false); } lease.Register(this); registered_objects.Add(obj, obj); return(true); }
public bool Register(MarshalByRefObject obj) { ILease lease = (ILease)obj.GetLifetimeService(); if (lease == null) { return(false); } lease.Register(this); Hashtable obj2 = this.sponsorTable; lock (obj2) { this.sponsorTable[obj] = lease; } return(true); }
[System.Security.SecurityCritical] // auto-generated public bool Register(MarshalByRefObject obj) { BCLDebug.Trace("REMOTE", "ClientSponsor Register " + obj); ILease lease = (ILease)obj.GetLifetimeService(); if (lease == null) { return(false); } lease.Register(this); lock (sponsorTable) { sponsorTable[obj] = lease; } return(true); }
public void Register(MarshalByRefObject obj) { Debug.Assert(_lease == null); var lease = (ILease)obj.GetLifetimeService(); if (lease == null) { return; } lease.Register(this); lock (_syncRoot) { _lease = lease; } }
/// <summary> /// 注销远程对象接口 /// </summary> /// <param name="_interfaceName"></param> /// <returns></returns> public static void DiscardRemotingInterface(string _interfaceName) { if (serverObjectLib.ContainsKey(_interfaceName)) { object _icsObject = serverObjectLib[_interfaceName]; try { MarshalByRefObject _mo = _icsObject as MarshalByRefObject; ILease lease = (ILease)_mo.GetLifetimeService(); lease.Unregister(sponsorLib[_interfaceName]); } catch (Exception e) { string errmsg = e.Message; } sponsorLib.Remove(_interfaceName); serverObjectLib.Remove(_interfaceName); } }
public void RegistersWithLifetimeService() { IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.Services.Tests/Spring.Data.Spring.Remoting/caoLifetimeService.xml"); ContextRegistry.RegisterContext(ctx); ICaoRemoteFactory caoFactory = Activator.GetObject(typeof(ICaoRemoteFactory), "tcp://localhost:8005/counter2") as ICaoRemoteFactory; Assert.IsNotNull(caoFactory, "Cao factory is null even though it has been registered."); MarshalByRefObject cao = caoFactory.GetObject() as MarshalByRefObject; Assert.IsNotNull(cao); ILease lease = (ILease)cao.GetLifetimeService(); Assert.AreEqual(TimeSpan.FromMilliseconds(10000), lease.InitialLeaseTime, "InitialLeaseTime"); Assert.AreEqual(TimeSpan.FromMilliseconds(1000), lease.RenewOnCallTime, "RenewOnCallTime"); Assert.AreEqual(TimeSpan.FromMilliseconds(100), lease.SponsorshipTimeout, "SponsorshipTimeout"); }
// Register an object for sponsorship. public bool Register(MarshalByRefObject obj) { // If there is no lease on the object, then bail out. ILease lease = (ILease)(obj.GetLifetimeService()); if (lease == null) { return(false); } // Inform the lease about the registered sponsor. lease.Register(this); // Add the lease to the sponsor table. lock (this) { sponsoredObjects[obj] = lease; } return(true); }
// Register an object for sponsorship. public bool Register(MarshalByRefObject obj) { // If there is no lease on the object, then bail out. ILease lease = (ILease)(obj.GetLifetimeService()); if(lease == null) { return false; } // Inform the lease about the registered sponsor. lease.Register(this); // Add the lease to the sponsor table. lock(this) { sponsoredObjects[obj] = lease; } return true; }
public static object GetLifetimeService (MarshalByRefObject obj) { if (obj == null) return null; return obj.GetLifetimeService (); }
public ClientSideSponsor(MarshalByRefObject objectToSponsor) { _objectLease = (ILease)objectToSponsor.GetLifetimeService(); }