public override void EntityExecutionStarted(ExecutionEntity entity)
 {
     lock (_executingEntities)
     {
         SystemMonitor.CheckError(_executingEntities.Contains(entity), "Removing entity not present in conversation.");
     }
 }
 public override void EntityExecutionFailed(ExecutionEntity entity, Exception exception)
 {
     SystemMonitor.Error("Execution of entity failed [" + exception.ToString() + "].");
     lock (_executingEntities)
     {
         SystemMonitor.CheckError(_executingEntities.Contains(entity), "Removing entity not present in conversation.");
         _executingEntities.Remove(entity);
     }
 }
Beispiel #3
0
 public override void EntityExecutionFailed(ExecutionEntity entity, Exception exception)
 {
     SystemMonitor.Error("Execution of entity failed [" + exception.ToString() + "].");
     lock (_executingEntities)
     {
         SystemMonitor.CheckError(_executingEntities.Contains(entity), "Removing entity not present in conversation.");
         _executingEntities.Remove(entity);
     }
 }
Beispiel #4
0
 public override void EntityTimedOut(ExecutionEntity entity)
 {
     lock (_executingEntities)
     {
         SystemMonitor.CheckError(_executingEntities.Contains(entity), "Removing entity not present in conversation.");
         _executingEntities.Remove(entity);
     }
     this.SetTimedOut();
 }
        /// 
        /// </summary>
        public ConversationMultiPoint(ExecutionManager executionManager, Message message, ArbiterClientId senderID, IEnumerable<ArbiterClientId> receivers, TimeSpan timeOut)
            : base(executionManager, senderID, timeOut)
        {
            _receivers.AddRange(receivers);

            foreach (ArbiterClientId receiverID in receivers)
            {
                ExecutionEntity entity = new ExecutionEntity(this, receiverID, TimeSpan.Zero, MessageContainer.DuplicateMessage(message, false));
                _executingEntities.Add(entity);
                ExecutionManager.AddExecutionEntity(entity);
            }
        }
Beispiel #6
0
        ///
        /// </summary>
        public ConversationMultiPoint(ExecutionManager executionManager, Message message, ArbiterClientId senderID, IEnumerable <ArbiterClientId> receivers, TimeSpan timeOut)
            : base(executionManager, senderID, timeOut)
        {
            _receivers.AddRange(receivers);

            foreach (ArbiterClientId receiverID in receivers)
            {
                ExecutionEntity entity = new ExecutionEntity(this, receiverID, TimeSpan.Zero, MessageContainer.DuplicateMessage(message, false));
                _executingEntities.Add(entity);
                ExecutionManager.AddExecutionEntity(entity);
            }
        }
        public override void EntityExecutionFinished(ExecutionEntity entity)
        {
            lock (_executingEntities)
            {
                SystemMonitor.CheckError(_executingEntities.Contains(entity), "Removing entity not present in conversation.");
                _executingEntities.Remove(entity);

                if (_executingEntities.Count == 0)
                {// OK, we are done.
                    this.Die();
                }
            }
        }
Beispiel #8
0
        public override void EntityExecutionFinished(ExecutionEntity entity)
        {
            lock (_executingEntities)
            {
                SystemMonitor.CheckError(_executingEntities.Contains(entity), "Removing entity not present in conversation.");
                _executingEntities.Remove(entity);

                if (_executingEntities.Count == 0)
                {// OK, we are done.
                    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();
            }
        }
        /// <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();
            }
        }
 public abstract void EntityTimedOut(ExecutionEntity entity);
