示例#1
0
 public ThriftServer(
     INiftyProcessor processor,
     ThriftServerConfig serverConfig,
     SslConfig sslConfig          = null,
     ILoggerFactory loggerFactory = null)
     : this(processor,
            serverConfig,
            DefaultFrameCodecFactories,
            DefaultProtocolFactories,
            sslConfig,
            loggerFactory)
 {
 }
示例#2
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);
        }