Inheritance: IMessageSink
Esempio n. 1
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static Object FinishAsyncWorkCallback(Object[] args)
        {
            AsyncWorkItem This   = (AsyncWorkItem)args[0];
            Context       srvCtx = This._srvID.ServerContext;

            LogicalCallContext threadPoolCallCtx =
                CallContext.SetLogicalCallContext(This._callCtx);

            // Call the server context chain Async. We provide workItem as our
            // replySink ... this will cause the replySink.ProcessMessage
            // to switch back to the context of the original caller thread.

            // Call the dynamic sinks to notify that the async call
            // is starting
            srvCtx.NotifyDynamicSinks(
                This._reqMsg,
                false,  // bCliSide
                true,   // bStart
                true,   // bAsync
                true);  // bNotifyGlobals

            // <

            IMessageCtrl ctrl =
                srvCtx.GetServerContextChain().AsyncProcessMessage(
                    This._reqMsg,
                    (IMessageSink)This);

            // change back to the old context
            CallContext.SetLogicalCallContext(threadPoolCallCtx);

            return(null);
        }
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            IMessage msg = InternalSink.ValidateMessage(reqMsg);

            object[]     args = new object[4];
            IMessageCtrl ctrl = null;

            if (msg != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(msg);
                }
                return(ctrl);
            }
            ServerIdentity serverIdentity = InternalSink.GetServerIdentity(reqMsg);

            if (RemotingServices.CORProfilerTrackRemotingAsync())
            {
                Guid empty = Guid.Empty;
                if (RemotingServices.CORProfilerTrackRemotingCookie())
                {
                    object obj2 = reqMsg.Properties["CORProfilerCookie"];
                    if (obj2 != null)
                    {
                        empty = (Guid)obj2;
                    }
                }
                RemotingServices.CORProfilerRemotingServerReceivingMessage(empty, true);
                if (replySink != null)
                {
                    IMessageSink sink = new ServerAsyncReplyTerminatorSink(replySink);
                    replySink = sink;
                }
            }
            Context serverContext = serverIdentity.ServerContext;

            if (serverContext.IsThreadPoolAware)
            {
                args[0] = reqMsg;
                args[1] = replySink;
                args[2] = Thread.CurrentContext;
                args[3] = serverContext;
                InternalCrossContextDelegate ftnToCall = new InternalCrossContextDelegate(CrossContextChannel.AsyncProcessMessageCallback);
                return((IMessageCtrl)Thread.CurrentThread.InternalCrossContextCallback(serverContext, ftnToCall, args));
            }
            AsyncWorkItem item = null;

            item = new AsyncWorkItem(reqMsg, replySink, Thread.CurrentContext, serverIdentity);
            WaitCallback callBack = new WaitCallback(item.FinishAsyncWork);

            ThreadPool.QueueUserWorkItem(callBack);
            return(ctrl);
        }
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            IMessage message = InternalSink.ValidateMessage(reqMsg);

            object[]     array  = new object[4];
            IMessageCtrl result = null;

            if (message != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(message);
                }
            }
            else
            {
                ServerIdentity serverIdentity = InternalSink.GetServerIdentity(reqMsg);
                if (RemotingServices.CORProfilerTrackRemotingAsync())
                {
                    Guid id = Guid.Empty;
                    if (RemotingServices.CORProfilerTrackRemotingCookie())
                    {
                        object obj = reqMsg.Properties["CORProfilerCookie"];
                        if (obj != null)
                        {
                            id = (Guid)obj;
                        }
                    }
                    RemotingServices.CORProfilerRemotingServerReceivingMessage(id, true);
                    if (replySink != null)
                    {
                        IMessageSink messageSink = new ServerAsyncReplyTerminatorSink(replySink);
                        replySink = messageSink;
                    }
                }
                Context serverContext = serverIdentity.ServerContext;
                if (serverContext.IsThreadPoolAware)
                {
                    array[0] = reqMsg;
                    array[1] = replySink;
                    array[2] = Thread.CurrentContext;
                    array[3] = serverContext;
                    InternalCrossContextDelegate ftnToCall = new InternalCrossContextDelegate(CrossContextChannel.AsyncProcessMessageCallback);
                    result = (IMessageCtrl)Thread.CurrentThread.InternalCrossContextCallback(serverContext, ftnToCall, array);
                }
                else
                {
                    AsyncWorkItem @object  = new AsyncWorkItem(reqMsg, replySink, Thread.CurrentContext, serverIdentity);
                    WaitCallback  callBack = new WaitCallback(@object.FinishAsyncWork);
                    ThreadPool.QueueUserWorkItem(callBack);
                }
            }
            return(result);
        }
        internal static object FinishAsyncWorkCallback(object[] args)
        {
            AsyncWorkItem      replySink     = (AsyncWorkItem)args[0];
            Context            serverContext = replySink._srvID.ServerContext;
            LogicalCallContext callCtx       = CallContext.SetLogicalCallContext(replySink._callCtx);

            serverContext.NotifyDynamicSinks(replySink._reqMsg, false, true, true, true);
            serverContext.GetServerContextChain().AsyncProcessMessage(replySink._reqMsg, replySink);
            CallContext.SetLogicalCallContext(callCtx);
            return(null);
        }
        internal static object FinishAsyncWorkCallback(object[] args)
        {
            AsyncWorkItem      asyncWorkItem      = (AsyncWorkItem)args[0];
            Context            serverContext      = asyncWorkItem._srvID.ServerContext;
            LogicalCallContext logicalCallContext = CallContext.SetLogicalCallContext(asyncWorkItem._callCtx);

            serverContext.NotifyDynamicSinks(asyncWorkItem._reqMsg, false, true, true, true);
            IMessageCtrl messageCtrl = serverContext.GetServerContextChain().AsyncProcessMessage(asyncWorkItem._reqMsg, asyncWorkItem);

            CallContext.SetLogicalCallContext(logicalCallContext);
            return(null);
        }
