Ejemplo 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());
            };
        }
Ejemplo n.º 2
0
 public NiftyBootstrap(
     IEnumerable <ThriftServerDef> thriftServerDefs,
     NettyServerConfig nettyServerConfig)
 {
     Guard.ArgumentNotNull(thriftServerDefs, nameof(nettyServerConfig));
     Guard.ArgumentNotNull(nettyServerConfig, nameof(nettyServerConfig));
     _transports             = new Dictionary <ThriftServerDef, NettyServerTransport>();
     this._nettyServerConfig = nettyServerConfig;
     foreach (ThriftServerDef thriftServerDef in thriftServerDefs)
     {
         _transports.Add(thriftServerDef, new NettyServerTransport(thriftServerDef,
                                                                   nettyServerConfig));
     }
 }