//*********************************************** /////////////////////////////////////////////////////////////////////////////////// public void Register(object obj) { if (obj == null) { return; } if (!(obj is MarshalByRefObject)) { return; } MarshalByRefObject marshalObj = (MarshalByRefObject)obj; //ObjRef laRef = marshalObj.CreateObjRef ( obj.GetType() ); ILease lease = (ILease)RemotingServices.GetLifetimeService(marshalObj); if (lease == null) { return; } //lease.Register(this, TimeSpan.FromSeconds(c_nbSecondes)); lease.Register(this, TimeSpan.FromMinutes(2)); m_nNbObjetsSponsorises++; I2iMarshalObject obj2i = obj as I2iMarshalObject; if (obj2i != null) { m_dicObjetsSponsor[obj2i.UniqueId] = new CProxy2iMarshal(obj2i); } else { m_listeObjetsSponsorises.Add(obj); } }
public CProxy2iMarshal(I2iMarshalObject objet) { Objet = objet; UniqueId = objet.UniqueId; }
public static void FonctionSecuriteParTimer(object state) { if (m_bDejaEnSecurite) { return; } try { m_bDejaEnSecurite = true; foreach (C2iSponsor sponsor in m_gl_listeSponsors.ToArray()) { string strLibelle = sponsor.Label; // Pour debuguer uniquement try { sponsor.m_suspectGarbage.CreateGeneration(); if (sponsor.m_listeObjetsSponsorises != null) { List <object> lstObjets = new List <object>(sponsor.m_listeObjetsSponsorises.ToArray()); foreach (object obj in sponsor.m_dicObjetsSponsor.Values) { lstObjets.Add(obj); } int nIndex = 0; sponsor.m_suspectGarbage.RenouvelleBailParAppel(); foreach (object obj in lstObjets) { I2iMarshalObject obj2i = obj as I2iMarshalObject; CProxy2iMarshal proxy = null; if (obj2i == null) { proxy = obj as CProxy2iMarshal; if (proxy != null) { obj2i = proxy.Objet; } } if (proxy == null) { nIndex++; } if (obj2i != null) { try { Type tp = obj2i.GetType(); ILease lease = (ILease)RemotingServices.GetLifetimeService((MarshalByRefObject)obj2i); if (lease != null) { lease.Renew(TimeSpan.FromMinutes(2)); } obj2i.RenouvelleBailParAppel(); nIndex++; } catch { sponsor.m_suspectGarbage.RegisterSuspect(obj2i); if (proxy != null) { sponsor.m_dicObjetsSponsor.Remove(proxy.UniqueId); } else { sponsor.m_listeObjetsSponsorises.RemoveAt(nIndex); } } } } } } catch {} } } catch {} finally { m_bDejaEnSecurite = false; } }
/////////////////////////////////////////////////////////////////////////////////// public void Unregister(object obj) { DateTime dt = DateTime.Now; TimeSpan sp; if (obj == null) { return; } try { I2iMarshalObject obj2i = obj as I2iMarshalObject; if (obj2i != null) { string strId = obj2i.UniqueId; if (m_dicObjetsSponsor.ContainsKey(strId)) { m_dicObjetsSponsor.Remove(strId); m_nNbObjetsSponsorises--; } } else { if (m_listeObjetsSponsorises.Contains(obj)) { m_listeObjetsSponsorises.Remove(obj); m_nNbObjetsSponsorises--; } } sp = DateTime.Now - dt; Console.WriteLine("sponsor unregister 1:" + sp.TotalMilliseconds); } catch { sp = DateTime.Now - dt; Console.WriteLine("sponsor unregister 2:" + sp.TotalMilliseconds); /*//Probablement un objet remote qui ne répond plus * try * { * RealProxy proxy = RemotingServices.GetRealProxy( obj ); * int nIndex = -1; * foreach ( object objInListe in m_listeObjetsSponsorises ) * { * try * { * nIndex++; * RealProxy prox2 = RemotingServices.GetRealProxy( objInListe ); * if ( prox2.Equals ( proxy ) ) * { * m_nNbObjetsSponsorises--; * m_listeObjetsSponsorises.RemoveAt ( nIndex ); * break; * } * } * catch * {} * } * } * catch * { * }*/ } try { ILease lease = (ILease)RemotingServices.GetLifetimeService((MarshalByRefObject)obj); sp = DateTime.Now - dt; Console.WriteLine("sponsor unregister 3 :" + sp.TotalMilliseconds); if (lease == null) { return; } lease.Unregister(this); sp = DateTime.Now - dt; Console.WriteLine("sponsor unregister 4 :" + sp.TotalMilliseconds); } catch { sp = DateTime.Now - dt; Console.WriteLine("sponsor unregister 5 :" + sp.TotalMilliseconds); } }