Пример #1
0
        public void Connect(RedFoxEndpoint endpoint, ISocketConfiguration socketConfiguration)
        {
            if (socketConfiguration == null)
            {
                throw new ArgumentNullException("socketConfiguration");
            }
            if (_socket != null)
            {
                throw new InvalidOperationException("Subscriber already connected");
            }
            _cts = new CancellationTokenSource();

            _socket = SocketFactory.CreateAndConnectAsync(endpoint, NodeType.Subscriber, socketConfiguration);
            _socket.Disconnected += SocketDisconnected;

            NodeGreetingMessageVerifier.SendReceiveAndVerify(_socket, socketConfiguration.ConnectTimeout);

            if (!_cts.IsCancellationRequested)
            {
                _messageFrameWriter = MessageFrameWriterFactory.CreateWriterFromSocket(_socket);

                _messageReceiveLoop = new MessageReceiveLoop(_messageSerialization, _socket, OnMessageReceived, MessageReceiveLoopOnException);
                _messageReceiveLoop.Start();
            }
        }
Пример #2
0
        public void Connect(RedFoxEndpoint endpoint, TimeSpan connectTimeout)
        {
            var socketConfiguration = (SocketConfiguration)SocketConfiguration.Default.Clone();
            socketConfiguration.ConnectTimeout = connectTimeout;

            Connect(endpoint, socketConfiguration);
        }
Пример #3
0
        public void ServiceQueue_AddMessageFrame_connect_single_message_received(ServiceQueueRotationAlgorithm rotationAlgorithm)
        {
            var endpoint = new RedFoxEndpoint("/path");

            using (var serviceQueue = new ServiceQueue(rotationAlgorithm))
                using (var serviceQueueReader = new ServiceQueueReader())
                {
                    IMessage messageReceived = null;
                    var      received        = new ManualResetEventSlim();
                    serviceQueueReader.MessageReceived += (s, m) =>
                    {
                        messageReceived = m;
                        received.Set();
                    };

                    var testMessage      = new TestMessage();
                    var testMessageFrame = new MessageFrameCreator(DefaultMessageSerialization.Instance).CreateFromMessage(testMessage);

                    serviceQueue.AddMessageFrame(testMessageFrame);

                    serviceQueue.Bind(endpoint);
                    serviceQueueReader.Connect(endpoint);

                    Assert.IsTrue(received.Wait(TimeSpan.FromSeconds(1)));
                    Assert.AreEqual(testMessage, messageReceived);
                }
        }
Пример #4
0
        public void GetHashCode_same_when_all_fields_match()
        {
            var endpoint1 = new RedFoxEndpoint(RedFoxTransport.Tcp, "host", 1234, "/path");
            var endpoint2 = new RedFoxEndpoint(RedFoxTransport.Tcp, "host", 1234, "/path");

            Assert.AreEqual(endpoint1.GetHashCode(), endpoint2.GetHashCode());
        }
Пример #5
0
        public void Bind(RedFoxEndpoint endpoint, NodeType nodeType, ISocketConfiguration socketConfiguration, ClientConnectedDelegate onClientConnected = null, ClientDisconnectedDelegate onClientDisconnected = null)
        {
            if (_listener != null || !_stopped.IsSet)
            {
                throw new InvalidOperationException("Server already bound, please use Unbind first");
            }

            var ipAddress = IpAddressFromHostTranslator.GetIpAddressForHost(endpoint.Host);

            _endpoint = endpoint;

            _listener = new TcpListener(ipAddress, endpoint.Port);

            if (onClientConnected != null)
            {
                ClientConnected += onClientConnected;
            }
            if (onClientDisconnected != null)
            {
                ClientDisconnected += onClientDisconnected;
            }

            _stopped.Reset();
            _started.Reset();

            _listener.Start();

            _cts = new CancellationTokenSource();

            StartAcceptLoop(socketConfiguration, _cts.Token, nodeType);
        }
Пример #6
0
        public void TryParse_port_should_be_parsed()
        {
            RedFoxEndpoint endpoint;

            Assert.IsTrue(RedFoxEndpoint.TryParse("tcp://hostname:1234", out endpoint));
            Assert.AreEqual(1234, endpoint.Port);
        }
