Example #1
0
        /// <param name="handlerEventLoopGroupFactory"></param>
        /// <param name="targetAddress">Ignored</param>
        /// <param name="targetPort">Ignored</param>
        /// <param name="certificate">Ignored</param>
        /// <returns></returns>
        public override async Task <IObservableChannel> BuildChannelAsync(IEventLoopGroupFactory handlerEventLoopGroupFactory,
                                                                          IPAddress targetAddress,
                                                                          int targetPort,
                                                                          X509Certificate2 certificate = null)
        {
            var channel = await BootStrapChannelAsync(handlerEventLoopGroupFactory, targetAddress, targetPort).ConfigureAwait(false);

            var messageStream = channel.Pipeline.Get <IObservableServiceHandler>()?.MessageStream;

            return(new ObservableChannel(messageStream
                                         ?? Observable.Never <IObserverDto <ProtocolMessage> >(), channel));
        }
Example #2
0
        /// <param name="eventLoopGroupFactory"></param>
        /// <param name="targetAddress">Ignored</param>
        /// <param name="targetPort">Ignored</param>
        /// <param name="certificate">Local TLS certificate</param>
        public override async Task <IObservableChannel> BuildChannel(IEventLoopGroupFactory eventLoopGroupFactory,
                                                                     IPAddress targetAddress,
                                                                     int targetPort,
                                                                     X509Certificate2 certificate = null)
        {
            var channel = await Bootstrap(eventLoopGroupFactory, targetAddress, targetPort, certificate);

            var messageStream = _observableServiceHandler.MessageStream;

            return(new ObservableChannel(messageStream
                                         ?? Observable.Never <IObserverDto <ProtocolMessage> >(), channel));
        }
        protected async Task <IChannel> BootStrapChannelAsync(IEventLoopGroupFactory handlerEventLoopGroupFactory,
                                                              IPAddress address,
                                                              int port)
        {
            var channelHandler = new ServerChannelInitializerBase <IChannel>(HandlerGenerationFunction, handlerEventLoopGroupFactory);

            return(await new Bootstrap()
                   .Group(handlerEventLoopGroupFactory.GetOrCreateSocketIoEventLoopGroup())
                   .ChannelFactory(() => new SocketDatagramChannel(AddressFamily.InterNetwork))
                   .Option(ChannelOption.SoBroadcast, true)
                   .Handler(new LoggingHandler(LogLevel.DEBUG))
                   .Handler(channelHandler)
                   .BindAsync(address, port)
                   .ConfigureAwait(false));
        }
Example #4
0
        public async Task Can_Dispose_All_Event_Loops()
        {
            _eventFactory = new TcpClientEventLoopGroupFactory(_eventLoopGroupFactoryConfiguration);
            IEventLoopGroup[] eventLoops =
            {
                _eventFactory.GetOrCreateHandlerWorkerEventLoopGroup(),
                _eventFactory.GetOrCreateSocketIoEventLoopGroup()
            };

            _eventFactory.Dispose();

            while (!eventLoops.All(x => x.IsShutdown))
            {
                await Task.Delay(100).ConfigureAwait(false);
            }

            eventLoops.ToList().ForEach(eventLoop => eventLoop.IsShutdown.Should().BeTrue());
        }
Example #5
0
        protected async Task <IChannel> BootstrapAsync(IEventLoopGroupFactory handlerEventLoopGroupFactory,
                                                       IPAddress targetAddress,
                                                       int targetPort,
                                                       X509Certificate2 certificate)
        {
            var supervisorLoopGroup = ((ITcpServerEventLoopGroupFactory)handlerEventLoopGroupFactory)
                                      .GetOrCreateSupervisorEventLoopGroup();
            var channelHandler = new ServerChannelInitializerBase <IChannel>(HandlerGenerationFunction, handlerEventLoopGroupFactory, certificate);

            return(await new ServerBootstrap()
                   .Group(handlerEventLoopGroupFactory.GetOrCreateSocketIoEventLoopGroup(), supervisorLoopGroup)
                   .ChannelFactory(() => new TcpServerSocketChannel())
                   .Option(ChannelOption.SoBacklog, _backLogValue)
                   .Handler(new LoggingHandler(LogLevel.DEBUG))
                   .ChildHandler(channelHandler)
                   .BindAsync(targetAddress, targetPort)
                   .ConfigureAwait(false));
        }
