internal static IMessageCtrl DoAsyncDispatch(IMessage reqMsg, IMessageSink replySink)
        {
            object[]       args           = new object[4];
            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;

            args[0] = reqMsg;
            args[1] = replySink;
            args[2] = Thread.CurrentContext;
            args[3] = serverContext;
            InternalCrossContextDelegate ftnToCall = new InternalCrossContextDelegate(CrossContextChannel.DoAsyncDispatchCallback);

            return((IMessageCtrl)Thread.CurrentThread.InternalCrossContextCallback(serverContext, ftnToCall, args));
        }
Пример #2
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static IMessageCtrl DoAsyncDispatch(IMessage reqMsg, IMessageSink replySink)
        {
            Object[] args = new Object[] { null, null, null, null };

            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;
                }
            }

            IMessageCtrl msgCtrl = null;
            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(DoAsyncDispatchCallback);

            msgCtrl = (IMessageCtrl)Thread.CurrentThread.InternalCrossContextCallback(srvCtx, xctxDel, args);

            //}

            return(msgCtrl);
        } // DoDispatch
        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);
        }
 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;
 }
Пример #6
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
        internal static IMessageCtrl DoAsyncDispatch(IMessage reqMsg, IMessageSink replySink)
        {
            Object[] args = new Object[] { null, null, null, null };
                
            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;
                }
            }

            IMessageCtrl msgCtrl = null;
            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(DoAsyncDispatchCallback);
                
                msgCtrl = (IMessageCtrl) Thread.CurrentThread.InternalCrossContextCallback(srvCtx, xctxDel, args);

            //}

            return msgCtrl;
        } // DoDispatch
        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
Пример #9
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
Пример #10
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
Пример #11
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
Пример #12
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 IMessageCtrl DoAsyncDispatch(IMessage reqMsg, IMessageSink replySink)
 {
     object[] args = new object[4];
     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;
     args[0] = reqMsg;
     args[1] = replySink;
     args[2] = Thread.CurrentContext;
     args[3] = serverContext;
     InternalCrossContextDelegate ftnToCall = new InternalCrossContextDelegate(CrossContextChannel.DoAsyncDispatchCallback);
     return (IMessageCtrl) Thread.CurrentThread.InternalCrossContextCallback(serverContext, ftnToCall, args);
 }