Esempio n. 6
0
        internal static object DoAsyncDispatchCallback(object[] args)
        {
            AsyncWorkItem asyncWorkItem = (AsyncWorkItem)null;
            IMessage      msg           = (IMessage)args[0];
            IMessageSink  replySink     = (IMessageSink)args[1];
            Context       oldCtx        = (Context)args[2];
            Context       context       = (Context)args[3];

            if (replySink != null)
            {
                asyncWorkItem = new AsyncWorkItem(replySink, oldCtx);
            }
            return((object)context.GetServerContextChain().AsyncProcessMessage(msg, (IMessageSink)asyncWorkItem));
        }
 internal static object AsyncProcessMessageCallback(object[] args)
 {
     AsyncWorkItem replySink = null;
     IMessage msg = (IMessage) args[0];
     IMessageSink sink = (IMessageSink) args[1];
     Context oldCtx = (Context) args[2];
     Context context2 = (Context) args[3];
     if (sink != null)
     {
         replySink = new AsyncWorkItem(sink, oldCtx);
     }
     context2.NotifyDynamicSinks(msg, false, true, true, true);
     return context2.GetServerContextChain().AsyncProcessMessage(msg, replySink);
 }
        internal static object DoAsyncDispatchCallback(object[] args)
        {
            AsyncWorkItem replySink = null;
            IMessage      msg       = (IMessage)args[0];
            IMessageSink  sink      = (IMessageSink)args[1];
            Context       oldCtx    = (Context)args[2];
            Context       context2  = (Context)args[3];

            if (sink != null)
            {
                replySink = new AsyncWorkItem(sink, oldCtx);
            }
            return(context2.GetServerContextChain().AsyncProcessMessage(msg, replySink));
        }
        internal static object AsyncProcessMessageCallback(object[] args)
        {
            AsyncWorkItem replySink = null;
            IMessage      msg       = (IMessage)args[0];
            IMessageSink  sink      = (IMessageSink)args[1];
            Context       oldCtx    = (Context)args[2];
            Context       context2  = (Context)args[3];

            if (sink != null)
            {
                replySink = new AsyncWorkItem(sink, oldCtx);
            }
            context2.NotifyDynamicSinks(msg, false, true, true, true);
            return(context2.GetServerContextChain().AsyncProcessMessage(msg, replySink));
        }
 public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
 {
     IMessage msg = InternalSink.ValidateMessage(reqMsg);
     object[] args = new object[4];
     IMessageCtrl ctrl = null;
     if (msg != null)
     {
         if (replySink != null)
         {
             replySink.SyncProcessMessage(msg);
         }
         return ctrl;
     }
     ServerIdentity serverIdentity = InternalSink.GetServerIdentity(reqMsg);
     if (RemotingServices.CORProfilerTrackRemotingAsync())
     {
         Guid empty = Guid.Empty;
         if (RemotingServices.CORProfilerTrackRemotingCookie())
         {
             object obj2 = reqMsg.Properties["CORProfilerCookie"];
             if (obj2 != null)
             {
                 empty = (Guid) obj2;
             }
         }
         RemotingServices.CORProfilerRemotingServerReceivingMessage(empty, true);
         if (replySink != null)
         {
             IMessageSink sink = new ServerAsyncReplyTerminatorSink(replySink);
             replySink = sink;
         }
     }
     Context serverContext = serverIdentity.ServerContext;
     if (serverContext.IsThreadPoolAware)
     {
         args[0] = reqMsg;
         args[1] = replySink;
         args[2] = Thread.CurrentContext;
         args[3] = serverContext;
         InternalCrossContextDelegate ftnToCall = new InternalCrossContextDelegate(CrossContextChannel.AsyncProcessMessageCallback);
         return (IMessageCtrl) Thread.CurrentThread.InternalCrossContextCallback(serverContext, ftnToCall, args);
     }
     AsyncWorkItem item = null;
     item = new AsyncWorkItem(reqMsg, replySink, Thread.CurrentContext, serverIdentity);
     WaitCallback callBack = new WaitCallback(item.FinishAsyncWork);
     ThreadPool.QueueUserWorkItem(callBack);
     return ctrl;
 }