Пример #7
0
        public void TryParse_transport_should_be_parsed(string endpointUri, RedFoxTransport expectedTransport)
        {
            RedFoxEndpoint endpoint;

            Assert.IsTrue(RedFoxEndpoint.TryParse(endpointUri, out endpoint));
            Assert.AreEqual(expectedTransport, endpoint.Transport);
        }
Пример #8
0
        public void Equals_different_Transport_false()
        {
            var endpoint = new RedFoxEndpoint { Transport = (RedFoxTransport)255 };

            Assert.False(endpoint.Equals(new RedFoxEndpoint()));
            Assert.False(endpoint.Equals((object)new RedFoxEndpoint()));
        }
Пример #9
0
        public InProcSocket Connect(RedFoxEndpoint endpoint)
        {
            if (endpoint.Transport != RedFoxTransport.Inproc)
            {
                throw new ArgumentException("Only InProcess transport endpoints are allowed to be registered");
            }

            BlockingCollection <InProcSocketPair> accepter;

            if (!_registeredAccepterPorts.TryGetValue(endpoint, out accepter))
            {
                throw new InvalidOperationException("Endpoint not listening to InProcess clients");
            }

            var clientStream = new BlockingConcurrentQueue <MessageFrame>();
            var serverStream = new BlockingConcurrentQueue <MessageFrame>();
            var clientSocket = new InProcSocket(endpoint, clientStream, serverStream);
            var serverSocket = new InProcSocket(endpoint, serverStream, clientStream);

            var socketPair = new InProcSocketPair(clientSocket, serverSocket);

            accepter.Add(socketPair);

            return(clientSocket);
        }
        public void ServiceQueue_connect_Writer_send_multiple_message_received()
        {
            const int count = 1000;

            using (var serviceQueue = new ServiceQueue())
                using (var writer = new ServiceQueueWriter())
                {
                    var endpoint = new RedFoxEndpoint("/path");

                    var messageFrames = new List <MessageFrame>();
                    var counterSignal = new CounterSignal(count, 0);
                    serviceQueue.MessageFrameReceived += m =>
                    {
                        messageFrames.Add(m);
                        counterSignal.Increment();
                    };

                    serviceQueue.Bind(endpoint);
                    writer.Connect(endpoint);

                    for (var i = 0; i < count; i++)
                    {
                        writer.SendMessage(new TestMessage());
                    }

                    Assert.IsTrue(counterSignal.Wait(TimeSpan.FromSeconds(30)));
                    Assert.AreEqual(count, messageFrames.Count);
                }
        }
Пример #11
0
        public void TryParse_path_should_be_parsed(string endpointString, string path)
        {
            RedFoxEndpoint endpoint;

            Assert.IsTrue(RedFoxEndpoint.TryParse(endpointString, out endpoint));
            Assert.AreEqual(path, endpoint.Path);
        }
Пример #12
0
        public void Equals(string endpointUri1, string endpointUri2)
        {
            var endpoint1 = RedFoxEndpoint.Parse(endpointUri1);
            var endpoint2 = RedFoxEndpoint.Parse(endpointUri2);

            Assert.AreEqual(endpoint2, endpoint1);
        }
Пример #13
0
        public void Bind(RedFoxEndpoint endpoint, NodeType nodeType, ISocketConfiguration socketConfiguration, ClientConnectedDelegate onClientConnected = null, ClientDisconnectedDelegate onClientDisconnected = null)
        {
            if (_listener != null || !_stopped.IsSet)
                throw new InvalidOperationException("Server already bound, please use Unbind first");

            var ipAddress = IpAddressFromHostTranslator.GetIpAddressForHost(endpoint.Host);

            _endpoint = endpoint;

            _listener = new TcpListener(ipAddress, endpoint.Port);

            if (onClientConnected != null)
                ClientConnected += onClientConnected;
            if (onClientDisconnected != null)
                ClientDisconnected += onClientDisconnected;

            _stopped.Reset();
            _started.Reset();

            _listener.Start();

            _cts = new CancellationTokenSource();

            StartAcceptLoop(socketConfiguration, _cts.Token, nodeType);
        }
