public void WriteGreeting(NodeGreetingMessage greetingMessage)
        {
            var messageFrame = new MessageFrame {
                RawMessage = greetingMessage.Serialize()
            };

            _queueSocket.Write(messageFrame);
        }
예제 #2
0
 public void Add(MessageFrame messageFrame)
 {
     if (messageFrame == null)
     {
         throw new ArgumentNullException("messageFrame");
     }
     if (_singleMessageFrames.TryAdd(messageFrame))
     {
         MessageCounterSignal.Increment();
         MessageFrameAdded(messageFrame);
     }
 }
        public async Task WriteMessageFrameAsync(MessageFrame messageFrame, CancellationToken cancellationToken)
        {
            if (messageFrame == null)
            {
                throw new ArgumentNullException("messageFrame");
            }
            if (messageFrame.RawMessage == null)
            {
                throw new ArgumentException("messageFrame.RawMessage cannot be null");
            }

            _queueSocket.Write(messageFrame);
        }
        public void WriteMessageFrame(MessageFrame messageFrame)
        {
            if (messageFrame == null)
            {
                throw new ArgumentNullException("messageFrame");
            }
            if (messageFrame.RawMessage == null)
            {
                throw new ArgumentException("messageFrame.RawMessage cannot be null");
            }

            _queueSocket.Write(messageFrame);
        }
예제 #5
0
        public async Task WriteMessageFrameAsync(MessageFrame messageFrame, CancellationToken cancellationToken)
        {
            if (messageFrame == null)
            {
                throw new ArgumentNullException("messageFrame");
            }
            if (messageFrame.RawMessage == null)
            {
                throw new ArgumentException("messageFrame.RawMessage cannot be null");
            }

            await CreateBufferWriteSingleAsync(messageFrame, cancellationToken);
        }
예제 #6
0
        public void WriteMessageFrame(MessageFrame messageFrame)
        {
            if (messageFrame == null)
            {
                throw new ArgumentNullException("messageFrame");
            }
            if (messageFrame.RawMessage == null)
            {
                throw new ArgumentException("messageFrame.RawMessage cannot be null");
            }

            CreateBufferWriteSingle(messageFrame);
        }
예제 #7
0
        public MessageFrame CreateFromMessage(IMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            var messageFrame = new MessageFrame
            {
                MessageTypeId = message.MessageTypeId,
                RawMessage    = _messageSerialization.Serialize(message)
            };

            return(messageFrame);
        }
예제 #8
0
 private void SendMessageFrame(IMessageFrameWriter writer, MessageFrame messageFrame)
 {
     try
     {
         writer.WriteMessageFrame(messageFrame);
     }
     catch
     {
         if (_resentMessageFrames.TryAdd(messageFrame))
         {
             Interlocked.Increment(ref _resentMessageFramesCount);
         }
         throw;
     }
 }
예제 #9
0
 private async Task SendMessageFrameAsync(IMessageFrameWriter writer, MessageFrame messageFrame, CancellationToken cancellationToken)
 {
     try
     {
         await writer.WriteMessageFrameAsync(messageFrame, cancellationToken);
     }
     catch
     {
         if (_resentMessageFrames.TryAdd(messageFrame))
         {
             Interlocked.Increment(ref _resentMessageFramesCount);
         }
         throw;
     }
 }
예제 #10
0
        private void CreateBufferWriteSingle(MessageFrame messageFrame)
        {
            var sendBufferSize = MessageFrame.HeaderSize + messageFrame.RawMessage.Length;

            WeakReference <MemoryStream> reference;
            var mem = GetOrCreateMemoryStream(sendBufferSize, out reference);

            try
            {
                WriteTypeId(mem, messageFrame.MessageTypeId);
                WriteLength(mem, messageFrame.RawMessage.Length);
                WriteBody(mem, messageFrame.RawMessage);

                var toSend = mem.GetBuffer();
                _streamSocket.Write(toSend, 0, sendBufferSize);
            }
            finally
            {
                mem.SetLength(0);
                RecycledMemoryStreams.Enqueue(reference);
            }
        }
예제 #11
0
        private async Task CreateBufferWriteSingleAsync(MessageFrame messageFrame,
                                                        CancellationToken cancellationToken)
        {
            var sendBufferSize = MessageFrame.HeaderSize + messageFrame.RawMessage.Length;

            WeakReference <MemoryStream> reference;
            var mem = GetOrCreateMemoryStream(sendBufferSize, out reference);

            try
            {
                WriteTypeId(mem, messageFrame.MessageTypeId);
                WriteLength(mem, messageFrame.RawMessage.Length);
                WriteBody(mem, messageFrame.RawMessage);

                var toSend = mem.GetBuffer();
                await _streamSocket.WriteAsync(toSend, 0, sendBufferSize, cancellationToken);
            }
            finally
            {
                mem.SetLength(0);
                RecycledMemoryStreams.Enqueue(reference);
            }
        }
예제 #12
0
 public void AddMessageFrame(MessageFrame messageFrame)
 {
     _messageQueue.Add(messageFrame);
 }