Esempio n. 11
0
        internal static object FinishAsyncWorkCallback(object[] args)
        {
            AsyncWorkItem      asyncWorkItem = (AsyncWorkItem)args[0];
            Context            serverContext = asyncWorkItem._srvID.ServerContext;
            LogicalCallContext callCtx       = CallContext.SetLogicalCallContext(asyncWorkItem._callCtx);
            IMessage           msg           = asyncWorkItem._reqMsg;
            int num1 = 0;
            int num2 = 1;
            int num3 = 1;
            int num4 = 1;

            serverContext.NotifyDynamicSinks(msg, num1 != 0, num2 != 0, num3 != 0, num4 != 0);
            serverContext.GetServerContextChain().AsyncProcessMessage(asyncWorkItem._reqMsg, (IMessageSink)asyncWorkItem);
            CallContext.SetLogicalCallContext(callCtx);
            return((object)null);
        }
Esempio n. 12
0
        internal static object AsyncProcessMessageCallback(object[] args)
        {
            AsyncWorkItem asyncWorkItem = (AsyncWorkItem)null;
            IMessage      msg1          = (IMessage)args[0];
            IMessageSink  replySink     = (IMessageSink)args[1];
            Context       oldCtx        = (Context)args[2];
            Context       context       = (Context)args[3];

            if (replySink != null)
            {
                asyncWorkItem = new AsyncWorkItem(replySink, oldCtx);
            }
            IMessage msg2 = msg1;
            int      num1 = 0;
            int      num2 = 1;
            int      num3 = 1;
            int      num4 = 1;

            context.NotifyDynamicSinks(msg2, num1 != 0, num2 != 0, num3 != 0, num4 != 0);
            return((object)context.GetServerContextChain().AsyncProcessMessage(msg1, (IMessageSink)asyncWorkItem));
        }
Esempio n. 13
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static Object AsyncProcessMessageCallback(Object[] args)
        {
            AsyncWorkItem workItem = null;

            IMessage     reqMsg    = (IMessage)args[0];
            IMessageSink replySink = (IMessageSink)args[1];
            Context      oldCtx    = (Context)args[2];
            Context      srvCtx    = (Context)args[3];
            IMessageCtrl msgCtrl   = null;

            // we use the work item just as our replySink in this case
            if (replySink != null)
            {
                workItem = new AsyncWorkItem(replySink, oldCtx);
            }

            Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: passing to ServerContextChain");

            srvCtx.NotifyDynamicSinks(
                reqMsg,
                false,       // bCliSide
                true,        // bStart
                true,        // bAsync
                true);       // bNotifyGlobals

            // call the server context chain
            msgCtrl =
                srvCtx.GetServerContextChain().AsyncProcessMessage(
                    reqMsg,
                    (IMessageSink)workItem);

            // Note: for async calls, we will do the return notification
            // for dynamic properties only when the async call
            // completes (i.e. when the replySink gets called)

            Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: back from ServerContextChain");

            return(msgCtrl);
        }