Пример #14
0
        public void ServiceQueue_connect_AddMessageFrame_single_message_received(ServiceQueueRotationAlgorithm rotationAlgorithm)
        {
            var endpoint = new RedFoxEndpoint("/path");

            using (var serviceQueue = new ServiceQueue(rotationAlgorithm))
            using (var serviceQueueReader = new ServiceQueueReader())
            {
                IMessage messageReceived = null;
                var received = new ManualResetEventSlim();
                serviceQueueReader.MessageReceived += (s, m) =>
                {
                    messageReceived = m;
                    received.Set();
                };

                serviceQueue.Bind(endpoint);
                serviceQueueReader.Connect(endpoint);

                var testMessage = new TestMessage();
                var testMessageFrame = new MessageFrameCreator(DefaultMessageSerialization.Instance).CreateFromMessage(testMessage);

                serviceQueue.AddMessageFrame(testMessageFrame);

                Assert.IsTrue(received.Wait(TimeSpan.FromSeconds(1)));
                Assert.AreEqual(testMessage, messageReceived);
            }
        }
Пример #15
0
 public InProcSocket(RedFoxEndpoint endpoint, BlockingConcurrentQueue<MessageFrame> writeStream, BlockingConcurrentQueue<MessageFrame> readStream)
 {
     if (writeStream == null) throw new ArgumentNullException("writeStream");
     if (readStream == null) throw new ArgumentNullException("readStream");
     Endpoint = endpoint;
     _writeStream = writeStream;
     _readStream = readStream;
 }
Пример #16
0
        public void GetHashCode_different_Host()
        {
            var endpoint = new RedFoxEndpoint {
                Host = "host"
            };

            Assert.AreNotEqual(endpoint.GetHashCode(), new RedFoxEndpoint().GetHashCode());
        }
Пример #17
0
        public void GetHashCode_different_Path()
        {
            var endpoint = new RedFoxEndpoint {
                Path = "/path"
            };

            Assert.AreNotEqual(endpoint.GetHashCode(), new RedFoxEndpoint().GetHashCode());
        }
Пример #18
0
        public void Equals_all_fields_match_true()
        {
            var endpoint1 = new RedFoxEndpoint(RedFoxTransport.Tcp, "host", 1234, "/path");
            var endpoint2 = new RedFoxEndpoint(RedFoxTransport.Tcp, "host", 1234, "/path");

            Assert.True(endpoint1.Equals(endpoint2));
            Assert.True(endpoint1.Equals((object)endpoint2));
        }
Пример #19
0
        public void GetHashCode_different_Port()
        {
            var endpoint = new RedFoxEndpoint {
                Port = 1234
            };

            Assert.AreNotEqual(endpoint.GetHashCode(), new RedFoxEndpoint().GetHashCode());
        }
Пример #20
0
        public void Connect(RedFoxEndpoint endpoint, TimeSpan connectTimeout)
        {
            var socketConfiguration = (SocketConfiguration)SocketConfiguration.Default.Clone();

            socketConfiguration.ConnectTimeout = connectTimeout;

            Connect(endpoint, socketConfiguration);
        }
Пример #21
0
        public void GetHashCode_different_Transport()
        {
            var endpoint = new RedFoxEndpoint {
                Transport = (RedFoxTransport)255
            };

            Assert.AreNotEqual(endpoint.GetHashCode(), new RedFoxEndpoint().GetHashCode());
        }
Пример #22
0
        public void Equals_all_fields_match_true()
        {
            var endpoint1 = new RedFoxEndpoint(RedFoxTransport.Tcp, "host", 1234, "/path");
            var endpoint2 = new RedFoxEndpoint(RedFoxTransport.Tcp, "host", 1234, "/path");

            Assert.True(endpoint1.Equals(endpoint2));
            Assert.True(endpoint1.Equals((object)endpoint2));
        }
Пример #23
0
 public void publishers_bind_same_endpoint_twice_fails()
 {
     using (var publisher = new Publisher())
     {
         var endpoint = new RedFoxEndpoint("/path");
         publisher.Bind(endpoint);
         Assert.Throws<InvalidOperationException>(() => publisher.Bind(endpoint));
     }
 }
Пример #24
0
        public void Equals_different_Host_false()
        {
            var endpoint = new RedFoxEndpoint {
                Host = "host"
            };

            Assert.False(endpoint.Equals(new RedFoxEndpoint()));
            Assert.False(endpoint.Equals((object)new RedFoxEndpoint()));
        }