Example #6
0
        protected async Task <IChannel> Bootstrap(IEventLoopGroupFactory handlerEventLoopGroupFactory,
                                                  IPAddress targetAddress,
                                                  int targetPort,
                                                  X509Certificate2 certificate = null)
        {
            var channelHandler = new ClientChannelInitializerBase <ISocketChannel>(HandlerGenerationFunction,
                                                                                   handlerEventLoopGroupFactory,
                                                                                   targetAddress,
                                                                                   certificate);

            return(await new Bootstrap()
                   .Group(handlerEventLoopGroupFactory.GetOrCreateSocketIoEventLoopGroup())
                   .ChannelFactory(() => new TcpSocketChannel())
                   .Option(ChannelOption.SoBacklog, _backLogValue)
                   .Handler(new LoggingHandler(LogLevel.DEBUG))
                   .Handler(channelHandler)
                   .ConnectAsync(targetAddress, targetPort)
                   .ConfigureAwait(false));
        }
Example #7
0
 public void Can_Spawn_Correct_Amount_Of_Tcp_Client_Event_Loops()
 {
     _eventFactory = new TcpClientEventLoopGroupFactory(_eventLoopGroupFactoryConfiguration);
     AssertEventLoopSize(_eventFactory.GetOrCreateHandlerWorkerEventLoopGroup(), ExpectedTcpClientThreads);
     AssertEventLoopSize(_eventFactory.GetOrCreateSocketIoEventLoopGroup(), ExpectedDefaultEventLoopThreadCount);
 }
Example #8
0
 public TestTcpServer(ITcpServerChannelFactory tcpServerChannelFactory,
                      ILogger logger,
                      IEventLoopGroupFactory eventLoopGroupFactory) : base(tcpServerChannelFactory, logger, eventLoopGroupFactory)
 {
     Channel = Substitute.For <IChannel>();
 }
Example #9
0
 public TestSocketBase(IChannelFactory channelFactory,
                       ILogger logger,
                       IEventLoopGroupFactory eventLoopGroupFactory) : base(channelFactory, logger, eventLoopGroupFactory)
 {
     Channel = Substitute.For <IChannel>();
 }
 public abstract Task <IObservableChannel> BuildChannelAsync(IEventLoopGroupFactory eventLoopGroupFactory,
                                                             IPAddress targetAddress,
                                                             int targetPort,
                                                             X509Certificate2 certificate = null);
Example #11
0
 protected TcpServer(ITcpServerChannelFactory tcpChannelFactory,
                     ILogger logger,
                     IEventLoopGroupFactory eventLoopGroupFactory)
     : base(tcpChannelFactory, logger, eventLoopGroupFactory)
 {
 }
Example #12
0
 protected ClientBase(IChannelFactory channelFactory, ILogger logger, IEventLoopGroupFactory handlerEventEventLoopGroupFactory)
     : base(channelFactory, logger, handlerEventEventLoopGroupFactory)
 {
 }
Example #13
0
 protected SocketBase(IChannelFactory channelFactory, ILogger logger, IEventLoopGroupFactory eventLoopGroupFactory)
 {
     ChannelFactory        = channelFactory;
     _logger               = logger;
     EventLoopGroupFactory = eventLoopGroupFactory;
 }
 /// <inheritdoc />
 internal ServerChannelInitializerBase(Func <IList <IChannelHandler> > handlerGenerationFunction,
                                       IEventLoopGroupFactory eventLoopGroupFactory,
                                       X509Certificate certificate = null)
     : base(handlerGenerationFunction, eventLoopGroupFactory, certificate: certificate)
 {
 }