Esempio n. 14
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static Object DoAsyncDispatchCallback(Object[] args)
        {
            AsyncWorkItem workItem = null;

            IMessage     reqMsg    = (IMessage)args[0];
            IMessageSink replySink = (IMessageSink)args[1];
            Context      oldCtx    = (Context)args[2];
            Context      srvCtx    = (Context)args[3];
            IMessageCtrl msgCtrl   = null;


            // we use the work item just as our replySink in this case
            if (replySink != null)
            {
                workItem = new AsyncWorkItem(replySink, oldCtx);
            }
            Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: passing to ServerContextChain");
            // call the server context chain
            msgCtrl =
                srvCtx.GetServerContextChain().AsyncProcessMessage(reqMsg, (IMessageSink)workItem);
            Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: back from ServerContextChain");

            return(msgCtrl);
        }
Esempio n. 15
0
        [System.Security.SecurityCritical]  // auto-generated
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            Message.DebugOut("::::::::::::::::::::::::::: CrossContext Channel: Async call starting!!\n");
            // One way Async notifications may potentially pass a null reply sink.
            IMessage errMsg = ValidateMessage(reqMsg);

            Object[] args = new Object[] { null, null, null, null };

            IMessageCtrl msgCtrl = null;

            if (errMsg != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(errMsg);
                }
            }
            else
            {
                ServerIdentity srvID = GetServerIdentity(reqMsg);

                // If active, notify the profiler that an asynchronous remoting message was received.
                if (RemotingServices.CORProfilerTrackRemotingAsync())
                {
                    Guid g = Guid.Empty;

                    if (RemotingServices.CORProfilerTrackRemotingCookie())
                    {
                        Object obj = reqMsg.Properties["CORProfilerCookie"];

                        if (obj != null)
                        {
                            g = (Guid)obj;
                        }
                    }

                    RemotingServices.CORProfilerRemotingServerReceivingMessage(g, true);

                    // Only wrap the replySink if the call wants a reply
                    if (replySink != null)
                    {
                        // Now wrap the reply sink in our own so that we can notify the profiler of
                        // when the reply is sent.  Upon invocation, it will notify the profiler
                        // then pass control on to the replySink passed in above.
                        IMessageSink profSink = new ServerAsyncReplyTerminatorSink(replySink);

                        // Replace the reply sink with our own
                        replySink = profSink;
                    }
                }

                Context srvCtx = srvID.ServerContext;
                if (srvCtx.IsThreadPoolAware)
                {
                    // this is the case when we do not queue the work item since the
                    // server context claims to be doing its own threading.

                    args[0] = reqMsg;
                    args[1] = replySink;
                    args[2] = Thread.CurrentContext;
                    args[3] = srvCtx;

                    InternalCrossContextDelegate xctxDel = new InternalCrossContextDelegate(AsyncProcessMessageCallback);

                    msgCtrl = (IMessageCtrl)Thread.CurrentThread.InternalCrossContextCallback(srvCtx, xctxDel, args);
                }
                else
                {
                    AsyncWorkItem workItem = null;

                    // This is the case where we take care of returning the calling
                    // thread asap by using the ThreadPool for completing the call.

                    // we use a more elaborate WorkItem and delegate the work to the thread pool
                    workItem = new AsyncWorkItem(reqMsg,
                                                 replySink,
                                                 Thread.CurrentContext,
                                                 srvID);

                    WaitCallback threadFunc = new WaitCallback(workItem.FinishAsyncWork);
                    // Note: Dynamic sinks are notified in the threadFunc
                    ThreadPool.QueueUserWorkItem(threadFunc);
                }
            }

            Message.DebugOut("::::::::::::::::::::::::::: CrossContext Channel: Async call returning!!\n");
            return(msgCtrl);
        } // AsyncProcessMessage
        } // AsyncProcessMessage

        internal static Object DoAsyncDispatchCallback(Object[] args)
        {
            AsyncWorkItem   workItem = null;
            
            IMessage        reqMsg      = (IMessage) args[0];
            IMessageSink    replySink   = (IMessageSink) args[1];
            Context         oldCtx      = (Context) args[2];
            Context         srvCtx      = (Context) args[3];
            IMessageCtrl    msgCtrl     = null;

            
            // we use the work item just as our replySink in this case
            if (replySink != null)
            {
                 workItem = new AsyncWorkItem(replySink, oldCtx); 
            }
            Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: passing to ServerContextChain");
            // call the server context chain
            msgCtrl = 
                srvCtx.GetServerContextChain().AsyncProcessMessage(reqMsg, (IMessageSink)workItem);
            Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: back from ServerContextChain");

            return msgCtrl;
        }
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink) 
        {
            Message.DebugOut("::::::::::::::::::::::::::: CrossContext Channel: Async call starting!!\n");
            // One way Async notifications may potentially pass a null reply sink.
            IMessage errMsg = ValidateMessage(reqMsg);

            Object[] args = new Object[] { null, null, null, null };
            
            IMessageCtrl    msgCtrl  = null;
            if (errMsg != null)
            {
                if (replySink!=null)
                {
                    replySink.SyncProcessMessage(errMsg);
                }
            }
            else
            {
                ServerIdentity srvID = GetServerIdentity(reqMsg);
                
                // If active, notify the profiler that an asynchronous remoting message was received.
                if (RemotingServices.CORProfilerTrackRemotingAsync())
                {
                    Guid g = Guid.Empty;

                    if (RemotingServices.CORProfilerTrackRemotingCookie())
                    {
                        Object obj = reqMsg.Properties["CORProfilerCookie"];

                        if (obj != null)
                        {
                            g = (Guid) obj;
                        }
                    }

                    RemotingServices.CORProfilerRemotingServerReceivingMessage(g, true);

                    // Only wrap the replySink if the call wants a reply
                    if (replySink != null)
                    {
                        // Now wrap the reply sink in our own so that we can notify the profiler of
                        // when the reply is sent.  Upon invocation, it will notify the profiler
                        // then pass control on to the replySink passed in above.
                        IMessageSink profSink = new ServerAsyncReplyTerminatorSink(replySink);

                        // Replace the reply sink with our own
                        replySink = profSink;
                    }
                }

                Context         srvCtx   = srvID.ServerContext;
                if (srvCtx.IsThreadPoolAware)
                {
                    // this is the case when we do not queue the work item since the 
                    // server context claims to be doing its own threading.

                    args[0] = reqMsg;
                    args[1] = replySink;
                    args[2] = Thread.CurrentContext;
                    args[3] = srvCtx;

                    InternalCrossContextDelegate xctxDel = new InternalCrossContextDelegate(AsyncProcessMessageCallback);

                    msgCtrl = (IMessageCtrl) Thread.CurrentThread.InternalCrossContextCallback(srvCtx, xctxDel, args);
                }
                else
                {
                    AsyncWorkItem   workItem = null;
                    
                    // This is the case where we take care of returning the calling
                    // thread asap by using the ThreadPool for completing the call.
                    
                    // we use a more elaborate WorkItem and delegate the work to the thread pool
                    workItem = new AsyncWorkItem(reqMsg, 
                                                 replySink, 
                                                 Thread.CurrentContext, 
                                                 srvID);
    
                    WaitCallback threadFunc = new WaitCallback(workItem.FinishAsyncWork);
                    // Note: Dynamic sinks are notified in the threadFunc
                    ThreadPool.QueueUserWorkItem(threadFunc);
                }
            }
    
            Message.DebugOut("::::::::::::::::::::::::::: CrossContext Channel: Async call returning!!\n");
            return msgCtrl;
        } // AsyncProcessMessage
        internal static Object AsyncProcessMessageCallback(Object[] args)
        {
            AsyncWorkItem   workItem = null;

            IMessage        reqMsg      = (IMessage) args[0];
            IMessageSink    replySink   = (IMessageSink) args[1];
            Context         oldCtx      = (Context) args[2];
            Context         srvCtx      = (Context) args[3];
            IMessageCtrl    msgCtrl     = null;
            
            // we use the work item just as our replySink in this case
            if (replySink != null)
            {
                workItem = new AsyncWorkItem(replySink, oldCtx); 
            }
            
            Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: passing to ServerContextChain");

            srvCtx.NotifyDynamicSinks(
                     reqMsg,
                     false,  // bCliSide
                     true,   // bStart
                     true,   // bAsync
                     true);  // bNotifyGlobals

            // call the server context chain
            msgCtrl = 
                srvCtx.GetServerContextChain().AsyncProcessMessage(
                    reqMsg, 
                    (IMessageSink)workItem);

            // Note: for async calls, we will do the return notification
            // for dynamic properties only when the async call 
            // completes (i.e. when the replySink gets called) 

            Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: back from ServerContextChain");

            return msgCtrl;
        }