Пример #25
0
        public void Equals_different_Transport_false()
        {
            var endpoint = new RedFoxEndpoint {
                Transport = (RedFoxTransport)255
            };

            Assert.False(endpoint.Equals(new RedFoxEndpoint()));
            Assert.False(endpoint.Equals((object)new RedFoxEndpoint()));
        }
Пример #26
0
        public void Constructor_Transport_Host_Port_Path_setting_fields()
        {
            var endpoint = new RedFoxEndpoint(RedFoxTransport.Tcp, "host", 1234, "/path");

            Assert.AreEqual(RedFoxTransport.Tcp, endpoint.Transport);
            Assert.AreEqual("host", endpoint.Host);
            Assert.AreEqual(1234, endpoint.Port);
            Assert.AreEqual("/path", endpoint.Path);
        }
Пример #27
0
        public void Constructor_default_values()
        {
            var endpoint = new RedFoxEndpoint();

            Assert.AreEqual(RedFoxTransport.Inproc, endpoint.Transport);
            Assert.AreEqual(null, endpoint.Host);
            Assert.AreEqual(0, endpoint.Port);
            Assert.AreEqual(null, endpoint.Path);
        }
Пример #28
0
        public void Constructor_Transport_Host_Port_Path_setting_fields()
        {
            var endpoint = new RedFoxEndpoint(RedFoxTransport.Tcp, "host", 1234, "/path");

            Assert.AreEqual(RedFoxTransport.Tcp, endpoint.Transport);
            Assert.AreEqual("host", endpoint.Host);
            Assert.AreEqual(1234, endpoint.Port);
            Assert.AreEqual("/path", endpoint.Path);
        }
Пример #29
0
        public void Equals_different_Port_false()
        {
            var endpoint = new RedFoxEndpoint {
                Port = 1234
            };

            Assert.False(endpoint.Equals(new RedFoxEndpoint()));
            Assert.False(endpoint.Equals((object)new RedFoxEndpoint()));
        }
Пример #30
0
        public void Constructor_default_values()
        {
            var endpoint = new RedFoxEndpoint();

            Assert.AreEqual(RedFoxTransport.Inproc, endpoint.Transport);
            Assert.AreEqual(null, endpoint.Host);
            Assert.AreEqual(0, endpoint.Port);
            Assert.AreEqual(null, endpoint.Path);
        }
Пример #31
0
        public void Equals_different_Path_false()
        {
            var endpoint = new RedFoxEndpoint {
                Path = "/path"
            };

            Assert.False(endpoint.Equals(new RedFoxEndpoint()));
            Assert.False(endpoint.Equals((object)new RedFoxEndpoint()));
        }
Пример #32
0
 public void responders_bind_same_endpoint_twice_fails()
 {
     using (var responder = TestHelpers.CreateTestResponder())
     {
         var endpoint = new RedFoxEndpoint("/path");
         responder.Bind(endpoint);
         Assert.Throws<InvalidOperationException>(() => responder.Bind(endpoint));
     }
 }
Пример #33
0
        private void DisconnectSocketsForEndpoint(RedFoxEndpoint endpoint)
        {
            var socketsMatchingEndpoint = _clientSockets.Keys.Where(socket => socket.Endpoint.Equals(endpoint));

            foreach (var socket in socketsMatchingEndpoint)
            {
                socket.Disconnect();
            }
        }
Пример #34
0
 public void responders_bind_same_endpoint_twice_fails()
 {
     using (var responder = TestHelpers.CreateTestResponder())
     {
         var endpoint = new RedFoxEndpoint("/path");
         responder.Bind(endpoint);
         Assert.Throws <InvalidOperationException>(() => responder.Bind(endpoint));
     }
 }
Пример #35
0
 public void ServiceQueues_bind_same_endpoint_twice_fails()
 {
     using (var serviceQueue = new ServiceQueue())
     {
         var endpoint = new RedFoxEndpoint("/path");
         serviceQueue.Bind(endpoint);
         Assert.Throws <InvalidOperationException>(() => serviceQueue.Bind(endpoint));
     }
 }
Пример #36
0
 public void ServiceQueues_bind_same_endpoint_twice_fails()
 {
     using (var serviceQueue = new ServiceQueue())
     {
         var endpoint = new RedFoxEndpoint("/path");
         serviceQueue.Bind(endpoint);
         Assert.Throws<InvalidOperationException>(() => serviceQueue.Bind(endpoint));
     }
 }
