/// <summary>
        /// Constructor.
        /// </summary>
        public ConversationPointToPoint(ExecutionManager executionManager, Message message, ArbiterClientId senderID, ArbiterClientId receiverID, TimeSpan timeOut)
            : base(executionManager, senderID, timeOut)
        {
            _receiverID = receiverID;

            ExecutionEntityWithReply entity = new ExecutionEntityWithReply(this, receiverID, timeOut,
                                                                           MessageContainer.DuplicateMessage(message, false));

            ExecutionManager.AddExecutionEntity(entity);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public ConversationPointToPoint(ExecutionManager executionManager, Message message, ArbiterClientId senderID, ArbiterClientId receiverID, TimeSpan timeOut)
            : base(executionManager, senderID, timeOut)
        {
            _receiverID = receiverID;

            ExecutionEntityWithReply entity = new ExecutionEntityWithReply(this, receiverID, timeOut,
                MessageContainer.DuplicateMessage(message, false));

            ExecutionManager.AddExecutionEntity(entity);
        }
        /// <summary>
        /// Entity execution has finished.
        /// </summary>
        public override void EntityExecutionFinished(ExecutionEntity entity)
        {
            ExecutionEntityWithReply entityWithReply = (ExecutionEntityWithReply)entity;

            if (entityWithReply.ReplyMessage != null)
            {// The other side replied.
                ArbiterClientId messageReceiver = ReceiverID;

                if (_receiverID.Equals(entity.ReceiverID))
                {// Swap direction, receiver must now send.
                    messageReceiver = SenderID;
                }

                ExecutionEntityWithReply replyEntity = new ExecutionEntityWithReply(this, messageReceiver, entityWithReply.TimeOut,
                                                                                    MessageContainer.DuplicateMessage(entityWithReply.ReplyMessage, false));

                ExecutionManager.AddExecutionEntity(replyEntity);
            }
            else
            {// We received a nothing, conversation done, die.
                this.Die();
            }
        }
        /// <summary>
        /// Entity execution has finished.
        /// </summary>
        public override void EntityExecutionFinished(ExecutionEntity entity)
        {
            ExecutionEntityWithReply entityWithReply = (ExecutionEntityWithReply)entity;
            if (entityWithReply.ReplyMessage != null)
            {// The other side replied.

                ArbiterClientId messageReceiver = ReceiverID;

                if (_receiverID.Equals(entity.ReceiverID))
                {// Swap direction, receiver must now send.
                    messageReceiver = SenderID;
                }

                ExecutionEntityWithReply replyEntity = new ExecutionEntityWithReply(this, messageReceiver, entityWithReply.TimeOut,
                    MessageContainer.DuplicateMessage(entityWithReply.ReplyMessage, false));

                ExecutionManager.AddExecutionEntity(replyEntity);
            }
            else
            {// We received a nothing, conversation done, die.
                this.Die();
            }
        }
示例#5
0
 public override void ReceiveExecutionWithReply(ExecutionEntityWithReply entity)
 {
     SystemMonitor.CheckError(entity.Message.GetType().IsSubclassOf(typeof(TransportMessage)));
     OnMessageReceived((TransportMessage)entity.Message);
 }
 public abstract void ReceiveExecutionWithReply(ExecutionEntityWithReply entity);
示例#7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="entity"></param>
 public override void ReceiveExecutionWithReply(ExecutionEntityWithReply entity)
 {// Logging does not need to be talked to directly.
     throw new Exception("UnImplemented.");
 }
示例#8
0
        /// <summary>
        ///
        /// </summary>
        void worker_DoWork(ExecutionEntity entity)
        {
            lock (this)
            {
                if (_clientsRunningExecutioners.ContainsKey(entity.ReceiverID) == false)
                {
                    _clientsRunningExecutioners[entity.ReceiverID] = 1;
                }
                else
                {
                    _clientsRunningExecutioners[entity.ReceiverID] = _clientsRunningExecutioners[entity.ReceiverID] + 1;
                }
            }

            TracerHelper.Trace(" Enlisted entity at [" + entity.ReceiverID.Id.Name + "]");

            DateTime startTime = DateTime.Now;

            TracerHelper.TraceEntry("entity starting [" + entity.Message.GetType().Name + ", " +
                                    entity.ReceiverID.Id.Name + "], total count [" + _threadPool.ActiveRunningThreadsCount.ToString() + "]");

            // Notify executor we are running this entity.
            entity.Conversation.EntityExecutionStarted(entity);

            try
            {
                IArbiterClient receiver = _arbiter.GetClientByID(entity.ReceiverID);
                if (receiver != null)
                {
                    SystemMonitor.CheckError(((TransportMessage)entity.Message).TransportInfo.TransportInfoCount > 0);

                    // Do the entity.
                    if (entity is ExecutionEntityWithReply)
                    {
                        ExecutionEntityWithReply replyEntity = (ExecutionEntityWithReply)entity;
                        SystemMonitor.CheckError(replyEntity.ReplyMessage == null && replyEntity.ReplyTimeOut == TimeSpan.Zero);
                        receiver.ReceiveExecutionWithReply(replyEntity);
                    }
                    else
                    {
                        SystemMonitor.CheckError(entity.GetType() == typeof(ExecutionEntity));
                        receiver.ReceiveExecution(entity);
                    }
                    entity.Conversation.EntityExecutionFinished(entity);
                }
            }
            catch (TargetInvocationException exception)
            {
                if (exception.InnerException is ThreadInterruptedException)
                {// ThreadInterruptedException's are OK, since we use them to awake sleeping threads when closing down.
                    SystemMonitor.Report(exception.ToString() + "[" + exception.InnerException.Message + "]");
                    entity.Conversation.EntityExecutionFailed(entity, exception);
                }
                else
                {
                    SystemMonitor.OperationError(exception.ToString() + "[" + exception.InnerException.Message + "]");
                    entity.Conversation.EntityExecutionFailed(entity, exception);
                }
            }
            catch (ThreadInterruptedException exception)
            {
                // ThreadInterruptedException's are OK, since we use them to awake sleeping threads when closing down.
                SystemMonitor.Report(exception.ToString() + "[" + exception.Message + "]");
                entity.Conversation.EntityExecutionFailed(entity, exception);
            }
            catch (Exception exception)
            {
                SystemMonitor.Error(exception.ToString());
                entity.Conversation.EntityExecutionFailed(entity, exception);
            }
            finally
            {
                entity.Die();
            }

            lock (this)
            {
                if (_clientsRunningExecutioners.ContainsKey(entity.ReceiverID))
                {
                    int newClientsValue = _clientsRunningExecutioners[entity.ReceiverID] - 1;
                    if (newClientsValue <= 0)
                    {
                        _clientsRunningExecutioners.Remove(entity.ReceiverID);
                    }
                    else
                    {
                        _clientsRunningExecutioners[entity.ReceiverID] = newClientsValue;
                    }
                }
                else
                {
                    if (IsDisposed == false)
                    {
                        SystemMonitor.Error("ClientsRunningExecutioners not properly maintained.");
                    }
                }

                TracerHelper.TraceExit("entity finished for [" + (DateTime.Now - startTime).Milliseconds + "]ms [" + entity.Message.GetType().Name + ", " + entity.ReceiverID.Id.Name + "], total count [" + _threadPool.ActiveRunningThreadsCount.ToString() + "]");
            }

            // Continue execution chain.
            UpdatePendingExecution();
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="entity"></param>
 public override void ReceiveExecutionWithReply(ExecutionEntityWithReply entity)
 {
     // Logging does not need to be talked to directly.
     throw new Exception("UnImplemented.");
 }
 public abstract void ReceiveExecutionWithReply(ExecutionEntityWithReply entity);