Esempio n. 1
0
        private void OnClientConnected(ISocket socket, ISocketConfiguration socketConfiguration)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            NodeGreetingMessageVerifier.SendReceiveAndVerify(socket, socketConfiguration.ConnectTimeout);

            var messageFrameWriter = MessageFrameWriterFactory.CreateWriterFromSocket(socket);
            var messageQueue       = new MessageQueueBatch(socketConfiguration.SendBufferSize);
            var messageReceiveLoop = new MessageReceiveLoop(_messageSerialization, socket, OnMessageReceived, MessageReceiveLoopOnException);

            if (_broadcastSockets.TryAdd(socket, new MessageQueueReceiveLoop(messageQueue, messageReceiveLoop)))
            {
                _messageQueueBroadcaster.Register(messageQueue, messageFrameWriter);
                ClientConnected(socket, socketConfiguration);
                messageReceiveLoop.Start();
            }

            if (socket.IsDisconnected)
            {
                // this is to fix the race condition if socket was disconnected meanwhile
                SocketDisconnected(socket);
            }
        }
        public void Register(MessageQueueBatch messageQueue, IMessageFrameWriter messageFrameWriter)
        {
            if (messageQueue == null) throw new ArgumentNullException("messageQueue");
            if (messageFrameWriter == null) throw new ArgumentNullException("messageFrameWriter");

            var messageQueuePayload = new MessageQueuePayload(messageFrameWriter);
            messageQueue.MessageFramesAdded += MessageQueueOnMessageFramesAdded;
            _messageQueues[messageQueue] = messageQueuePayload;
            StartAsyncProcessingIfNotStartedYet();
        }
 private static async Task LoopMessageQueueAsync(MessageQueueBatch messageQueue, MessageQueuePayload messageQueuePayload, CancellationToken cancellationToken)
 {
     try
     {
         await messageQueue.SendMultipleFromQueueAsync(messageQueuePayload.Writer, cancellationToken);
     }
     finally
     {
         messageQueuePayload.Busy.Set(false);
     }
 }
        public void Register(MessageQueueBatch messageQueue, IMessageFrameWriter messageFrameWriter)
        {
            if (messageQueue == null)
            {
                throw new ArgumentNullException("messageQueue");
            }
            if (messageFrameWriter == null)
            {
                throw new ArgumentNullException("messageFrameWriter");
            }

            var messageQueuePayload = new MessageQueuePayload(messageFrameWriter);

            messageQueue.MessageFramesAdded += MessageQueueOnMessageFramesAdded;
            _messageQueues[messageQueue]     = messageQueuePayload;
            StartAsyncProcessingIfNotStartedYet();
        }
        public bool Unregister(MessageQueueBatch messageQueue)
        {
            if (messageQueue == null) throw new ArgumentNullException("messageQueue");

            MessageQueuePayload messageQueuePayload;
            var removed = _messageQueues.TryRemove(messageQueue, out messageQueuePayload);
            if (removed)
            {
                messageQueuePayload.Cancelled.Set(true);
                messageQueue.MessageFramesAdded -= MessageQueueOnMessageFramesAdded;
            }

            if (_messageQueues.IsEmpty)
            {
                StopProcessing();
            }

            return removed;
        }
        public bool Unregister(MessageQueueBatch messageQueue)
        {
            if (messageQueue == null)
            {
                throw new ArgumentNullException("messageQueue");
            }

            MessageQueuePayload messageQueuePayload;
            var removed = _messageQueues.TryRemove(messageQueue, out messageQueuePayload);

            if (removed)
            {
                messageQueuePayload.Cancelled.Set(true);
                messageQueue.MessageFramesAdded -= MessageQueueOnMessageFramesAdded;
            }

            if (_messageQueues.IsEmpty)
            {
                StopProcessing();
            }

            return(removed);
        }
Esempio n. 7
0
        private void OnClientConnected(ISocket socket, ISocketConfiguration socketConfiguration)
        {
            if (socket == null) throw new ArgumentNullException("socket");

            NodeGreetingMessageVerifier.SendReceiveAndVerify(socket, socketConfiguration.ConnectTimeout);

            var messageFrameWriter = MessageFrameWriterFactory.CreateWriterFromSocket(socket);
            var messageQueue = new MessageQueueBatch(socketConfiguration.SendBufferSize);
            var messageReceiveLoop = new MessageReceiveLoop(_messageSerialization, socket, OnMessageReceived, MessageReceiveLoopOnException);

            if (_broadcastSockets.TryAdd(socket, new MessageQueueReceiveLoop(messageQueue, messageReceiveLoop)))
            {
                _messageQueueBroadcaster.Register(messageQueue, messageFrameWriter);
                ClientConnected(socket, socketConfiguration);
                messageReceiveLoop.Start();
            }

            if (socket.IsDisconnected)
            {
                // this is to fix the race condition if socket was disconnected meanwhile
                SocketDisconnected(socket);
            }
        }
 private static async Task LoopMessageQueueAsync(MessageQueueBatch messageQueue, MessageQueuePayload messageQueuePayload, CancellationToken cancellationToken)
 {
     try
     {
         await messageQueue.SendMultipleFromQueueAsync(messageQueuePayload.Writer, cancellationToken);
     }
     finally
     {
         messageQueuePayload.Busy.Set(false);
     }
 }
Esempio n. 9
0
 public MessageQueueReceiveLoop(MessageQueueBatch messageQueue, MessageReceiveLoop messageReceiveLoop)
 {
     MessageQueue = messageQueue;
     MessageReceiveLoop = messageReceiveLoop;
 }
Esempio n. 10
0
 public MessageQueueReceiveLoop(MessageQueueBatch messageQueue, MessageReceiveLoop messageReceiveLoop)
 {
     MessageQueue       = messageQueue;
     MessageReceiveLoop = messageReceiveLoop;
 }