Esempio n. 19
0
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            Message.DebugOut("::::::::::::::::::::::::::: CrossContext Channel: Async call starting!!\n");
            // One way Async notifications may potentially pass a null reply sink.
            IMessage     errMsg  = ValidateMessage(reqMsg);
            IMessageCtrl msgCtrl = null;

            if (errMsg != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(errMsg);
                }
            }
            else
            {
                ServerIdentity srvID    = GetServerIdentity(reqMsg);
                AsyncWorkItem  workItem = null;

                // If active, notify the profiler that an asynchronous remoting message was received.
                if (RemotingServices.CORProfilerTrackRemotingAsync())
                {
                    Guid g = Guid.Empty;

                    if (RemotingServices.CORProfilerTrackRemotingCookie())
                    {
                        Object obj = reqMsg.Properties["CORProfilerCookie"];

                        if (obj != null)
                        {
                            g = (Guid)obj;
                        }
                    }

                    RemotingServices.CORProfilerRemotingServerReceivingMessage(g, true);

                    // Only wrap the replySink if the call wants a reply
                    if (replySink != null)
                    {
                        // Now wrap the reply sink in our own so that we can notify the profiler of
                        // when the reply is sent.  Upon invocation, it will notify the profiler
                        // then pass control on to the replySink passed in above.
                        IMessageSink profSink = new ServerAsyncReplyTerminatorSink(replySink);

                        // Replace the reply sink with our own
                        replySink = profSink;
                    }
                }

                Context srvCtx = srvID.ServerContext;
                if (srvCtx.IsThreadPoolAware)
                {
                    // this is the case when we do not queue the work item since the
                    // server context claims to be doing its own threading.

                    Context oldCtx = Thread.CurrentContext;
                    // change to server object context
                    ContextTransitionFrame frame = new ContextTransitionFrame();
                    srvCtx = srvID.ServerContext;
                    Thread.CurrentThread.EnterContext(srvCtx, ref frame);

                    // we use the work item just as our replySink in this case
                    if (replySink != null)
                    {
                        workItem = new AsyncWorkItem(replySink, oldCtx);
                    }

                    Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: passing to ServerContextChain");

                    srvCtx.NotifyDynamicSinks(
                        reqMsg,
                        false,          // bCliSide
                        true,           // bStart
                        true,           // bAsync
                        true);          // bNotifyGlobals

                    // call the server context chain
                    msgCtrl =
                        srvCtx.GetServerContextChain().AsyncProcessMessage(
                            reqMsg,
                            (IMessageSink)workItem);

                    // Note: for async calls, we will do the return notification
                    // for dynamic properties only when the async call
                    // completes (i.e. when the replySink gets called)

                    Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: back from ServerContextChain");

                    // chain back to the dispatch thread context
                    Thread.CurrentThread.ReturnToContext(ref frame);
                }
                else
                {
                    // This is the case where we take care of returning the calling
                    // thread asap by using the ThreadPool for completing the call.

                    // we use a more elaborate WorkItem and delegate the work to the thread pool
                    workItem = new AsyncWorkItem(reqMsg,
                                                 replySink,
                                                 Thread.CurrentContext,
                                                 srvID);

                    WaitCallback threadFunc = new WaitCallback(workItem.FinishAsyncWork);
                    // Note: Dynamic sinks are notified in the threadFunc
                    ThreadPool.QueueUserWorkItem(threadFunc);

                    msgCtrl = null;
                }
            }

            Message.DebugOut("::::::::::::::::::::::::::: CrossContext Channel: Async call returning!!\n");
            return(msgCtrl);
        } // AsyncProcessMessage
