public TCPManager(string ipAddress)
        {
            IPAddress = ipAddress;
            // Create message receiver receiving 'MyRequest' and receiving 'MyResponse'.
            aReceiverFactory = new DuplexTypedMessagesFactory();
            myReceiver       = aReceiverFactory.CreateDuplexTypedMessageReceiver <String, String>();

            // Subscribe to handle messages.
            myReceiver.MessageReceived += OnMessageReceived;

            // Create TCP messaging.
            // Note: 192.168.0.100 is the IP from the wireless router (no internet)
            // and 8800 is the socket.
            aMessaging     = new TcpMessagingSystemFactory();
            anInputChannel = aMessaging.CreateDuplexInputChannel(IPAddress);

            // Attach the input channel and start to listen to messages.
            try
            {
                myReceiver.AttachDuplexInputChannel(anInputChannel);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemple #2
0
        public YZXCMessagingNode(
            YZXMessagingType messagingtype     = YZXMessagingType.Tcp,
            YZXSerializerType serializertype   = YZXSerializerType.Xml,
            YZXMessagesFactoryType factorytype = YZXMessagesFactoryType.Duplex)
        {
            DSenderFactory = new DuplexTypedMessagesFactory();

            DReceiverFactory = new DuplexTypedMessagesFactory();

            switch (messagingtype)
            {
            case YZXMessagingType.Tcp:
                UnderlyingMessaging = new TcpMessagingSystemFactory();
                break;

            case YZXMessagingType.Http:
                UnderlyingMessaging = new HttpMessagingSystemFactory();
                break;

            case YZXMessagingType.WebSocket:
                UnderlyingMessaging = new WebSocketMessagingSystemFactory();
                break;
            }

            switch (serializertype)
            {
            case YZXSerializerType.Xml:
                serializer = new XmlStringSerializer();
                break;

            case YZXSerializerType.Json:
                serializer = new DataContractJsonStringSerializer();
                break;
            }
        }
Exemple #3
0
            // 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;
                    }
                }
            }
 public DuplexRouter(IMessagingSystemFactory duplexOutpuChannelsMessagingFactory)
 {
     using (EneterTrace.Entering())
     {
         MessagingSystemFactory = duplexOutpuChannelsMessagingFactory;
     }
 }
 public RoundRobinBalancer(IMessagingSystemFactory outputMessagingFactory)
 {
     using (EneterTrace.Entering())
     {
         myOutputMessagingFactory = outputMessagingFactory;
     }
 }
 public ServiceMock(IMessagingSystemFactory messaging, string channelId)
 {
     InputChannel = messaging.CreateDuplexInputChannel(channelId);
     InputChannel.ResponseReceiverConnected    += OnResponseReceiverConnected;
     InputChannel.ResponseReceiverDisconnected += OnResponseReceiverDisconnected;
     InputChannel.MessageReceived += OnMessageReceived;
 }
 /// <summary>
 /// Constructs the duplex router factory.
 /// </summary>
 /// <param name="duplexOutputChannelMessaging">
 /// the messaging system factory used to create duplex output channels
 /// </param>
 public DuplexRouterFactory(IMessagingSystemFactory duplexOutputChannelMessaging)
 {
     using (EneterTrace.Entering())
     {
         myDuplexOutputChannelMessaging = duplexOutputChannelMessaging;
     }
 }
Exemple #8
0
 /// <summary>
 /// Creates duplex channel unwrapper.
 /// </summary>
 /// <returns></returns>
 public IDuplexChannelUnwrapper CreateDuplexChannelUnwrapper(IMessagingSystemFactory outputMessagingSystem)
 {
     using (EneterTrace.Entering())
     {
         return(new DuplexChannelUnwrapper(outputMessagingSystem, Serializer));
     }
 }
 /// <summary>
 /// Constructs the duplex dispatcher factory.
 /// </summary>
 /// <param name="duplexOutputChannelsFactory">
 /// the messaging system factory used to create duplex output channels
 /// </param>
 public DuplexDispatcherFactory(IMessagingSystemFactory duplexOutputChannelsFactory)
 {
     using (EneterTrace.Entering())
     {
         myMessagingSystemFactory = duplexOutputChannelsFactory;
     }
 }