Beispiel #12
0
        /// <summary>
        /// Obtain the next execution entity and remove it from pending.
        /// Children to override to manage the way operations are performed, if they need to.
        /// This is where currently the MultiThreads per client protection is performed.
        /// </summary>
        protected virtual ExecutionEntity PopNextExecutionEntity()
        {
            lock (this)
            {
                // Check total executioners count.
                if (_threadPool.FreeThreadsCount < 2)
                {
                    //if ((DateTime.Now - _executionersBusyWarningShownTime) >= _warningsTimeSpan)
                    {
                        SystemMonitor.OperationError("All of the [" + _threadPool.MaximumThreadsCount + "] arbiter [" + _arbiter.Name + "] executioners are busy, entity execution delayed.", TracerItem.PriorityEnum.Medium);
                        //_executionersBusyWarningShownTime = DateTime.Now;
                    }

                    return(null);
                }

                // List of IDs we tried to execute upon already, and presumably failed.
                List <ArbiterClientId> processedIds = new List <ArbiterClientId>();

                // Try looking for a new entity.
                for (int i = 0; i < _pendingEntities.Count; i++)
                {// Look for an entity that we are allowed to execute now.
                    ExecutionEntity entity  = _pendingEntities[i];
                    IArbiterClient  iClient = _arbiter.GetClientByID(entity.ReceiverID);

                    if (processedIds.Contains(entity.ReceiverID))
                    {// Alredy tried on this entity, skip.
                        continue;
                    }
                    else
                    {// First time we see this entity.
                        processedIds.Add(entity.ReceiverID);
                    }

                    bool isTransportResponseMessage = (entity.Message is TransportMessage &&
                                                       ((TransportMessage)(entity.Message)).IsRequest == false);

                    int runningOnClient = 0;
                    if (_clientsRunningExecutioners.ContainsKey(entity.ReceiverID))
                    {
                        runningOnClient = _clientsRunningExecutioners[entity.ReceiverID];
                    }

                    if (isTransportResponseMessage == false && iClient != null &&
                        iClient.SingleThreadMode && runningOnClient > 0 /*_executionersAndClientIDs.ContainsValue(entity.ReceiverID)*/)
                    {// We are not allowed to run this, as there is already an executioner there.
                        // And it is not a responce requestMessage.
                        continue;
                    }

                    if (runningOnClient >= _maxExecutionersPerEntity)
                    {// This entity is already consuming too many threads. It must release some before using more.
                        //if ((DateTime.Now - _executionersBusyWarningShownTime) >= _warningsTimeSpan)
                        {
                            //_executionersBusyWarningShownTime = DateTime.Now;
                            SystemMonitor.OperationError("An entity [" + entity.ReceiverID.Id.Name + "] is using all its threads allowed. Further entity executions will be delayed.", TracerItem.PriorityEnum.Medium);
                        }

                        continue;
                    }

                    //TraceHelper.Trace("PopNextExecutionEntity [" + iClient.ToString() + "][" + iClient.SingleThreadMode + "," + _executionersAndClientIDs.ContainsValue(entity.ReceiverID) + "][" + entity.Message.ToString() + "]");

                    _pendingEntities.Remove(entity);

                    // OK, this entity is good to go.
                    return(entity);
                }

                return(null);
            }
        }
 public abstract void ReceiveExecution(ExecutionEntity entity);
Beispiel #14
0
 public abstract void EntityTimedOut(ExecutionEntity entity);
Beispiel #15
0
 public abstract void EntityExecutionStarted(ExecutionEntity entity);
 public BackgroundWorkerEx(ExecutionEntity entity)
 {
     _entity = entity;
 }
 /// <summary>
 /// Entity has timed out.
 /// </summary>
 /// <param name="entity"></param>
 public override void EntityTimedOut(ExecutionEntity entity)
 {
     this.SetTimedOut();
 }
 /// <summary>
 /// Entity has timed out.
 /// </summary>
 /// <param name="entity"></param>
 public override void EntityTimedOut(ExecutionEntity entity)
 {
     this.SetTimedOut();
 }
 public BackgroundWorkerEx(ExecutionEntity entity)
 {
     _entity = entity;
 }