Esempio n. 20
0
        } // AsyncProcessMessage


        internal static IMessageCtrl DoAsyncDispatch(IMessage reqMsg, IMessageSink replySink)
        {
            ServerIdentity srvID = GetServerIdentity(reqMsg);
            AsyncWorkItem workItem = null;
            
            // If active, notify the profiler that an asynchronous remoting message was received.
            if (RemotingServices.CORProfilerTrackRemotingAsync())
            {
                Guid g = Guid.Empty;

                if (RemotingServices.CORProfilerTrackRemotingCookie())
                {
                    Object obj = reqMsg.Properties["CORProfilerCookie"];
                    if (obj != null)
                        g = (Guid) obj;
                }

                RemotingServices.CORProfilerRemotingServerReceivingMessage(g, true);

                // Only wrap the replySink if the call wants a reply
                if (replySink != null)
                {
                    // Now wrap the reply sink in our own so that we can notify the profiler of
                    // when the reply is sent.  Upon invocation, it will notify the profiler
                    // then pass control on to the replySink passed in above.
                    IMessageSink profSink = 
                        new ServerAsyncReplyTerminatorSink(replySink);

                    // Replace the reply sink with our own
                    replySink = profSink;
                }
            }

            Context srvCtx = srvID.ServerContext;
            
            //if (srvCtx.IsThreadPoolAware)
            //{
                // this is the case when we do not queue the work item since the 
                // server context claims to be doing its own threading.

                Context oldCtx = Thread.CurrentContext;                     
                // change to server object context
                ContextTransitionFrame frame = new ContextTransitionFrame();
                Thread.CurrentThread.EnterContext(srvID.ServerContext, ref frame);

                // we use the work item just as our replySink in this case
                if (replySink != null)
                {
                     workItem = new AsyncWorkItem(replySink, oldCtx); 
                }
                Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: passing to ServerContextChain");
                // call the server context chain
                IMessageCtrl msgCtrl = 
                    srvID.ServerContext.GetServerContextChain().AsyncProcessMessage(reqMsg, (IMessageSink)workItem);
                Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: back from ServerContextChain");
                // chain back to the dispatch thread context
                Thread.CurrentThread.ReturnToContext(ref frame);
    
            //}

            return msgCtrl;
        } // DoDispatch