Exemple #10
0
 /// <summary>
 /// Constructs factory that will be used only by a service.
 /// </summary>
 /// <remarks>
 /// The constructor takes only callbacks which are used by the service. Therefore if you use this constructor
 /// you can create only duplex input channels.
 /// </remarks>
 /// <param name="underlyingMessagingSystem">underlying messaging upon which the authentication will work.</param>
 /// <param name="getHandshakeMessageCallback">callback called by the input chanel to get the handshake message for the login message which was received from the output channel.</param>
 /// <param name="authenticateCallback">callback called by the input channe to perform the authentication.</param>
 /// <param name="handleAuthenticationCancelledCallback">callback called by the input channel to indicate the output channel closed the connection during the authentication procedure.
 /// Can be null if your authentication code does not need to handle it.
 /// </param>
 public AuthenticatedMessagingFactory(IMessagingSystemFactory underlyingMessagingSystem,
                                      GetHanshakeMessage getHandshakeMessageCallback,
                                      Authenticate authenticateCallback,
                                      HandleAuthenticationCancelled handleAuthenticationCancelledCallback)
     : this(underlyingMessagingSystem, null, null, getHandshakeMessageCallback, authenticateCallback, handleAuthenticationCancelledCallback)
 {
 }
 /// <summary>
 /// Constructs the factory.
 /// </summary>
 /// <param name="duplexOutputChannelsFactory">
 /// messaging system used to create duplex output channels that will be used for the communication with
 /// services from the farm.
 /// </param>
 public RoundRobinBalancerFactory(IMessagingSystemFactory duplexOutputChannelsFactory)
 {
     using (EneterTrace.Entering())
     {
         myDuplexOutputChannelsFactory = duplexOutputChannelsFactory;
     }
 }
 /// <summary>
 /// Constructs the factory.
 /// </summary>
 /// <param name="outputMessagingFactory">messaging system used to connect services (receivers) via the duplex output channels
 /// </param>
 public BackupConnectionRouterFactory(IMessagingSystemFactory outputMessagingFactory)
 {
     using (EneterTrace.Entering())
     {
         myOutputMessagingFactory = outputMessagingFactory;
     }
 }
Exemple #13
0
 public TInputChannelContext(IMessagingSystemFactory messaging, Func <IEnumerable <string> > getOutputChannelIds)
 {
     using (EneterTrace.Entering())
     {
         myMessaging           = messaging;
         myGetOutputChannelIds = getOutputChannelIds;
     }
 }
 /// <summary>
 /// Constructs the factory from the specified parameters.
 /// </summary>
 /// <param name="underlyingMessaging">underlying messaging system e.g. Websocket, TCP, ...</param>
 /// <param name="maxOfflineTime">the max time, the communicating applications can be disconnected</param>
 public BufferedMessagingFactory(IMessagingSystemFactory underlyingMessaging, TimeSpan maxOfflineTime)
 {
     using (EneterTrace.Entering())
     {
         myUnderlyingMessaging = underlyingMessaging;
         myMaxOfflineTime      = maxOfflineTime;
     }
 }
 public ClientMockFarm(IMessagingSystemFactory messaging, string channelId, int numberOfClients)
 {
     for (int i = 0; i < numberOfClients; ++i)
     {
         ClientMock aClient = new ClientMock(messaging, channelId);
         myClients.Add(aClient);
     }
 }
Exemple #16
0
 // Client opens connections to all available outputs.
 public void OpenOutputConnections(IMessagingSystemFactory messaging, IEnumerable <string> availableOutputChannelIds)
 {
     using (EneterTrace.Entering())
     {
         foreach (string aChannelId in availableOutputChannelIds)
         {
             OpenOutputConnection(messaging, aChannelId);
         }
     }
 }
Exemple #17
0
        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>();
        }
Exemple #18
0
        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 CalculatorService(string address, IMessagingSystemFactory messaging)
            {
                using (EneterTrace.Entering())
                {
                    IDuplexTypedMessagesFactory aReceiverFactory = new DuplexTypedMessagesFactory();

                    myRequestReceiver = aReceiverFactory.CreateDuplexTypedMessageReceiver <double, Interval>();
                    myRequestReceiver.MessageReceived += OnMessageReceived;

                    IDuplexInputChannel anInputChannel = messaging.CreateDuplexInputChannel(address);
                    myRequestReceiver.AttachDuplexInputChannel(anInputChannel);
                }
            }
