Beispiel #1
0
        /// <summary>
        /// Handles the incoming GroupCommunicationMessage.
        /// Updates the sending node's message queue.
        /// </summary>
        /// <param name="gcm">The incoming message</param>
        public void OnNext(GeneralGroupCommunicationMessage gcm)
        {
            if (gcm == null)
            {
                throw new ArgumentNullException("gcm");
            }
            if (gcm.Source == null)
            {
                throw new ArgumentException("Message must have a source");
            }

            var sourceNode = FindNode(gcm.Source);

            if (sourceNode == null)
            {
                throw new IllegalStateException("Received message from invalid task id: " + gcm.Source);
            }

            lock (_thisLock)
            {
                _nodesWithData.Add(sourceNode);
                var message = gcm as GroupCommunicationMessage <T>;

                if (message == null)
                {
                    throw new NullReferenceException("message passed not of type GroupCommunicationMessage");
                }

                sourceNode.AddData(message);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Handles the incoming GroupCommunicationMessage.
        /// Updates the sending node's message queue.
        /// </summary>
        /// <param name="gcm">The incoming message</param>
        public void OnNext(GeneralGroupCommunicationMessage gcm)
        {
            if (gcm == null)
            {
                throw new ArgumentNullException("gcm");
            }
            if (gcm.Source == null)
            {
                throw new ArgumentException("Message must have a source");
            }

            var sourceNode = (_parent != null && _parent.Identifier == gcm.Source)
                ? _parent
                : _childNodeContainer.GetChild(gcm.Source);

            if (sourceNode == null)
            {
                throw new IllegalStateException("Received message from invalid task id: " + gcm.Source);
            }

            var message = gcm as GroupCommunicationMessage <T>;

            if (message == null)
            {
                throw new NullReferenceException("message passed not of type GroupCommunicationMessage");
            }

            sourceNode.AddData(message);
        }
        /// <summary>
        /// Handles the incoming GeneralGroupCommunicationMessage sent to this Communication Group.
        /// Looks for the operator that the message is being sent to and invoke its handler.
        /// </summary>
        /// <param name="message">The incoming message</param>
        public void OnNext(GeneralGroupCommunicationMessage message)
        {
            string operatorName = message.OperatorName;

            IObserver <GeneralGroupCommunicationMessage> handler = GetOperatorHandler(operatorName);

            if (handler == null)
            {
                Exceptions.Throw(new ArgumentException("No handler registered with the operator name: " + operatorName), LOGGER);
            }
            else
            {
                handler.OnNext(message);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Send the GroupCommunicationMessage to the Task whose name is
        /// included in the message.
        /// </summary>
        /// <param name="message">The message to send.</param>
        public void Send(GeneralGroupCommunicationMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (string.IsNullOrEmpty(message.Destination))
            {
                throw new ArgumentException("Message destination cannot be null or empty");
            }

            IIdentifier destId = _idFactory.Create(message.Destination);
            var         conn   = _networkService.NewConnection(destId);

            conn.Open();
            conn.Write(message);
        }
        /// <summary>
        /// Handles the incoming WritableNsMessage for this Task.
        /// Delegates the GeneralGroupCommunicationMessage to the correct
        /// WritableCommunicationGroupNetworkObserver.
        /// </summary>
        /// <param name="nsMessage"></param>
        public void OnNext(NsMessage <GeneralGroupCommunicationMessage> nsMessage)
        {
            if (nsMessage == null)
            {
                throw new ArgumentNullException("nsMessage");
            }

            try
            {
                GeneralGroupCommunicationMessage gcm = nsMessage.Data.First();
                _commGroupHandlers[gcm.GroupName].OnNext(gcm);
            }
            catch (InvalidOperationException)
            {
                LOGGER.Log(Level.Error, "Group Communication Network Handler received message with no data");
                throw;
            }
            catch (KeyNotFoundException)
            {
                LOGGER.Log(Level.Error, "Group Communication Network Handler received message for nonexistant group");
                throw;
            }
        }
 /// <summary>
 /// Creates a NodeObserverIdentifier from a group communication message.
 /// </summary>
 public static NodeObserverIdentifier FromMessage(GeneralGroupCommunicationMessage message)
 {
     return(new NodeObserverIdentifier(message.MessageType, message.GroupName, message.OperatorName));
 }