Esempio n. 21
0
        } // AsyncProcessMessage

        internal static IMessageCtrl DoAsyncDispatch(IMessage reqMsg, IMessageSink replySink)
        {
            ServerIdentity srvID    = GetServerIdentity(reqMsg);
            AsyncWorkItem  workItem = null;

            // If active, notify the profiler that an asynchronous remoting message was received.
            if (RemotingServices.CORProfilerTrackRemotingAsync())
            {
                Guid g = Guid.Empty;

                if (RemotingServices.CORProfilerTrackRemotingCookie())
                {
                    Object obj = reqMsg.Properties["CORProfilerCookie"];
                    if (obj != null)
                    {
                        g = (Guid)obj;
                    }
                }

                RemotingServices.CORProfilerRemotingServerReceivingMessage(g, true);

                // Only wrap the replySink if the call wants a reply
                if (replySink != null)
                {
                    // Now wrap the reply sink in our own so that we can notify the profiler of
                    // when the reply is sent.  Upon invocation, it will notify the profiler
                    // then pass control on to the replySink passed in above.
                    IMessageSink profSink =
                        new ServerAsyncReplyTerminatorSink(replySink);

                    // Replace the reply sink with our own
                    replySink = profSink;
                }
            }

            Context srvCtx = srvID.ServerContext;

            //if (srvCtx.IsThreadPoolAware)
            //{
            // this is the case when we do not queue the work item since the
            // server context claims to be doing its own threading.

            Context oldCtx = Thread.CurrentContext;
            // change to server object context
            ContextTransitionFrame frame = new ContextTransitionFrame();

            Thread.CurrentThread.EnterContext(srvID.ServerContext, ref frame);

            // we use the work item just as our replySink in this case
            if (replySink != null)
            {
                workItem = new AsyncWorkItem(replySink, oldCtx);
            }
            Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: passing to ServerContextChain");
            // call the server context chain
            IMessageCtrl msgCtrl =
                srvID.ServerContext.GetServerContextChain().AsyncProcessMessage(reqMsg, (IMessageSink)workItem);

            Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: back from ServerContextChain");
            // chain back to the dispatch thread context
            Thread.CurrentThread.ReturnToContext(ref frame);

            //}

            return(msgCtrl);
        } // DoDispatch