Пример #37
0
        public TcpSocket(RedFoxEndpoint endpoint, TcpClient tcpClient)
        {
            if (tcpClient == null) throw new ArgumentNullException("tcpClient");
            TcpClient = tcpClient;
            _remoteEndPoint = tcpClient.Client.RemoteEndPoint;

            Endpoint = endpoint;
            Stream = tcpClient.GetStream();
        }
Пример #38
0
 public void publishers_bind_same_endpoint_twice_fails()
 {
     using (var publisher = new Publisher())
     {
         var endpoint = new RedFoxEndpoint("/path");
         publisher.Bind(endpoint);
         Assert.Throws <InvalidOperationException>(() => publisher.Bind(endpoint));
     }
 }
Пример #39
0
 public void two_ServiceQueues_same_endpoint_fails()
 {
     using (var serviceQueue1 = new ServiceQueue())
         using (var serviceQueue2 = new ServiceQueue())
         {
             var endpoint = new RedFoxEndpoint("/path");
             serviceQueue1.Bind(endpoint);
             Assert.Throws <InvalidOperationException>(() => serviceQueue2.Bind(endpoint));
         }
 }
Пример #40
0
 public void two_publishers_same_endpoint_fails()
 {
     using (var publisher1 = new Publisher())
         using (var publisher2 = new Publisher())
         {
             var endpoint = new RedFoxEndpoint("/path");
             publisher1.Bind(endpoint);
             Assert.Throws <InvalidOperationException>(() => publisher2.Bind(endpoint));
         }
 }
Пример #41
0
 public void two_publishers_same_endpoint_fails()
 {
     using (var publisher1 = new Publisher())
     using (var publisher2 = new Publisher())
     {
         var endpoint = new RedFoxEndpoint("/path");
         publisher1.Bind(endpoint);
         Assert.Throws<InvalidOperationException>(() => publisher2.Bind(endpoint));
     }
 }
Пример #42
0
 public void two_ServiceQueues_same_endpoint_fails()
 {
     using (var serviceQueue1 = new ServiceQueue())
     using (var serviceQueue2 = new ServiceQueue())
     {
         var endpoint = new RedFoxEndpoint("/path");
         serviceQueue1.Bind(endpoint);
         Assert.Throws<InvalidOperationException>(() => serviceQueue2.Bind(endpoint));
     }
 }
Пример #43
0
        public void GetHashCode_case_insensitive_Host_same()
        {
            var endpoint1 = new RedFoxEndpoint {
                Host = "HOST"
            };
            var endpoint2 = new RedFoxEndpoint {
                Host = "host"
            };

            Assert.AreEqual(endpoint1.GetHashCode(), endpoint2.GetHashCode());
        }
Пример #44
0
        public void GetHashCode_ignore_Path_when_using_Tcp()
        {
            var endpoint1 = new RedFoxEndpoint {
                Transport = RedFoxTransport.Tcp, Path = "ignore"
            };
            var endpoint2 = new RedFoxEndpoint {
                Transport = RedFoxTransport.Tcp
            };

            Assert.AreEqual(endpoint1.GetHashCode(), endpoint2.GetHashCode());
        }
Пример #45
0
        public ISocketAccepter CreateAndBind(RedFoxEndpoint endpoint,
            NodeType nodeType,
            ISocketConfiguration socketConfiguration,
            ClientConnectedDelegate onClientConnected = null,
            ClientDisconnectedDelegate onClientDisconnected = null)
        {
            if (socketConfiguration == null) throw new ArgumentNullException("socketConfiguration");

            var server = CreateForTransport(endpoint.Transport);
            server.Bind(endpoint, nodeType, socketConfiguration, onClientConnected, onClientDisconnected);
            return server;
        }
Пример #46
0
 public ISocket CreateAndConnectAsync(RedFoxEndpoint endpoint, NodeType nodeType, ISocketConfiguration socketConfiguration)
 {
     switch (endpoint.Transport)
     {
         case RedFoxTransport.Inproc:
             return CreateInProcSocket(endpoint);
         case RedFoxTransport.Tcp:
             return CreateTcpSocket(endpoint, nodeType, socketConfiguration);
         default:
             throw new NotSupportedException(String.Format("Transport {0} not supported", endpoint.Transport));
     }
 }