Exemple #20
0
        public LoadBalancer(string value)
        {
            messageCreator = new TcpMessagingSystemFactory();

            RRLoadBalancer = new RoundRobinBalancerFactory(messageCreator).CreateLoadBalancer();

            foreach (string ipaddress in GetServiceIPs())
            {
                RRLoadBalancer.AddDuplexOutputChannel(ipaddress);
            }

            input = messageCreator.CreateDuplexInputChannel("tcp://127.0.0.1:65000");

            RRLoadBalancer.AttachDuplexInputChannel(input);
        }
        /// <summary>
        /// Constructs the factory from specified parameters.
        /// </summary>
        /// <param name="underlyingMessaging">underlying messaging system e.g. Websocket, TCP, ...</param>
        /// <param name="pingFrequency">how often the ping message is sent.</param>
        /// <param name="pingReceiveTimeout">the maximum time within it the ping message must be received.</param>
        public MonitoredMessagingFactory(IMessagingSystemFactory underlyingMessaging,
                                         TimeSpan pingFrequency,
                                         TimeSpan pingReceiveTimeout)
        {
            using (EneterTrace.Entering())
            {
                myUnderlyingMessaging = underlyingMessaging;
                PingFrequency         = pingFrequency;
                ReceiveTimeout        = pingReceiveTimeout;
                Serializer            = new MonitoredMessagingCustomSerializer();

                InputChannelThreading  = new SyncDispatching();
                OutputChannelThreading = InputChannelThreading;
            }
        }
        /// <summary>
        /// Constructs the factory with the specified parameters.
        /// </summary>
        /// <param name="underlyingMessaging">underlying messaging system e.g. TCP</param>
        /// <param name="maxOfflineTime">the maximum time, the messaging can work offline. When the messaging works offline,
        /// the sent messages are buffered and the connection is being reopened. If the connection is
        /// not reopen within maxOfflineTime, the connection is closed.
        /// </param>
        /// <param name="pingFrequency">how often the connection is checked with the 'ping' requests.</param>
        /// <param name="pingResponseTimeout">the maximum time, the response for the 'ping' is expected.</param>
        public BufferedMonitoredMessagingFactory(IMessagingSystemFactory underlyingMessaging,

                                                 // Buffered Messaging
                                                 TimeSpan maxOfflineTime,

                                                 // Monitored Messaging
                                                 TimeSpan pingFrequency,
                                                 TimeSpan pingResponseTimeout)
        {
            using (EneterTrace.Entering())
            {
                myMonitoredMessaging = new MonitoredMessagingFactory(underlyingMessaging, pingFrequency, pingResponseTimeout);
                myBufferedMessaging  = new BufferedMessagingFactory(myMonitoredMessaging, maxOfflineTime);
            }
        }
        public DuplexChannelUnwrapper(IMessagingSystemFactory outputMessagingFactory, ISerializer serializer)
        {
            using (EneterTrace.Entering())
            {
                if (serializer == null)
                {
                    string anError = "Input parameter serializer is null.";
                    EneterTrace.Error(anError);
                    throw new ArgumentNullException(anError);
                }

                myOutputMessagingFactory = outputMessagingFactory;
                mySerializer             = serializer;
            }
        }
Exemple #24
0
        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;
            }
        }
        /// <summary>
        /// Constructs the factory.
        /// </summary>
        /// <param name="serviceConnectingAddress">message bus address intended for services which want to register in the message bus.
        /// It can be null if the message bus factory is intended to create only duplex output channels.</param>
        /// <param name="clientConnectingAddress">clientConnectingAddress message bus address intended for clients which want to connect a registered service.
        /// It can be null if the message bus factory is intended to create only duplex input channels.</param>
        /// <param name="serviceUnderlyingMessaging">underlying messaging used for services which connect the message bus to expose services.
        /// It can be null if the message bus factory is intended to create only duplex output channels.</param>
        /// <param name="clientUnderlyingMessaging">underlying messaging used for clients which connect the message bus to consume an exposed service.
        /// It can be null if the message bus factory is intended to create only duplex input channels.</param>
        /// <param name="serializer">serializer which is used to serialize {@link MessageBusMessage} which is internally used for the communication with
        /// the message bus. If null then custom message bus serializer is used.</param>
        public MessageBusMessagingFactory(string serviceConnectingAddress, string clientConnectingAddress, IMessagingSystemFactory serviceUnderlyingMessaging, IMessagingSystemFactory clientUnderlyingMessaging, ISerializer serializer)
        {
            using (EneterTrace.Entering())
            {
                ISerializer aSerializer = serializer ?? new MessageBusCustomSerializer();
                myOutputConnectorFactory = new MessageBusOutputConnectorFactory(clientConnectingAddress, aSerializer);
                myInputConnectorFactory  = new MessageBusInputConnectorFactory(serviceConnectingAddress, aSerializer);

                ClientMessaging  = clientUnderlyingMessaging;
                ServiceMessaging = serviceUnderlyingMessaging;

                // Dispatch events in the same thread as notified from the underlying messaging.
                OutputChannelThreading = new NoDispatching();
                InputChannelThreading  = OutputChannelThreading;
            }
        }