Beispiel #20
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();
        }
 public override void EntityTimedOut(ExecutionEntity entity)
 {
     lock (_executingEntities)
     {
         SystemMonitor.CheckError(_executingEntities.Contains(entity), "Removing entity not present in conversation.");
         _executingEntities.Remove(entity);
     }
     this.SetTimedOut();
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        public void AddExecutionEntity(ExecutionEntity entity)
        {
            TracerHelper.TraceEntry();
            lock (this)
            {
                if (_pendingEntities.Count > _maxPendingExecutionItems)
                {
                    TracerHelper.TraceError("Too many pending entities in system. Some older entities are being dropped.");
                    if ((DateTime.Now - _maxPendingItemsWarningShownTime) > _warningsTimeSpan)
                    {
                        _maxPendingItemsWarningShownTime = DateTime.Now;
                        SystemMonitor.Error("Too many pending entities in system. Some older entities are being dropped.");
                    }

                    // Loose the oldest entity in line.
                    _timeOutMonitor.RemoveEntity(_pendingEntities[0]);
                    _pendingEntities.RemoveAt(0);
                }

                _timeOutMonitor.AddEntity(entity);
                _pendingEntities.Add(entity);
            }

            // Continue execution chain.
            UpdatePendingExecution();
        }
        /// <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>
 /// Entity execution has started.
 /// </summary>
 public override void EntityExecutionStarted(ExecutionEntity entity)
 {
 }
 public override void EntityExecutionFailed(ExecutionEntity entity, Exception exception)
 {
     SystemMonitor.OperationError("Entity execution failed [" + exception.ToString() + "].", TracerItem.PriorityEnum.Medium);
     this.Die();
 }
 public abstract void ReceiveExecution(ExecutionEntity entity);
 public override void EntityExecutionFailed(ExecutionEntity entity, Exception exception)
 {
     SystemMonitor.OperationError("Entity execution failed [" + exception.ToString() + "].", TracerItem.PriorityEnum.Medium);
     this.Die();
 }
 /// <summary>
 /// Entity execution has started.
 /// </summary>
 public override void EntityExecutionStarted(ExecutionEntity entity)
 {
 }
Beispiel #29
0
        /// <summary>
        /// Custom XML logging.
        /// </summary>
        /// <param name="entity"></param>
        //public override void ReceiveExecution(ExecutionEntity entity)
        //{
        //    if (_xmlDoc == null || _xmlWriter == null)
        //    {
        //        return;
        //    }

        //    TraceHelper.Trace("Arbiter::ReceiveExecution");

        //    try
        //    {
        //        XmlText messageText = _xmlDoc.CreateTextNode("MessageNode");
        //        messageText.Value = entity.Message.ToString();

        //        XmlElement messageNode = _xmlDoc.CreateElement("Message");
        //        messageNode.AppendChild(messageText);
        //        messageNode.SetAttribute("Time", System.DateTime.Now.ToString());

        //        messageNode.WriteTo(_xmlWriter);
        //    }
        //    catch (Exception ex)
        //    {
        //        SystemMonitor.Error("Error occured while serializing logger requestMessage [" + ex.ToString() + "].");
        //    }

        //    _xmlWriter.Flush();
        //}


        public override void ReceiveExecution(ExecutionEntity entity)
        {
            ReceiveDirectCall(entity.Message);
        }
 public abstract void EntityExecutionFailed(ExecutionEntity entity, Exception exception);
Beispiel #31
0
 public abstract void EntityExecutionFinished(ExecutionEntity entity);
 public abstract void EntityExecutionFinished(ExecutionEntity entity);
Beispiel #33
0
 public abstract void EntityExecutionFailed(ExecutionEntity entity, Exception exception);
 public abstract void EntityExecutionStarted(ExecutionEntity entity);
Beispiel #35
0
 public override void ReceiveExecution(ExecutionEntity entity)
 {
     SystemMonitor.CheckError(entity.Message.GetType().IsSubclassOf(typeof(TransportMessage)));
     OnMessageReceived((TransportMessage)entity.Message);
 }
 /// <summary>
 /// Custom XML logging.
 /// </summary>
 /// <param name="entity"></param>
 //public override void ReceiveExecution(ExecutionEntity entity)
 //{
 //    if (_xmlDoc == null || _xmlWriter == null)
 //    {
 //        return;
 //    }
 //    TraceHelper.Trace("Arbiter::ReceiveExecution");
 //    try
 //    {
 //        XmlText messageText = _xmlDoc.CreateTextNode("MessageNode");
 //        messageText.Value = entity.Message.ToString();
 //        XmlElement messageNode = _xmlDoc.CreateElement("Message");
 //        messageNode.AppendChild(messageText);
 //        messageNode.SetAttribute("Time", System.DateTime.Now.ToString());
 //        messageNode.WriteTo(_xmlWriter);
 //    }
 //    catch (Exception ex)
 //    {
 //        SystemMonitor.Error("Error occured while serializing logger requestMessage [" + ex.ToString() + "].");
 //    }
 //    _xmlWriter.Flush();
 //}
 public override void ReceiveExecution(ExecutionEntity entity)
 {
     ReceiveDirectCall(entity.Message);
 }