예제 #1
0
        public ThriftServer(NettyServerConfig nettyServerConfig, ThriftServerDef thriftServerDef, ILoggerFactory loggerFactory = null)
        {
            Guard.ArgumentNotNull(nettyServerConfig, nameof(nettyServerConfig));
            Guard.ArgumentNotNull(thriftServerDef, nameof(thriftServerDef));

            _eventLocked = new ManualResetEvent(true);
            _logger      = loggerFactory?.CreateLogger <ThriftServer>() ?? (ILogger)NullLogger.Instance;

            _transport = new NettyServerTransport(thriftServerDef, nettyServerConfig);
        }
예제 #2
0
            public ServerTester Invoke()
            {
                ThriftServiceProcessor processor = new ThriftServiceProcessor(loggerFactory: null, services: new SimpleService());

                bossExecutor     = new MultithreadEventLoopGroup(1);
                ioWorkerExecutor = new MultithreadEventLoopGroup(1);

                ThriftServerDef serverDef = new ThriftServerDef(processor, new TBinaryProtocol.Factory());

                NettyServerConfig serverConfig = new NettyServerConfig(bossGroup: bossExecutor, workerGroup: ioWorkerExecutor);

                Server = new ThriftServer(serverConfig, serverDef);
                return(this);
            }
예제 #3
0
        public ThriftServer(
            INiftyProcessor processor,
            ThriftServerConfig serverConfig,
            IDictionary <String, IThriftFrameCodecFactory> availableFrameCodecFactories,
            IDictionary <String, TDuplexProtocolFactory> availableProtocolFactories,
            SslConfig sslConfig          = null,
            ILoggerFactory loggerFactory = null
            )
        {
            Guard.ArgumentNotNull(serverConfig, nameof(serverConfig));
            Guard.ArgumentNotNull(availableFrameCodecFactories, nameof(availableFrameCodecFactories));
            Guard.ArgumentNotNull(availableProtocolFactories, nameof(availableProtocolFactories));
            Guard.ArgumentCondition(availableFrameCodecFactories.ContainsKey(serverConfig.TransportName), $"No available server transport named {serverConfig.TransportName}");
            Guard.ArgumentCondition(availableProtocolFactories.ContainsKey(serverConfig.ProtocolName), $"No available server protocol named {serverConfig.ProtocolName}");

            _eventLocked = new ManualResetEvent(true);
            _logger      = loggerFactory?.CreateLogger <ThriftServer>() ?? (ILogger)NullLogger.Instance;
            ThriftServerDef def = new ThriftServerDef(
                new DelegateNiftyProcessorFactory(t => processor),
                availableProtocolFactories[serverConfig.ProtocolName],
                "thrift",
                serverConfig.BindingAddress,
                serverConfig.Port,
                serverConfig.MaxFrameSizeBytes,
                serverConfig.MaxQueuedResponsesPerConnection,
                serverConfig.ConnectionLimit ?? int.MaxValue,
                availableFrameCodecFactories[serverConfig.TransportName],
                serverConfig.IdleConnectionTimeout,
                serverConfig.TaskExpirationTimeout != TimeSpan.Zero ? serverConfig.TaskExpirationTimeout : (TimeSpan?)null,
                serverConfig.QueueTimeout != TimeSpan.Zero ? serverConfig.QueueTimeout : (TimeSpan?)null,
                sslConfig
                );

            NettyServerConfig config = new NettyServerConfig(new HashedWheelTimer(),
                                                             new MultithreadEventLoopGroup(serverConfig.AcceptorThreadCount),
                                                             new MultithreadEventLoopGroup(serverConfig.WorkerThreadCount), serverConfig.IOThreadCount,//20170515陈慎远临时添加
                                                             null,
                                                             loggerFactory);

            //NettyServerConfig config = new NettyServerConfig(timer:new HashedWheelTimer(),
            //    bossGroup: new MultithreadEventLoopGroup(serverConfig.AcceptorThreadCount),
            //    ioThreadCount:1);


            _transport = new NettyServerTransport(def, config);
        }