Пример #47
0
        public BlockingCollection<InProcSocketPair> RegisterAccepter(RedFoxEndpoint endpoint)
        {
            if (endpoint.Transport != RedFoxTransport.Inproc)
                throw new ArgumentException("Only InProcess transport endpoints are allowed to be registered");

            var result = _registeredAccepterPorts.AddOrUpdate(
                endpoint,
                e => new BlockingCollection<InProcSocketPair>(),
                (e, v) =>
                {
                    throw new InvalidOperationException("Endpoint already listening to InProcess clients");
                });
            return result;
        }
Пример #48
0
        public void Connect(RedFoxEndpoint endpoint, ISocketConfiguration socketConfiguration)
        {
            if (socketConfiguration == null) throw new ArgumentNullException("socketConfiguration");
            if (_socket != null) throw new InvalidOperationException("Subscriber already connected");
            _cts = new CancellationTokenSource();

            _socket = SocketFactory.CreateAndConnectAsync(endpoint, NodeType.ServiceQueueWriter, socketConfiguration);
            _socket.Disconnected += SocketDisconnected;

            NodeGreetingMessageVerifier.SendReceiveAndVerify(_socket, socketConfiguration.ConnectTimeout);

            if (!_cts.IsCancellationRequested)
            {
                _messageFrameWriter = MessageFrameWriterFactory.CreateWriterFromSocket(_socket);
            }
        }
Пример #49
0
        private static ISocket CreateTcpSocket(RedFoxEndpoint endpoint, NodeType nodeType, ISocketConfiguration socketConfiguration)
        {
            var hasReceiveTimeout = NodeTypeHasReceiveTimeout.HasReceiveTimeout(nodeType);

            var tcpClient = new TcpClient
            {
                ReceiveTimeout = hasReceiveTimeout ? socketConfiguration.ReceiveTimeout.ToMillisOrZero() : 0,
                SendTimeout = socketConfiguration.SendTimeout.ToMillisOrZero(),

                NoDelay = true,
                ReceiveBufferSize = socketConfiguration.ReceiveBufferSize,
                SendBufferSize = socketConfiguration.SendBufferSize
            };
            ConnectTcpSocket(tcpClient, endpoint.Host, endpoint.Port, socketConfiguration.ConnectTimeout);

            return new TcpSocket(endpoint, tcpClient);
        }
Пример #50
0
        public void Bind(RedFoxEndpoint endpoint, NodeType nodeType, ISocketConfiguration socketConfiguration, ClientConnectedDelegate onClientConnected = null, ClientDisconnectedDelegate onClientDisconnected = null)
        {
            if (_listener != null || !_stopped.IsSet)
                throw new InvalidOperationException("Server already bound, please use Unbind first");

            _listener = InProcessEndpoints.Instance.RegisterAccepter(endpoint);
            _endpoint = endpoint;

            if (onClientConnected != null)
                ClientConnected += onClientConnected;
            if (onClientDisconnected != null)
                ClientDisconnected += onClientDisconnected;

            _started.Reset();
            _cts = new CancellationTokenSource();
            Task.Factory.StartNew(() => StartAcceptLoop(_cts.Token, socketConfiguration), TaskCreationOptions.LongRunning);
            _started.Wait();
        }
Пример #51
0
        public void ServiceQueue_connect_Writer_send_single_message_MessageFramesCount_is_one()
        {
            using (var serviceQueue = new ServiceQueue())
            using (var writer = new ServiceQueueWriter())
            {
                var endpoint = new RedFoxEndpoint("/path");

                var received = new ManualResetEventSlim();
                serviceQueue.MessageFrameReceived += m => received.Set();

                serviceQueue.Bind(endpoint);
                writer.Connect(endpoint);

                Assert.AreEqual(0, serviceQueue.MessageFramesCount);
                writer.SendMessage(new TestMessage());

                Assert.IsTrue(received.Wait(TimeSpan.FromSeconds(1)));
                Assert.AreEqual(1, serviceQueue.MessageFramesCount);
            }
        }
