예제 #1
0
            internal MessageReplyer(MessageEndPoint endPoint, IMessageHandler <TMessage, TResponse> messageHandler)
            {
                Debug.Assert(endPoint != null);
                Debug.Assert(messageHandler != null);

                _endPoint       = endPoint;
                _messageHandler = messageHandler;
            }
예제 #2
0
            /// <summary>
            /// Creates a new slot in the response table.
            /// </summary>
            /// <param name="messageEndPoint">The message end point.</param>
            public ResponseTableSlot(MessageEndPoint messageEndPoint)
            {
                Assert(messageEndPoint != null);

                _messageEndPoint = messageEndPoint;
                _seqNum          = 0;

                _completionSource = new TaskCompletionSource <object>();

                // Allocate the next free seq-num that must not habe an entry in the response table.
                do
                {
                    _seqNum = _messageEndPoint.GetNextSeqNum();
                }while (!_messageEndPoint._responseTable.TryAdd(_seqNum, _completionSource));
            }
예제 #3
0
파일: ModuleRunner.cs 프로젝트: BS88/AI4E
        private async Task RunAsync()
        {
            _services.AddSingleton(typeof(IModule), _moduleType);
            _services.AddSingleton <RemoteCommandDispatcher>();
            _services.AddSingleton <IRemoteCommandDispatcher>(p => p.GetRequiredService <RemoteCommandDispatcher>());
            _services.AddSingleton <ICommandDispatcher>(p => p.GetRequiredService <RemoteCommandDispatcher>());
            _services.AddSingleton <INonGenericRemoteCommandDispatcher>(p => p.GetRequiredService <RemoteCommandDispatcher>());
            _services.AddSingleton <INonGenericCommandDispatcher>(p => p.GetRequiredService <RemoteCommandDispatcher>());
            _services.AddSingleton <ICommandMessageTranslator, CommandMessageTranslator>();

            _services.AddSingleton <RemoteQueryDispatcher>();
            _services.AddSingleton <IRemoteQueryDispatcher>(p => p.GetRequiredService <RemoteQueryDispatcher>());
            _services.AddSingleton <IQueryDispatcher>(p => p.GetRequiredService <RemoteQueryDispatcher>());
            _services.AddSingleton <INonGenericRemoteQueryDispatcher>(p => p.GetRequiredService <RemoteQueryDispatcher>());
            _services.AddSingleton <INonGenericQueryDispatcher>(p => p.GetRequiredService <RemoteQueryDispatcher>());
            _services.AddSingleton <IQueryMessageTranslator, QueryMessageTranslator>();

            _services.AddSingleton <RemoteEventDispatcher>();
            _services.AddSingleton <IRemoteEventDispatcher>(p => p.GetRequiredService <RemoteEventDispatcher>());
            _services.AddSingleton <IEventDispatcher>(p => p.GetRequiredService <RemoteEventDispatcher>());
            _services.AddSingleton <INonGenericRemoteEventDispatcher>(p => p.GetRequiredService <RemoteEventDispatcher>());
            _services.AddSingleton <INonGenericEventDispatcher>(p => p.GetRequiredService <RemoteEventDispatcher>());
            _services.AddSingleton <IEventMessageTranslator, EventMessageTranslator>();

            var client = new TcpClient();

            client.Connect(IPAddress.Loopback, _port);

            _services.AddSingleton <IMessageEndPoint>(provider =>
            {
                var endPoint = new MessageEndPoint(client.GetStream(), provider.GetRequiredService <IMessageSerializer>(), provider);

                endPoint.RegisterAsync(new DefaultHandlerFactory <CommandMessageBroker>());
                endPoint.RegisterAsync <ActivateCommandForwarding>(new DefaultHandlerFactory <CommandMessageBroker>());
                endPoint.RegisterAsync <DeactivateCommandForwarding>(new DefaultHandlerFactory <CommandMessageBroker>());

                endPoint.RegisterAsync(new DefaultHandlerFactory <QueryMessageBroker>());
                endPoint.RegisterAsync <ActivateQueryForwarding>(new DefaultHandlerFactory <QueryMessageBroker>());
                endPoint.RegisterAsync <DeactivateQueryForwarding>(new DefaultHandlerFactory <QueryMessageBroker>());

                endPoint.RegisterAsync <DispatchEvent, EventDispatchResult>(new DefaultHandlerFactory <EventMessageBroker>());
                endPoint.RegisterAsync <ActivateEventForwarding>(new DefaultHandlerFactory <EventMessageBroker>());
                endPoint.RegisterAsync <DeactivateEventForwarding>(new DefaultHandlerFactory <EventMessageBroker>());

                endPoint.RegisterAsync <SetupModule>(new DefaultHandlerFactory <ModuleHandler>());
                endPoint.RegisterAsync <TearDownModule>(new DefaultHandlerFactory <ModuleHandler>());

                return(endPoint);
            });

            _services.AddTransient <IMessageSerializer, MessageSerializer>();

            //var serviceProvider = _services.BuildServiceProvider();
            //var messageEndPoint = serviceProvider.GetRequiredService<IMessageEndPoint>();

            //await messageEndPoint.Initialization;



            //await messageEndPoint.Completion;
        }
예제 #4
0
            public MessageReceiver(MessageEndPoint endPoint)
            {
                Debug.Assert(endPoint != null);

                _endPoint = endPoint;
            }