Exemplo n.º 1
0
        public NettyServerTransport(
            ThriftServerDef def,
            NettyServerConfig nettyServerConfig)
        {
            this._logger            = nettyServerConfig.LoggerFactory?.CreateLogger(this.GetType()) ?? NullLogger.Instance;
            this._def               = def;
            this._nettyServerConfig = nettyServerConfig;
            this._requestedPort     = def.ServerPort;
            //this.allChannels = allChannels;


            //this.channelStatistics = new ChannelStatistics(allChannels);

            //this.sslConfiguration.set(this.def.getSslConfiguration());
            X509Certificate2 tlsCertificate = null;

            if (this._def.SslConfig != null)
            {
                tlsCertificate = CertificateHelper.GetCertificate(this._def.SslConfig);
            }

            this._pipelineSetup = cp =>
            {
                TProtocolFactory inputProtocolFactory = def.DuplexProtocolFactory.GetInputProtocolFactory();
                if (tlsCertificate != null)
                {
                    cp.AddLast("tls", TlsHandler.Server(tlsCertificate));
                }
                //NiftySecurityHandlers securityHandlers = def.getSecurityFactory().getSecurityHandlers(def, nettyServerConfig);
                cp.AddLast("connectionContext", new ConnectionContextHandler());
                if (def.MaxConnections > 0 && def.MaxConnections != int.MaxValue)
                {
                    // connectionLimiter must be instantiated exactly once (and thus outside the pipeline factory)
                    ConnectionLimiter connectionLimiter = new ConnectionLimiter(def.MaxConnections, nettyServerConfig.LoggerFactory);
                    cp.AddLast("connectionLimiter", connectionLimiter);
                }
                //cp.addLast(ChannelStatistics.NAME, channelStatistics);
                //cp.AddLast("encryptionHandler", securityHandlers.getEncryptionHandler());
                //cp.AddLast("ioDispatcher", new NiftyIODispatcher());

                //cp.AddLast("encoder", new DefaultThriftFrameEncoder(def.MaxFrameSize));
                cp.AddLast("thriftDecoder", def.ThriftFrameCodecFactory.Create(def.MaxFrameSize, inputProtocolFactory, _nettyServerConfig.LoggerFactory));
                if (def.ClientIdleTimeout > TimeSpan.Zero)
                {
                    // Add handlers to detect idle client connections and disconnect them
                    cp.AddLast("idleTimeoutHandler", new IdleStateHandler(
                                   (int)def.ClientIdleTimeout.TotalSeconds,
                                   NoWriterIdleTimeout,
                                   NoAllIdleTimeout));
                    cp.AddLast("idleDisconnectHandler", new IdleDisconnectHandler());
                }

                //cp.addLast("authHandler", securityHandlers.getAuthenticationHandler());
                cp.AddLast("dispatcher", new NiftyDispatcher(def, nettyServerConfig.Timer, nettyServerConfig.IOThreadCount, nettyServerConfig.LoggerFactory));
                //cp.AddLast("exceptionLogger", new NiftyExceptionLogger());
            };
        }
Exemplo n.º 2
0
        public NiftyDispatcher(ThriftServerDef serverDef, ITimer timer, int?ioThreadCount, ILoggerFactory loggerFactory = null)
        {
            Guard.ArgumentNotNull(timer, nameof(timer));
            this._taskTimeoutTimer = timer;

            _logger = loggerFactory?.CreateLogger(this.GetType()) ?? NullLogger.Instance;
            this._processorFactory = serverDef.ProcessorFactory;
            //this.exe = serverDef.Executor;
            this._taskTimeoutMillis     = (long)serverDef.TaskTimeout.TotalMilliseconds;
            this._queueTimeoutMillis    = (long)serverDef.QueueTimeout.TotalMilliseconds;
            this._queuedResponseLimit   = serverDef.QueuedResponseLimit;
            this._duplexProtocolFactory = serverDef.DuplexProtocolFactory;

            if (ioThreadCount.HasValue && ioThreadCount.Value > 0)
            {
                LimitedConcurrencyLevelTaskScheduler limitedScheduler = new LimitedConcurrencyLevelTaskScheduler(ioThreadCount.Value);
                _factory = new TaskFactory(limitedScheduler);
            }
            else
            {
                _factory = Task.Factory;
            }
        }
Exemplo n.º 3
0
        //private readonly ChannelStatistics channelStatistics;

        //private AtomicReference<SslServerConfiguration> sslConfiguration = new AtomicReference<>();

        public NettyServerTransport(ThriftServerDef def) :
            this(def, new NettyServerConfig())
        {
        }