/// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="receiver"></param>
 /// <param name="timeOut"></param>
 /// <param name="requestMessage"></param>
 public ExecutionEntity(IExecutor executor, ArbiterClientId receiverID, TimeSpan timeOut, Message message)
     : base(timeOut)
 {
     _executor = executor;
     _receiverID = receiverID;
     _message = message;
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name">The name of this client module.</param>
        /// <param name="singleThreadOnly">Should the module be entered with single or multiple Arbiter threads.</param>
        public ArbiterClientBase(bool singleThreadOnly)
        {
            string name = UserFriendlyNameAttribute.GetTypeAttributeName(this.GetType());

            // Make sure not to use the default struct parameterless constructor.
            _subscriptionClientId = new ArbiterClientId(name, this.GetType(), this);

            _messageFilter = new MessageFilter(true);
            _singleThreadOnly = singleThreadOnly;
        }
        /// <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>
        /// 
        /// </summary>
        /// <param name="name">The name of this client module.</param>
        /// <param name="singleThreadOnly">Should the module be entered with single or multiple Arbiter threads.</param>
        public ArbiterClientBase(string idName, bool singleThreadOnly)
        {
            if (string.IsNullOrEmpty(idName))
            {// Try to establish user friendly name, or if not available, use class name.
                idName = UserFriendlyNameAttribute.GetTypeAttributeName(this.GetType());
            }

            _subscriptionClientId = new ArbiterClientId(idName, this.GetType(), this);
            _messageFilter = new MessageFilter(true);
            _singleThreadOnly = singleThreadOnly;
        }
        /// 
        /// </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);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public bool FullUnsubscribe(ArbiterClientId? originalSenderId)
        {
            if (originalSenderId.HasValue == false)
            {
                SystemMonitor.Error("Original sender not available in transport info.");
                return false;
            }

            lock (this)
            {
                return _subscriptions.Remove(originalSenderId.Value);
            }
        }
Esempio n. 7
0
        public ArbiterClientId[] GetComponentsArbiterIds(Type componentType)
        {
            List <PlatformComponent> components = GetComponentsByType(componentType);

            ArbiterClientId[] result = new ArbiterClientId[components.Count];

            for (int i = 0; i < components.Count; i++)
            {
                result[i] = components[i].SubscriptionClientID;
            }

            return(result);
        }
Esempio n. 8
0
        /// <summary>
        /// Check if some other component is operational, by arbiter client componentId.
        /// </summary>
        /// <param name="componentId"></param>
        /// <returns></returns>
        public OperationalStateEnum?GetComponentOperationalState(ArbiterClientId?id)
        {
            if (id.HasValue == false)
            {
                SystemMonitor.Error("Component Id not valid.");
                return(null);
            }

            ArbiterClientId idValue = id.Value;

            // Should a direct referencing be completely ommited, this call can be replaced with a requestMessage query to the platform.
            PlatformComponent component = GetComponentByIdentification(idValue.Id, true);

            if (component == null)
            {
                return(null);
            }

            return(component.OperationalState);
        }
        public bool Start(out string operationResultMessage)
        {// This will start the integration client.
            if (Arbiter == null)
            {
                operationResultMessage = "Arbiter not assigned.";
                return(false);
            }

            if (IsStarted)
            {
                operationResultMessage = "Adapter already started.";
                return(false);
            }

            if (_integrationClient == null)
            {
                _integrationClient = new TransportIntegrationClient(_integrationUri);
            }

            if (_integrationClient != null && _integrationClientId.IsEmpty == false)
            {
                _integrationClient.SetArbiterSubscriptionClientId(_integrationClientId);
            }

            _integrationClient.MandatoryRequestMessageReceiverID = this.SubscriptionClientID;

            _integrationClient.ConnectionStatusChangedEvent += new TransportIntegrationClient.ConnectionStatusChangedDelegate(_integrationClient_ConnectionStatusChangedEvent);
            Arbiter.AddClient(_integrationClient);
            _integrationClientId = _integrationClient.SubscriptionClientID;

            _isStarted = true;

            ChangeOperationalState(OperationalStateEnum.Initialized);

            operationResultMessage = string.Empty;
            return(true);
        }
 /// <summary>
 /// 
 /// </summary>
 public TransportMessageFilter(ArbiterClientId ownerID)
     : base(true)
 {
     _ownerID = ownerID;
 }
 /// <summary>
 /// 
 /// </summary>
 public Conversation(ExecutionManager executionManager, ArbiterClientId ownerID, TimeSpan timeOut)
     : base(timeOut)
 {
     _ownerID = ownerID;
     _executionManager = executionManager;
 }
 /// <summary>
 /// Deserialization constructor.
 /// </summary>
 /// <param name="singleThreadOnly"></param>
 public ArbiterClientBase(SerializationInfo info, StreamingContext context)
 {
     _subscriptionClientId = (ArbiterClientId)info.GetValue("clientId", typeof(ArbiterClientId));
     _messageFilter = (MessageFilter)info.GetValue("messageFilter", typeof(MessageFilter));
 }
 public ExecutionEntityWithReply(Conversation conversation, ArbiterClientId receiverID, TimeSpan timeOut, Message message)
     : base(conversation, receiverID, timeOut, message)
 {
 }
Esempio n. 14
0
        /// <summary>
        /// Find out what clients need to receive this requestMessage.
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public IEnumerable<ArbiterClientId> GatherMessageClients(Message message, ArbiterClientId senderID)
        {
            List<ArbiterClientId> clients = new List<ArbiterClientId>();
            if (_isDisposed)
            {// Possible to get disposed while operating here.
                return null;
            }

            lock (_clientsAndFilters)
            {
                foreach (IArbiterClient client in _clientsAndFilters.Keys)
                {
                    if (_clientsAndFilters[client].MessageAllowed(message))
                    {
                        clients.Add(client.SubscriptionClientID);
                    }
                }
            }
            return clients;
        }
Esempio n. 15
0
        public ArbiterClientId[] GetComponentsArbiterIds(Type componentType)
        {
            List<PlatformComponent> components = GetComponentsByType(componentType);
            ArbiterClientId[] result = new ArbiterClientId[components.Count];

            for (int i = 0; i < components.Count; i++)
            {
                result[i] = components[i].SubscriptionClientID;
            }

            return result;
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 public TransportInfoUnit(Guid id, ArbiterClientId? senderID, ArbiterClientId? receiverID)
 {
     _id = id;
     _senderID = senderID;
     _receiverID = receiverID;
 }
        public bool Start(out string operationResultMessage)
        {
            // This will start the integration client.
            if (Arbiter == null)
            {
                operationResultMessage = "Arbiter not assigned.";
                return false;
            }

            if (IsStarted)
            {
                operationResultMessage = "Adapter already started.";
                return false;
            }

            if (_integrationClient == null)
            {
                _integrationClient = new TransportIntegrationClient(_integrationUri);
            }

            if (_integrationClient != null && _integrationClientId.IsEmpty == false)
            {
                _integrationClient.SetArbiterSubscriptionClientId(_integrationClientId);
            }

            _integrationClient.MandatoryRequestMessageReceiverID = this.SubscriptionClientID;

            _integrationClient.ConnectionStatusChangedEvent += new TransportIntegrationClient.ConnectionStatusChangedDelegate(_integrationClient_ConnectionStatusChangedEvent);
            Arbiter.AddClient(_integrationClient);
            _integrationClientId = _integrationClient.SubscriptionClientID;

            _isStarted = true;

            ChangeOperationalState(OperationalStateEnum.Initialized);

            operationResultMessage = string.Empty;
            return true;
        }
Esempio n. 18
0
 /// <summary>
 /// Check if there is a client with this ID to this Arbiter instance.
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public bool HasClient(ArbiterClientId id)
 {
     lock (_clientsIdsAndClients)
     {
         return _clientsIdsAndClients.ContainsKey(id);
     }
 }
Esempio n. 19
0
        /// <summary>
        /// Will return NULL if the client has left arbiter. Do not keep references to this as it will keep objects alive!
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IArbiterClient GetClientByID(ArbiterClientId id, bool useOptionalReference)
        {
            if (_isDisposed)
            {// Possible to get disposed while operating here.
                return null;
            }

            if (useOptionalReference && id.OptionalReference != null)
            {// Optional reference allows to circumvent the usage of the dictionary,
                // to establish the corresponding client for this id.
                return id.OptionalReference;
            }

            lock (_clientsIdsAndClients)
            {
                IArbiterClient resultValue;
                if (_clientsIdsAndClients.TryGetValue(id, out resultValue))
                {
                    return resultValue;
                }
                else
                {
                    return null;
                }
            }
        }
Esempio n. 20
0
 /// <summary>
 /// Allows to retrieve an instance of a client by its ID. Use with caution since it breaks the independence model 
 /// and is applied only in special cases.
 /// </summary>
 public IArbiterClient GetClientByID(ArbiterClientId id)
 {
     return GetClientByID(id, false);
 }
        /// <summary>
        /// Do not use this in normal circumstances, this is automatically assigned.
        /// Allows to assign element with an existing ID, in order to be recognized in existing paths after de-persistence.
        /// </summary>
        /// <param name="id"></param>
        public bool SetArbiterSubscriptionClientId(ArbiterClientId id)
        {
            if (_arbiter != null)
            {
                SystemMonitor.Error("CAn not assign arbiter subscription id, after item already added to arbiter.");
                return false;
            }

            lock (this)
            {
                _subscriptionClientId = id;
            }

            return true;
        }
 /// <summary>
 ///
 /// </summary>
 public ProxyIntegrationAdapterClient(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     IntegrationUri       = (Uri)info.GetValue("integrationUri", typeof(Uri));
     _integrationClientId = (ArbiterClientId)info.GetValue("integrationClientId", typeof(ArbiterClientId));
 }
Esempio n. 23
0
        /// <summary>
        /// Will start a shoutcast mode conversation, the sender sending to all.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="requestMessage"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public ConversationMultiPoint CreateConversation(ArbiterClientId senderID, Message message, TimeSpan timeout)
        {
            if (message is TransportMessage)
            {
                SystemMonitor.CheckError(((TransportMessage)message).TransportInfo.CurrentTransportInfo != null);
                TracerHelper.Trace("sender[" + senderID.Id.Name + "], message [" + message.GetType().Name + "] [" + ((TransportMessage)message).TransportInfo.TransportInfoCount + "]");
            }
            else
            {
                TracerHelper.Trace("sender[" + senderID.Id.Name + "], message [" + message.GetType().Name + "]");
            }

            if (GetClientByID(senderID, false) == null)
            {
                SystemMonitor.Error("Creating conversation by not present sender/owner.");
                return null;
            }

            ConversationMultiPoint conversation = new ConversationMultiPoint(_executionManager, message, senderID, GatherMessageClients(message, senderID), timeout);

            if (_isDisposed)
            {// Possible to get disposed while operating here.
                return null;
            }

            lock (_timeOutMonitor)
            {
                _timeOutMonitor.AddEntity(conversation);
            }
            return conversation;
        }
 /// <summary>
 /// 
 /// </summary>
 public ProxyIntegrationAdapterClient(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     IntegrationUri = (Uri)info.GetValue("integrationUri", typeof(Uri));
     _integrationClientId = (ArbiterClientId)info.GetValue("integrationClientId", typeof(ArbiterClientId));
 }
        /// <summary>
        /// Message received from the "Pipe".
        /// </summary>
        void _transport_MessageReceivedEvent(string operationContextSessionID, MessageContainer messageContainer)
        {
            TransportMessage message = (TransportMessage)messageContainer.CreateMessageInstance();
            TracerHelper.Trace("[" + message.GetType().Name + "], length [" + messageContainer.MessageStreamLength + "]");

            if (message.IsRequest)
            {// Request requestMessage.

                {// Mark the request requestMessage with additional fragment in the transportation stack.
                    ArbiterClientId senderID = new ArbiterClientId("PipeChannelID", null, null);
                    senderID.SessionTag = operationContextSessionID;
                    message.TransportInfo.AddTransportInfoUnit(new TransportInfoUnit(Guid.NewGuid(), senderID, this.SubscriptionClientID));
                }

                if (MandatoryRequestMessageReceiverID.HasValue)
                {// There is a default receiver assigned for all messages from this integrator.
                    DoSendCustom(true, Guid.NewGuid(), null, 0, MandatoryRequestMessageReceiverID.Value, this.SubscriptionClientID, message, TimeSpan.Zero);
                }
                else
                {// No explicit mandatory receiver.

                    if (message.TransportInfo.ForwardTransportInfoCount > 0)
                    {
                        // First pop the Session stack, than send the cleared requestMessage.
                        ArbiterClientId? receiverID = message.TransportInfo.PopForwardTransportInfo();
                        DoSendCustom(true, Guid.NewGuid(), null, 0, receiverID, this.SubscriptionClientID, message, TimeSpan.Zero);

                    }
                    else
                    {
                        DoSendCustom(true, Guid.NewGuid(), null, 0, null, this.SubscriptionClientID, message, TimeSpan.Zero);
                    }
                }

            }
            else
            {// Responce requestMessage - send back to whoever sent it to us before.

                // And clear off the initial request information, we are responding now to.
                Guid sessionID = message.TransportInfo.CurrentTransportInfo.Value.Id;
                ArbiterClientId? receiverID = message.TransportInfo.CurrentTransportInfo.Value.SenderID;
                message.TransportInfo.PopTransportInfo();

                this.DoSendCustom(false, sessionID, null, 0,
                    receiverID, this.SubscriptionClientID, message, TimeSpan.Zero);
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Check if some other component is operational, by arbiter client componentId.
        /// </summary>
        /// <param name="componentId"></param>
        /// <returns></returns>
        public OperationalStateEnum? GetComponentOperationalState(ArbiterClientId? id)
        {
            if (id.HasValue == false)
            {
                SystemMonitor.Error("Component Id not valid.");
                return null;
            }

            ArbiterClientId idValue = id.Value;

            // Should a direct referencing be completely ommited, this call can be replaced with a requestMessage query to the platform.
            PlatformComponent component = GetComponentByIdentification(idValue.Id, true);
            if (component == null)
            {
                return null;
            }

            return component.OperationalState;
        }
 /// <summary>
 /// 
 /// </summary>
 public ComponentUnInitializedMessage(ArbiterClientId componentId)
 {
     _componentId = componentId;
 }
 /// <summary>
 ///
 /// </summary>
 public ComponentUnInitializedMessage(ArbiterClientId componentId)
 {
     _componentId = componentId;
 }
Esempio n. 29
0
        /// <summary>
        /// The direct call allows to circumvent the many steps (incl serialization) of typical message sending
        /// and make a direct call to another Arbiter member; thus making a much faster delivery. This path
        /// has a maximum optimization for speed, so tracing etc. are disabled.
        /// 
        /// Also this mechanism only works for TransportClients currently.
        /// 
        /// The mechanism does not utilize any new threads, and the execution is performed on the calling thread.
        /// 
        /// Direct calls can only be made to participants on the same arbiter, and no addressing is applied
        /// for the messages.
        /// </summary>
        public Message DirectCall(ArbiterClientId senderID, ArbiterClientId receiverID, Message message)
        {
            IArbiterClient receiver = GetClientByID(receiverID, true);
            if (receiver == null || receiver is TransportClient == false)
            {
                SystemMonitor.OperationWarning("Sender [" + senderID.Id.Print() + "] creating conversation message [" + message.GetType().Name + " ] by not present receiver [" + receiverID.Id.Print() + "] or receiver not a TransportClient");
                return null;
            }

            Message response = receiver.ReceiveDirectCall(message);
            return response;
        }