public override void startup() { base.startup(); if (addressParser == null) { addressParser = new RpcAddressParser(); } ConnectionSelectStrategy connectionSelectStrategy = (ConnectionSelectStrategy)option(BoltGenericOption.CONNECTION_SELECT_STRATEGY); if (connectionSelectStrategy == null) { connectionSelectStrategy = new RandomSelectStrategy(switches()); } connectionManager = new DefaultClientConnectionManager(connectionSelectStrategy, new RpcConnectionFactory(userProcessors, this), connectionEventHandler, connectionEventListener, switches()); connectionManager.AddressParser = addressParser; connectionManager.startup(); rpcRemoting = new RpcClientRemoting(new RpcCommandFactory(), addressParser, connectionManager); taskScanner.add(connectionManager); taskScanner.startup(); if (switches().isOn(GlobalSwitch.CONN_MONITOR_SWITCH)) { if (monitorStrategy == null) { connectionMonitor = new DefaultConnectionMonitor(new ScheduledDisconnectStrategy(), connectionManager); } else { connectionMonitor = new DefaultConnectionMonitor(monitorStrategy, connectionManager); } connectionMonitor.startup(); logger.LogWarning("Switch on connection monitor"); } if (switches().isOn(GlobalSwitch.CONN_RECONNECT_SWITCH)) { reconnectManager = new ReconnectManager(connectionManager); reconnectManager.startup(); connectionEventHandler.Reconnector = reconnectManager; logger.LogWarning("Switch on reconnect manager"); } }
protected internal override void doInit() { if (addressParser == null) { addressParser = new RpcAddressParser(); } if (switches().isOn(GlobalSwitch.SERVER_MANAGE_CONNECTION_SWITCH)) { // in server side, do not care the connection service state, so use null instead of global switch ConnectionSelectStrategy connectionSelectStrategy = new RandomSelectStrategy(null); connectionManager = new DefaultServerConnectionManager(connectionSelectStrategy); connectionManager.startup(); connectionEventHandler = new RpcConnectionEventHandler(switches()); connectionEventHandler.ConnectionManager = connectionManager; connectionEventHandler.ConnectionEventListener = connectionEventListener; } else { connectionEventHandler = new ConnectionEventHandler(switches()); connectionEventHandler.ConnectionEventListener = connectionEventListener; } initRpcRemoting(); bootstrap = new ServerBootstrap(); if (IsUseLibuv) { bootstrap.Channel <TcpServerChannel>(); } else { bootstrap.Channel <TcpServerSocketChannel>(); } bootstrap.Group(bossGroup, workerGroup) .Option(ChannelOption.SoBacklog, ConfigManager.tcp_so_backlog()) .Option(ChannelOption.SoReuseaddr, ConfigManager.tcp_so_reuseaddr()) .ChildOption(ChannelOption.TcpNodelay, ConfigManager.tcp_nodelay()) .ChildOption(ChannelOption.SoKeepalive, ConfigManager.tcp_so_keepalive()); // set write buffer water mark initWriteBufferWaterMark(); // init byte buf allocator if (ConfigManager.netty_buffer_pooled()) { bootstrap .Option(ChannelOption.Allocator, PooledByteBufferAllocator.Default) .ChildOption(ChannelOption.Allocator, PooledByteBufferAllocator.Default); } else { bootstrap .Option(ChannelOption.Allocator, UnpooledByteBufferAllocator.Default) .ChildOption(ChannelOption.Allocator, PooledByteBufferAllocator.Default); } // enable trigger mode for epoll if need NettyEventLoopUtil.enableTriggeredMode(bootstrap); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final boolean idleSwitch = config.ConfigManager.tcp_idle_switch(); bool idleSwitch = ConfigManager.tcp_idle_switch(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int idleTime = config.ConfigManager.tcp_server_idle(); int idleTime = ConfigManager.tcp_server_idle(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final io.netty.channel.ChannelHandler serverIdleHandler = new ServerIdleHandler(); IChannelHandler serverIdleHandler = new ServerIdleHandler(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final RpcHandler rpcHandler = new RpcHandler(true, this.userProcessors); RpcHandler rpcHandler = new RpcHandler(true, userProcessors); bootstrap.ChildHandler(new ActionChannelInitializer <ISocketChannel>(channel => { IChannelPipeline pipeline = channel.Pipeline; pipeline.AddLast("decoder", codec.newDecoder()); pipeline.AddLast("encoder", codec.newEncoder()); if (idleSwitch) { pipeline.AddLast("idleStateHandler", new IdleStateHandler(TimeSpan.FromMilliseconds(0), TimeSpan.FromMilliseconds(0), TimeSpan.FromMilliseconds(idleTime))); pipeline.AddLast("serverIdleHandler", serverIdleHandler); } pipeline.AddLast("connectionEventHandler", connectionEventHandler); pipeline.AddLast("handler", rpcHandler); Url url = addressParser.parse(((IPEndPoint)channel?.RemoteAddress)?.ToString()); if (switches().isOn(GlobalSwitch.SERVER_MANAGE_CONNECTION_SWITCH)) { connectionManager.add(new Connection(channel, url), url.UniqueKey); } else { new Connection(channel, url); } channel.Pipeline.FireUserEventTriggered(ConnectionEventType.CONNECT); })); }