Пример #52
0
        public InProcSocket Connect(RedFoxEndpoint endpoint)
        {
            if (endpoint.Transport != RedFoxTransport.Inproc)
                throw new ArgumentException("Only InProcess transport endpoints are allowed to be registered");

            BlockingCollection<InProcSocketPair> accepter;
            if (!_registeredAccepterPorts.TryGetValue(endpoint, out accepter))
            {
                throw new InvalidOperationException("Endpoint not listening to InProcess clients");
            }

            var clientStream = new BlockingConcurrentQueue<MessageFrame>();
            var serverStream = new BlockingConcurrentQueue<MessageFrame>();
            var clientSocket = new InProcSocket(endpoint, clientStream, serverStream);
            var serverSocket = new InProcSocket(endpoint, serverStream, clientStream);

            var socketPair = new InProcSocketPair(clientSocket, serverSocket);
            accepter.Add(socketPair);

            return clientSocket;
        }
Пример #53
0
        public void unbind_disconnects_client()
        {
            using (var responder = TestHelpers.CreateTestResponder())
            using (var requester = new Requester())
            {
                var endpoint = new RedFoxEndpoint("/path");

                var connected = new ManualResetEventSlim();
                var disconnected = new ManualResetEventSlim();

                responder.ClientConnected += (s, c) => connected.Set();
                responder.ClientDisconnected += s => disconnected.Set();

                responder.Bind(endpoint);
                requester.Connect(endpoint);

                Assert.IsTrue(connected.Wait(TimeSpan.FromSeconds(1)));

                responder.Unbind(endpoint);

                Assert.IsTrue(disconnected.Wait(TimeSpan.FromSeconds(1)));
            }
        }
Пример #54
0
        public void unbind_disconnects_client()
        {
            using (var publisher = new Publisher())
            using (var subscriber = new Subscriber())
            {
                var endpoint = new RedFoxEndpoint("/path");

                var connected = new ManualResetEventSlim();
                var disconnected = new ManualResetEventSlim();

                publisher.ClientConnected += (s, c) => connected.Set();
                publisher.ClientDisconnected += s => disconnected.Set();

                publisher.Bind(endpoint);
                subscriber.Connect(endpoint);

                Assert.IsTrue(connected.Wait(TimeSpan.FromSeconds(1)));

                publisher.Unbind(endpoint);

                Assert.IsTrue(disconnected.Wait(TimeSpan.FromSeconds(1)));
            }
        }
Пример #55
0
        public void ServiceQueue_connect_Writer_send_single_message_received_fires_MessageFrameReceived_event()
        {
            using (var serviceQueue = new ServiceQueue())
            using (var writer = new ServiceQueueWriter())
            {
                var endpoint = new RedFoxEndpoint("/path");

                MessageFrame messageFrame = null;
                var received = new ManualResetEventSlim();
                serviceQueue.MessageFrameReceived += m =>
                {
                    messageFrame = m;
                    received.Set();
                };

                serviceQueue.Bind(endpoint);
                writer.Connect(endpoint);

                writer.SendMessage(new TestMessage());

                Assert.IsTrue(received.Wait(TimeSpan.FromSeconds(1)));
                Assert.IsNotNull(messageFrame);
            }
        }
Пример #56
0
 public void Bind(RedFoxEndpoint endpoint, ISocketConfiguration socketConfiguration)
 {
     var server = SocketAccepterFactory.CreateAndBind(endpoint, NodeType.Responder, socketConfiguration, OnClientConnected);
     _servers[endpoint] = server;
 }
Пример #57
0
 public void Bind(RedFoxEndpoint endpoint)
 {
     Bind(endpoint, SocketConfiguration.Default);
 }
Пример #58
0
 private void DisconnectSocketsForEndpoint(RedFoxEndpoint endpoint)
 {
     var socketsMatchingEndpoint = _clientSockets.Keys.Where(socket => socket.Endpoint.Equals(endpoint));
     foreach (var socket in socketsMatchingEndpoint)
     {
         socket.Disconnect();
     }
 }
Пример #59
0
        public bool Unbind(RedFoxEndpoint endpoint)
        {
            ISocketAccepter removedServer;
            var serverRemoved = _servers.TryRemove(endpoint, out removedServer);
            if (serverRemoved)
            {
                removedServer.Unbind();
                DisconnectSocketsForEndpoint(endpoint);
            }

            return serverRemoved;
        }
Пример #60
0
 public bool UnregisterAccepter(RedFoxEndpoint endpoint)
 {
     BlockingCollection<InProcSocketPair> oldValue;
     return _registeredAccepterPorts.TryRemove(endpoint, out oldValue);
 }