Exemple #26
0
        /// <summary>
        /// Constructs factory that can be used by client and service simultaneously.
        /// </summary>
        /// <remarks>
        /// If you construct the factory with this constructor you can create both duplex output channels and
        /// duplex input channels.
        /// </remarks>
        /// <param name="underlyingMessagingSystem">underlying messaging upon which the authentication will work.</param>
        /// <param name="getLoginMessageCallback">callback called by the output channel to get the login message which shall be used to open the connection</param>
        /// <param name="getHandshakeResponseMessageCallback">callback called by the output channel to get the response for the handshake message which was received from the input channel.</param>
        /// <param name="getHandshakeMessageCallback">callback called by the input chanel to get the handshake message for the login message which was received from the output channel.</param>
        /// <param name="authenticateCallback">callback called by the input channe to perform the authentication.</param>
        /// <param name="handleAuthenticationCancelledCallback">callback called by the input channel to indicate the output channel closed the connection during the authentication procedure.
        /// Can be null if your authentication code does not need to handle it.
        /// (E.g. if the authentication logic needs to clean if the authentication fails.)</param>
        public AuthenticatedMessagingFactory(IMessagingSystemFactory underlyingMessagingSystem,
                                             GetLoginMessage getLoginMessageCallback,
                                             GetHandshakeResponseMessage getHandshakeResponseMessageCallback,
                                             GetHanshakeMessage getHandshakeMessageCallback,
                                             Authenticate authenticateCallback,
                                             HandleAuthenticationCancelled handleAuthenticationCancelledCallback)
        {
            using (EneterTrace.Entering())
            {
                myUnderlyingMessaging = underlyingMessagingSystem;
                AuthenticationTimeout = TimeSpan.FromMilliseconds(30000);

                myGetLoginMessageCallback             = getLoginMessageCallback;
                myGetHandShakeMessageCallback         = getHandshakeMessageCallback;
                myGetHandshakeResponseMessageCallback = getHandshakeResponseMessageCallback;
                myAuthenticateCallback          = authenticateCallback;
                myHandleAuthenticationCancelled = handleAuthenticationCancelledCallback;

                OutputChannelThreading = new SyncDispatching();
            }
        }
 /// <summary>
 /// Constructs the factory with default settings.
 /// </summary>
 /// <remarks>
 /// It uses optimized custom serializer which is optimized to serialize/deserialize MonitorChannelMessage which is
 /// used for the internal communication between output and input channels.
 /// The ping message is sent once per second and it is expected the ping message is received at least once per two seconds.
 /// </remarks>
 /// <param name="underlyingMessaging">underlying messaging system e.g. HTTP, TCP, ...</param>
 public MonitoredMessagingFactory(IMessagingSystemFactory underlyingMessaging)
     : this(underlyingMessaging, TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(2000))
 {
 }
 /// <summary>
 /// Constructs the factory with default settings.
 /// </summary>
 /// <remarks>
 /// The maximum offline time for buffered messaging is set to 10 seconds.
 /// The ping frequency for monitored messaging is set to 1 second and the receive timeout for monitored messaging
 /// is set to 2 seconds.
 /// </remarks>
 /// <param name="underlyingMessaging">underlying messaging system e.g. TCP, ...</param>
 public BufferedMonitoredMessagingFactory(IMessagingSystemFactory underlyingMessaging)
     : this(underlyingMessaging,
            TimeSpan.FromMilliseconds(10000), // max offline time
            TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(2000))
 {
 }
Exemple #29
0
 /// <summary>
 /// Constructs factory that will be used only by a client.
 /// </summary>
 /// <remarks>
 /// The constructor takes only callbacks which are used by the client. Therefore if you use this constructor
 /// you can create only duplex output channels.
 /// </remarks>
 /// <param name="underlyingMessagingSystem">underlying messaging upon which the authentication will work.</param>
 /// <param name="getLoginMessageCallback">callback called by the output channel to get the login message which shall be used to open the connection</param>
 /// <param name="getHandshakeResponseMessageCallback">callback called by the output channel to get the response for the handshake message which was received from the input channel.</param>
 public AuthenticatedMessagingFactory(IMessagingSystemFactory underlyingMessagingSystem,
                                      GetLoginMessage getLoginMessageCallback,
                                      GetHandshakeResponseMessage getHandshakeResponseMessageCallback)
     : this(underlyingMessagingSystem, getLoginMessageCallback, getHandshakeResponseMessageCallback, null, null, null)
 {
 }
Exemple #30
0
 /// <summary>
 /// Constructs factory that will be used only by a service.
 /// </summary>
 /// <remarks>
 /// The constructor takes only callbacks which are used by the service. Therefore if you use this constructor
 /// you can create only duplex input channels.
 /// </remarks>
 /// <param name="underlyingMessagingSystem">underlying messaging upon which the authentication will work.</param>
 /// <param name="getHandshakeMessageCallback">callback returning the handshake message.</param>
 /// <param name="authenticateCallback">callback performing the authentication.</param>
 public AuthenticatedMessagingFactory(IMessagingSystemFactory underlyingMessagingSystem,
                                      GetHanshakeMessage getHandshakeMessageCallback,
                                      Authenticate authenticateCallback)
     : this(underlyingMessagingSystem, null, null, getHandshakeMessageCallback, authenticateCallback, null)
 {
 }