private CreateObjRef ( |
||
requestedType | ||
return |
static int CreateObjRef(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); System.MarshalByRefObject obj = (System.MarshalByRefObject)ToLua.CheckObject(L, 1, typeof(System.MarshalByRefObject)); System.Type arg0 = (System.Type)ToLua.CheckObject(L, 2, typeof(System.Type)); System.Runtime.Remoting.ObjRef o = obj.CreateObjRef(arg0); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
[System.Security.SecurityCritical] // auto-generated internal static ObjRef MarshalInternal(MarshalByRefObject Obj, String ObjURI, Type RequestedType, bool updateChannelData) { BCLDebug.Trace("REMOTE", "Entered Marshal for URI" + ObjURI + "\n"); if (null == Obj) return null; ObjRef objectRef = null; Identity idObj = null; idObj = GetOrCreateIdentity(Obj, ObjURI); if (RequestedType != null) { ServerIdentity srvIdObj = idObj as ServerIdentity; if (srvIdObj != null) { // If more than one thread, marshals with different types the // results would be non-deterministic, so we just let the last // call win (also allows type to be marshalled a second time // to change the exposed type). srvIdObj.ServerType = RequestedType; srvIdObj.MarshaledAsSpecificType = true; } } // If there is no objref associated with the identity then go ahead // and create one and stick it back into the identity object #if _DEBUG idObj.AssertValid(); #endif Contract.Assert(null != idObj.ObjURI,"null != idObj.ObjURI"); Message.DebugOut("RemotingServices::Marshal: trying to create objref\n"); // We should definitely have an identity object at this point of time Contract.Assert(null != idObj,"null != idObj"); // Extract the objref from the identity objectRef = idObj.ObjectRef; if (null == objectRef) { Message.DebugOut("RemotingServices::Marshal: really trying to create objref\n"); if (IsTransparentProxy(Obj)) { RealProxy realProxy = GetRealProxy(Obj); Contract.Assert(null != realProxy,"null != realProxy"); objectRef = realProxy.CreateObjRef(RequestedType); } else { // Create a new object ref which contains the default information objectRef = Obj.CreateObjRef(RequestedType); } Message.DebugOut("RemotingServices::Marshal: created objref\n"); if (idObj == null || objectRef == null) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidMarshalByRefObject"), "Obj"); // The ObjectRef property setter will take care of ----s objectRef = idObj.RaceSetObjRef(objectRef); } // Retime lease on every marshal on the server side // and extend lease on every marshal on the client side <EMAIL>- GopalK</EMAIL> ServerIdentity srvId = idObj as ServerIdentity; if (srvId != null) { // Ensure that the lease is started soon as the object is // marshaled. MarshalByRefObject obj = null; // This call forces creation of the lifetime lease sink. srvId.GetServerObjectChain(out obj); // Server side ... object being marshaled => give it another // full lease Lease lease = idObj.Lease; if (lease != null) { // We always make Identity reference our own Lease though // the actual object implements its own ILease object. // This seems completely broken. Further, ILease interface // should have the activate method. <EMAIL>- GopalK</EMAIL> // This lock ensures coordination with the lifetime service // which might have decided to Disconnect the object about // the same time as it is being marshaled lock (lease) { if (lease.CurrentState == LeaseState.Expired) { // Lease.Renew is a no-op if LeaseState==Expired // So we do a full ActivateLease lease.ActivateLease(); } else { // Lease is still around. Just increase the time lease.RenewInternal(idObj.Lease.InitialLeaseTime); } } } // Every marshal should also ensure that the channel data // being carried in the objRef reflects the latest data from // regisetered channels // < if (updateChannelData && objectRef.ChannelInfo != null) { // Create the channel info Object[] channelData = ChannelServices.CurrentChannelData; // Make sure the channelInfo only has x-appdomain data since the objref is agile while other // channelData might not be and regardless this data is useless for an appdomain proxy if (!(Obj is AppDomain)) objectRef.ChannelInfo.ChannelData = channelData; else { int channelDataLength = channelData.Length; Object[] newChannelData = new Object[channelDataLength]; // Clone the data so that we dont [....] the current appdomain data which is stored // as a static Array.Copy(channelData, newChannelData, channelDataLength); for (int i = 0; i < channelDataLength; i++) { if (!(newChannelData[i] is CrossAppDomainData)) newChannelData[i] = null; } objectRef.ChannelInfo.ChannelData = newChannelData; } } } else { #if false /* */ ILease lease = idObj.Lease; if (lease == null) { lease = (ILease)Obj.GetLifetimeService(); } if (lease != null) { lease.Renew(lease.RenewOnCallTime); } #endif } // Notify TrackingServices that an object has been marshaled // NOTE: This call also keeps the object alive otherwise GC // can report it as dead anytime inside this call when it thinks // that the object will no longer be referenced, either inside // this call or outside. /* < */ TrackingServices.MarshaledObject(Obj, objectRef); return objectRef; }
internal static ObjRef MarshalInternal(MarshalByRefObject Obj, string ObjURI, Type RequestedType, bool updateChannelData) { if (Obj == null) { return null; } ObjRef objRefGiven = null; Identity orCreateIdentity = null; orCreateIdentity = GetOrCreateIdentity(Obj, ObjURI); if (RequestedType != null) { ServerIdentity identity2 = orCreateIdentity as ServerIdentity; if (identity2 != null) { identity2.ServerType = RequestedType; identity2.MarshaledAsSpecificType = true; } } objRefGiven = orCreateIdentity.ObjectRef; if (objRefGiven == null) { if (IsTransparentProxy(Obj)) { objRefGiven = GetRealProxy(Obj).CreateObjRef(RequestedType); } else { objRefGiven = Obj.CreateObjRef(RequestedType); } if ((orCreateIdentity == null) || (objRefGiven == null)) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidMarshalByRefObject"), "Obj"); } objRefGiven = orCreateIdentity.RaceSetObjRef(objRefGiven); } ServerIdentity identity3 = orCreateIdentity as ServerIdentity; if (identity3 != null) { MarshalByRefObject obj2 = null; identity3.GetServerObjectChain(out obj2); Lease lease = orCreateIdentity.Lease; if (lease != null) { lock (lease) { if (lease.CurrentState == LeaseState.Expired) { lease.ActivateLease(); } else { lease.RenewInternal(orCreateIdentity.Lease.InitialLeaseTime); } } } if (updateChannelData && (objRefGiven.ChannelInfo != null)) { object[] currentChannelData = ChannelServices.CurrentChannelData; if (!(Obj is AppDomain)) { objRefGiven.ChannelInfo.ChannelData = currentChannelData; } else { int length = currentChannelData.Length; object[] destinationArray = new object[length]; Array.Copy(currentChannelData, destinationArray, length); for (int i = 0; i < length; i++) { if (!(destinationArray[i] is CrossAppDomainData)) { destinationArray[i] = null; } } objRefGiven.ChannelInfo.ChannelData = destinationArray; } } } TrackingServices.MarshaledObject(Obj, objRefGiven); return objRefGiven; }
// Internal flavor without security! internal static ObjRef MarshalInternal(MarshalByRefObject Obj, String ObjURI, Type RequestedType) { BCLDebug.Trace("REMOTE", "Entered Marshal for URI" + ObjURI + "\n"); if (null == Obj) return null; ObjRef objectRef = null; Identity idObj = null; idObj = GetOrCreateIdentity(Obj, ObjURI); if (RequestedType != null) { ServerIdentity srvIdObj = idObj as ServerIdentity; if (srvIdObj != null) { // If more than one thread, marshals with different types the // results would be non-deterministic, so we just let the last // call win (also allows type to be marshalled a second time // to change the exposed type). srvIdObj.ServerType = RequestedType; srvIdObj.MarshaledAsSpecificType = true; } } // If there is no objref associated with the identity then go ahead // and create one and stick it back into the identity object #if _DEBUG idObj.AssertValid(); #endif BCLDebug.Assert(null != idObj.ObjURI,"null != idObj.ObjURI"); Message.DebugOut("RemotingServices::Marshal: trying to create objref\n"); // We should definitely have an identity object at this point of time BCLDebug.Assert(null != idObj,"null != idObj"); // Extract the objref from the identity objectRef = idObj.ObjectRef; if (null == objectRef) { Message.DebugOut("RemotingServices::Marshal: really trying to create objref\n"); if (IsTransparentProxy(Obj)) { RealProxy realProxy = GetRealProxy(Obj); BCLDebug.Assert(null != realProxy,"null != realProxy"); objectRef = realProxy.CreateObjRef(RequestedType); } else { // Create a new object ref which contains the default information objectRef = Obj.CreateObjRef(RequestedType); } Message.DebugOut("RemotingServices::Marshal: created objref\n"); BCLDebug.Assert(null != idObj,"null != idObj"); BCLDebug.Assert(null != objectRef,"null != objectRef"); // The ObjectRef property setter will take care of races objectRef = idObj.RaceSetObjRef(objectRef); } // Retime lease on every marshal on the server side // and extend lease on every marshal on the client side ServerIdentity srvId = idObj as ServerIdentity; if (srvId != null) { // Ensure that the lease is started soon as the object is // marshaled. MarshalByRefObject obj = null; // This call forces creation of the lifetime lease sink. srvId.GetServerObjectChain(out obj); // Server side ... object being marshaled => give it another // full lease Lease lease = idObj.Lease; if (lease != null) { // We always make Identity reference our own Lease though // the actual object implements its own ILease object. // This seems completely broken. Further, ILease interface // should have the activate method. // This lock ensures coordination with the lifetime service // which might have decided to Disconnect the object about // the same time as it is being marshaled lock (lease) { if (lease.CurrentState == LeaseState.Expired) { // Lease.Renew is a no-op if LeaseState==Expired // So we do a full ActivateLease lease.ActivateLease(); } else { // Lease is still around. Just increase the time lease.RenewInternal(idObj.Lease.InitialLeaseTime); } } } // Every marshal should also ensure that the channel data // being carried in the objRef reflects the latest data from // regisetered channels if (objectRef.ChannelInfo != null) { objectRef.ChannelInfo.ChannelData = ChannelServices.CurrentChannelData; } } else { } // Notify TrackingServices that an object has been marshaled // NOTE: This call also keeps the object alive otherwise GC // can report it as dead anytime inside this call when it thinks // that the object will no longer be referenced, either inside // this call or outside. /* */ TrackingServices.MarshaledObject(Obj, objectRef); return objectRef; }