// Client opens connection to a particular output. public void OpenOutputConnection(IMessagingSystemFactory messaging, string channelId) { using (EneterTrace.Entering()) { IDuplexOutputChannel anOutputChannel = null; try { using (ThreadLock.Lock(myOutputConnectionLock)) { anOutputChannel = messaging.CreateDuplexOutputChannel(channelId); anOutputChannel.ConnectionClosed += OnConnectionClosed; anOutputChannel.ResponseMessageReceived += OnResponseMessageReceived; anOutputChannel.OpenConnection(); // Connection is successfuly open so it can be stored. myOpenOutputConnections.Add(anOutputChannel); } } catch (Exception err) { EneterTrace.Warning("Failed to open connection to '" + channelId + "'.", err); if (anOutputChannel != null) { anOutputChannel.ConnectionClosed -= OnConnectionClosed; anOutputChannel.ResponseMessageReceived -= OnResponseMessageReceived; } throw; } } }
protected void Setup(IMessagingSystemFactory messagingSystemFactory, string channelId, ISerializer serializer) { MessagingSystemFactory = messagingSystemFactory; DuplexOutputChannel = MessagingSystemFactory.CreateDuplexOutputChannel(channelId); DuplexInputChannel = MessagingSystemFactory.CreateDuplexInputChannel(channelId); IDuplexTypedMessagesFactory aMessageFactory = new DuplexTypedMessagesFactory(serializer); Requester = aMessageFactory.CreateDuplexTypedMessageSender <int, int>(); Responser = aMessageFactory.CreateDuplexTypedMessageReceiver <int, int>(); }
protected void Setup(IMessagingSystemFactory messagingSystemFactory, string channelId) { MessagingSystemFactory = messagingSystemFactory; DuplexOutputChannel = MessagingSystemFactory.CreateDuplexOutputChannel(channelId); DuplexInputChannel = MessagingSystemFactory.CreateDuplexInputChannel(channelId); IDuplexStringMessagesFactory aMessageFactory = new DuplexStringMessagesFactory(); MessageRequester = aMessageFactory.CreateDuplexStringMessageSender(); MessageResponser = aMessageFactory.CreateDuplexStringMessageReceiver(); }
public AndroidUsbDuplexOutputChannel(int port, string responseReceiverId, int adbHostPort, IMessagingSystemFactory underlyingTcpMessaging) { using (EneterTrace.Entering()) { ChannelId = port.ToString(); ResponseReceiverId = (string.IsNullOrEmpty(responseReceiverId)) ? port + "_" + Guid.NewGuid().ToString() : responseReceiverId; myAdbHostPort = adbHostPort; string anIpAddressAndPort = "tcp://127.0.0.1:" + ChannelId + "/"; myOutputchannel = underlyingTcpMessaging.CreateDuplexOutputChannel(anIpAddressAndPort, ResponseReceiverId); myOutputchannel.ConnectionOpened += OnConnectionOpened; myOutputchannel.ConnectionClosed += OnConnectionClosed; myOutputchannel.ResponseMessageReceived += OnResponseMessageReceived; } }
private void Notify(int numberOfTimes, ISerializer serializer, IMessagingSystemFactory messaging, string aBrokerAddress) { IDuplexInputChannel aBrokerInputChannel = messaging.CreateDuplexInputChannel(aBrokerAddress); IDuplexOutputChannel aClient1OutputChannel = messaging.CreateDuplexOutputChannel(aBrokerAddress); IDuplexOutputChannel aClient2OutputChannel = messaging.CreateDuplexOutputChannel(aBrokerAddress); // Specify in the factory that the publisher shall not be notified from its own published events. IDuplexBrokerFactory aBrokerFactory = new DuplexBrokerFactory(serializer) { IsPublisherNotified = false }; IDuplexBroker aBroker = aBrokerFactory.CreateBroker(); aBroker.AttachDuplexInputChannel(aBrokerInputChannel); IDuplexBrokerClient aClient1 = aBrokerFactory.CreateBrokerClient(); int aCount = 0; AutoResetEvent aCompletedEvent = new AutoResetEvent(false); aClient1.BrokerMessageReceived += (x, y) => { ++aCount; if (aCount == numberOfTimes) { aCompletedEvent.Set(); } }; aClient1.AttachDuplexOutputChannel(aClient1OutputChannel); IDuplexBrokerClient aClient2 = aBrokerFactory.CreateBrokerClient(); aClient2.AttachDuplexOutputChannel(aClient2OutputChannel); try { var aTimer = new PerformanceTimer(); aTimer.Start(); aClient1.Subscribe("TypeA"); for (int i = 0; i < numberOfTimes; ++i) { // Notify the message. aClient2.SendMessage("TypeA", "Message A"); } aCompletedEvent.WaitOne(); aTimer.Stop(); // Client 2 should not get the notification. Assert.AreEqual(numberOfTimes, aCount); } finally { aClient1.DetachDuplexOutputChannel(); aClient2.DetachDuplexOutputChannel(); aBroker.DetachDuplexInputChannel(); } }
public ClientMock(IMessagingSystemFactory messaging, string channelId) : this(messaging.CreateDuplexOutputChannel(channelId)) { }
public TClient(IMessagingSystemFactory messaging, string channelId) { myOutputChannel = messaging.CreateDuplexOutputChannel(channelId); myOutputChannel.ResponseMessageReceived += OnResponseMessageReceived; }