Ejemplo n.º 1
0
        /// <summary>
        /// Writes the class fields.
        /// </summary>
        /// <param name="obj">The message to write</param>
        /// <param name="writer">The writer to which to write</param>
        public void Write(GroupCommunicationMessage <T> obj, IDataWriter writer)
        {
            byte[] encodedMetadata = GenerateMetaDataEncoding(obj);
            byte[] encodedInt      = BitConverter.GetBytes(encodedMetadata.Length);
            byte[] totalEncoding   = encodedInt.Concat(encodedMetadata).ToArray();
            writer.Write(totalEncoding, 0, totalEncoding.Length);

            foreach (var data in obj.Data)
            {
                _codec.Write(data, writer);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes the class fields.
        /// </summary>
        /// <param name="obj">The message to write</param>
        /// <param name="writer">The writer to which to write</param>
        /// <param name="token">The cancellation token</param>
        public async System.Threading.Tasks.Task WriteAsync(GroupCommunicationMessage <T> obj, IDataWriter writer, CancellationToken token)
        {
            byte[] encodedMetadata = GenerateMetaDataEncoding(obj);
            byte[] encodedInt      = BitConverter.GetBytes(encodedMetadata.Length);
            byte[] totalEncoding   = encodedInt.Concat(encodedMetadata).ToArray();
            await writer.WriteAsync(totalEncoding, 0, totalEncoding.Length, token);

            foreach (var data in obj.Data)
            {
                await _codec.WriteAsync(data, writer, token);
            }
        }
Ejemplo n.º 3
0
 public static GcmMessageProto Create(GroupCommunicationMessage gcm)
 {
     return new GcmMessageProto()
     {
         Data = gcm.Data,
         OperatorName = gcm.OperatorName,
         GroupName = gcm.GroupName,
         Source = gcm.Source,
         Destination = gcm.Destination,
         MsgType = gcm.MsgType,
     };
 }
        /// <summary>
        /// Handles the incoming GroupCommunicationMessage 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(GroupCommunicationMessage message)
        {
            string operatorName = message.OperatorName;

            IObserver<GroupCommunicationMessage> handler = GetOperatorHandler(operatorName);

            if (handler == null)
            {
                Exceptions.Throw(new ArgumentException("No handler registered with the operator name: " + operatorName), LOGGER);
            }
            else
            {
                handler.OnNext(message);
            }
        }
Ejemplo n.º 5
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(GroupCommunicationMessage 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);
        }
Ejemplo n.º 6
0
        private static byte[] GenerateMetaDataEncoding(GroupCommunicationMessage <T> obj)
        {
            List <byte[]> metadataBytes = new List <byte[]>();

            byte[] groupBytes    = StringToBytes(obj.GroupName);
            byte[] operatorBytes = StringToBytes(obj.OperatorName);
            byte[] sourceBytes   = StringToBytes(obj.Source);
            byte[] dstBytes      = StringToBytes(obj.Destination);
            byte[] messageCount  = BitConverter.GetBytes(obj.Data.Length);

            metadataBytes.Add(BitConverter.GetBytes(groupBytes.Length));
            metadataBytes.Add(BitConverter.GetBytes(operatorBytes.Length));
            metadataBytes.Add(BitConverter.GetBytes(sourceBytes.Length));
            metadataBytes.Add(BitConverter.GetBytes(dstBytes.Length));
            metadataBytes.Add(groupBytes);
            metadataBytes.Add(operatorBytes);
            metadataBytes.Add(sourceBytes);
            metadataBytes.Add(dstBytes);
            metadataBytes.Add(messageCount);

            return(metadataBytes.SelectMany(i => i).ToArray());
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Adds an incoming message to the message queue.
 /// </summary>
 /// <param name="gcm">The incoming message</param>
 public void AddData(GroupCommunicationMessage gcm)
 {
     _messageQueue.Add(gcm);
 }