Esempio n. 22
0
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink) 
        {
            Message.DebugOut("::::::::::::::::::::::::::: CrossContext Channel: Async call starting!!\n");
            // One way Async notifications may potentially pass a null reply sink.
            IMessage errMsg = ValidateMessage(reqMsg);
            IMessageCtrl msgCtrl=null;
            
            if (errMsg != null)
            {
                if (replySink!=null)
                {
                    replySink.SyncProcessMessage(errMsg);
                }
            }
            else
            {
                ServerIdentity srvID = GetServerIdentity(reqMsg);
                AsyncWorkItem workItem = null;
                
                // If active, notify the profiler that an asynchronous remoting message was received.
                if (RemotingServices.CORProfilerTrackRemotingAsync())
                {
                    Guid g = Guid.Empty;

                    if (RemotingServices.CORProfilerTrackRemotingCookie())
                    {
                        Object obj = reqMsg.Properties["CORProfilerCookie"];

                        if (obj != null)
                        {
                            g = (Guid) obj;
                        }
                    }

                    RemotingServices.CORProfilerRemotingServerReceivingMessage(g, true);

                    // Only wrap the replySink if the call wants a reply
                    if (replySink != null)
                    {
                        // Now wrap the reply sink in our own so that we can notify the profiler of
                        // when the reply is sent.  Upon invocation, it will notify the profiler
                        // then pass control on to the replySink passed in above.
                        IMessageSink profSink = new ServerAsyncReplyTerminatorSink(replySink);

                        // Replace the reply sink with our own
                        replySink = profSink;
                    }
                }

                Context srvCtx = srvID.ServerContext;
                if (srvCtx.IsThreadPoolAware)
                {
                    // this is the case when we do not queue the work item since the 
                    // server context claims to be doing its own threading.

                    Context oldCtx = Thread.CurrentContext;                     
                    // change to server object context
                    ContextTransitionFrame frame = new ContextTransitionFrame();
                    srvCtx = srvID.ServerContext;
                    Thread.CurrentThread.EnterContext(srvCtx, ref frame);

                    // we use the work item just as our replySink in this case
                    if (replySink != null)
                    {
                         workItem = new AsyncWorkItem(replySink, oldCtx); 
                    }

                    Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: passing to ServerContextChain");

                    srvCtx.NotifyDynamicSinks(
                                reqMsg,
                                false,  // bCliSide
                                true,   // bStart
                                true,   // bAsync
                                true);  // bNotifyGlobals

                    // call the server context chain
                    msgCtrl = 
                        srvCtx.GetServerContextChain().AsyncProcessMessage(
                            reqMsg, 
                            (IMessageSink)workItem);

                    // Note: for async calls, we will do the return notification
                    // for dynamic properties only when the async call 
                    // completes (i.e. when the replySink gets called) 

                    Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: back from ServerContextChain");

                    // chain back to the dispatch thread context
                    Thread.CurrentThread.ReturnToContext(ref frame);
    
                }
                else
                {
                    // This is the case where we take care of returning the calling
                    // thread asap by using the ThreadPool for completing the call.
                    
                    // we use a more elaborate WorkItem and delegate the work to the thread pool
                    workItem = new AsyncWorkItem(reqMsg, 
                                                replySink, 
                                                Thread.CurrentContext, 
                                                srvID);
    
                    WaitCallback threadFunc = new WaitCallback(workItem.FinishAsyncWork);
                    // Note: Dynamic sinks are notified in the threadFunc
                    ThreadPool.QueueUserWorkItem(threadFunc);
                    
                    msgCtrl = null;
                }
            }
    
            Message.DebugOut("::::::::::::::::::::::::::: CrossContext Channel: Async call returning!!\n");
            return msgCtrl;
        } // AsyncProcessMessage
 internal static object DoAsyncDispatchCallback(object[] args)
 {
     AsyncWorkItem replySink = null;
     IMessage msg = (IMessage) args[0];
     IMessageSink sink = (IMessageSink) args[1];
     Context oldCtx = (Context) args[2];
     Context context2 = (Context) args[3];
     if (sink != null)
     {
         replySink = new AsyncWorkItem(sink, oldCtx);
     }
     return context2.GetServerContextChain().AsyncProcessMessage(msg, replySink);
 }