示例#1
0
        /// <summary>
        /// An envelope has arrived from the messaging infrastructure.
        /// </summary>
        protected override void OnPerformExecution(Envelope envelope)
        {
            object messageConsumer = Source;

            if (messageConsumer == null || envelope.Message.GetType() != typeof(SuperPoolCall))
            {// This is a not a super pool call, or no message consumer.
                base.OnPerformExecution(envelope);
                return;
            }

            try
            {
                SuperPoolCall call = envelope.Message as SuperPoolCall;

                if (call.State == SuperPoolCall.StateEnum.Responding)
                {// Response.
                    object    response  = call.Parameters.Length > 0 ? call.Parameters[0] : null;
                    Exception exception = call.Parameters.Length > 1 ? call.Parameters[1] as Exception : null;

                    long callId = call.Id;

                    SyncCallInfo syncCallInfo = null;
                    lock (_syncCalls)
                    {
                        if (_syncCalls.TryGetValue(callId, out syncCallInfo))
                        {
                            if (syncCallInfo.IsMultiResponse == false)
                            {// Only remove single response ones, since we have 1 for sure.
                                _syncCalls.Remove(callId);
                            }
                        }
                        else
                        {
                            syncCallInfo = null;
                        }
                    }

                    if (syncCallInfo != null)
                    {
                        syncCallInfo.AcceptResponse(this, response, exception);

                        if (syncCallInfo.IsMultiResponse && syncCallInfo.IsMultiResponseComplete)
                        {
                            lock (_syncCalls)
                            {
                                _syncCalls.Remove(callId);
                            }
                        }
                    }
                }
                else if (call.State == SuperPoolCall.StateEnum.Requesting)
                {// Call (Request).
                    if (_consumerInterfacesHotSwap.Contains(call.MethodInfoLocal.ReflectedType))
                    {
                        object    result    = null;
                        Exception exception = null;
                        result = PerformCall(call, messageConsumer, out exception);

                        if (call.RequestResponse)
                        {
                            call.State = SuperPoolCall.StateEnum.Responding;
                            if (exception == null)
                            {
                                call.Parameters = new object[] { result };
                            }
                            else
                            {// Also transport the exception.
                                call.Parameters = new object[] { result, exception };
                            }

                            Matrix.Framework.SuperPool.Core.SuperPool pool = _superPool;
                            if (pool == null)
                            {
#if Matrix_Diagnostics
                                SystemMonitor.Error(this.GetType().Name + " has failed to find super pool instance, execution failed.");
#endif
                                return;
                            }

                            IMessageBus messageBus = pool.MessageBus;
                            if (messageBus == null)
                            {
#if Matrix_Diagnostics
                                SystemMonitor.Error(this.GetType().Name + " has failed to find super pool's message bus instance, execution failed.");
#endif
                                return;
                            }

                            messageBus.Respond(envelope, new Envelope(call)
                            {
                                DuplicationMode = EnvelopeDuplicationMode
                            });
                        }
                        else
                        {
                            call.State = SuperPoolCall.StateEnum.Finished;
                        }
                    }
                    else
                    {
                        if (call.MethodInfoLocal == null)
                        {
#if Matrix_Diagnostics
                            SystemMonitor.OperationError(string.Format("Call with no method info assigned ignored."));
#endif
                        }
                        else
                        {
#if Matrix_Diagnostics
                            SystemMonitor.OperationError(string.Format("Call to [{0}] not recognized.", call.MethodInfoLocal.ToString()));
#endif
                        }
                    }
                }
                else if (call.State == SuperPoolCall.StateEnum.EventRaise)
                {
                    Exception exception;
                    object    result = PerformCall(call, messageConsumer, out exception);
                    call.State = SuperPoolCall.StateEnum.Finished;
                }
            }
            catch (Exception ex)
            {// It is possible we encounter some invocation error (for ex. source type changed while call travelling)
             // so gracefully handle these here.
#if Matrix_Diagnostics
                SystemMonitor.OperationError("Execution failed", ex);
#endif
            }
        }
示例#2
0
        protected override void OnPerformExecution(Envelope envelope)
        {
            object source = this.Source;

            if (source == null || envelope.Message.GetType() != typeof(SuperPoolCall))
            {
                base.OnPerformExecution(envelope);
            }
            else
            {
                try
                {
                    SuperPoolCall call = envelope.Message as SuperPoolCall;
                    object        obj1;
                    if (call.State == SuperPoolCall.StateEnum.Responding)
                    {
                        object       result       = call.Parameters.Length > 0 ? call.Parameters[0] : (object)null;
                        Exception    exception    = call.Parameters.Length > 1 ? call.Parameters[1] as Exception : (Exception)null;
                        long         id           = call.Id;
                        SyncCallInfo syncCallInfo = (SyncCallInfo)null;
                        lock (this._syncCalls)
                        {
                            if (this._syncCalls.TryGetValue(id, out syncCallInfo))
                            {
                                if (!syncCallInfo.IsMultiResponse)
                                {
                                    this._syncCalls.Remove(id);
                                }
                            }
                            else
                            {
                                syncCallInfo = (SyncCallInfo)null;
                            }
                        }
                        if (syncCallInfo != null)
                        {
                            syncCallInfo.AcceptResponse(this, result, exception);
                            if (syncCallInfo.IsMultiResponse && syncCallInfo.IsMultiResponseComplete)
                            {
                                lock (this._syncCalls)
                                    this._syncCalls.Remove(id);
                            }
                        }
                    }
                    else if (call.State == SuperPoolCall.StateEnum.Requesting)
                    {
                        if (this._consumerInterfacesHotSwap.Contains(call.MethodInfoLocal.ReflectedType))
                        {
                            obj1 = (object)null;
                            Exception exception = (Exception)null;
                            object    obj2      = this.PerformCall(call, source, out exception);
                            if (call.RequestResponse)
                            {
                                call.State = SuperPoolCall.StateEnum.Responding;
                                if (exception == null)
                                {
                                    call.Parameters = new object[1]
                                    {
                                        obj2
                                    }
                                }
                                ;
                                else
                                {
                                    call.Parameters = new object[2]
                                    {
                                        obj2,
                                        (object)exception
                                    }
                                };
                                SuperPool superPool = this._superPool;
                                if (superPool == null)
                                {
                                    return;
                                }
                                IMessageBus messageBus = superPool.MessageBus;
                                if (messageBus == null)
                                {
                                    return;
                                }
                                int num = (int)messageBus.Respond(envelope, new Envelope((object)call)
                                {
                                    DuplicationMode = this.EnvelopeDuplicationMode
                                });
                            }
                            else
                            {
                                call.State = SuperPoolCall.StateEnum.Finished;
                            }
                        }
                        else if (call.MethodInfoLocal != null)
                        {
                            ;
                        }
                    }
                    else if (call.State == SuperPoolCall.StateEnum.EventRaise)
                    {
                        Exception exception;
                        obj1       = this.PerformCall(call, source, out exception);
                        call.State = SuperPoolCall.StateEnum.Finished;
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }