Search in sources :

Example 61 with IdleStateHandler

use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project dubbo by alibaba.

the class NettyClient method initBootstrap.

protected void initBootstrap(NettyClientHandler nettyClientHandler) {
    bootstrap.group(EVENT_LOOP_GROUP).option(ChannelOption.SO_KEEPALIVE, true).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT).channel(socketChannelClass());
    bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, Math.max(DEFAULT_CONNECT_TIMEOUT, getConnectTimeout()));
    bootstrap.handler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            int heartbeatInterval = UrlUtils.getHeartbeat(getUrl());
            if (getUrl().getParameter(SSL_ENABLED_KEY, false)) {
                ch.pipeline().addLast("negotiation", SslHandlerInitializer.sslClientHandler(getUrl(), nettyClientHandler));
            }
            NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyClient.this);
            // .addLast("logging",new LoggingHandler(LogLevel.INFO))//for debug
            ch.pipeline().addLast("decoder", adapter.getDecoder()).addLast("encoder", adapter.getEncoder()).addLast("client-idle-handler", new IdleStateHandler(heartbeatInterval, 0, 0, MILLISECONDS)).addLast("handler", nettyClientHandler);
            String socksProxyHost = ConfigUtils.getProperty(SOCKS_PROXY_HOST);
            if (socksProxyHost != null) {
                int socksProxyPort = Integer.parseInt(ConfigUtils.getProperty(SOCKS_PROXY_PORT, DEFAULT_SOCKS_PROXY_PORT));
                Socks5ProxyHandler socks5ProxyHandler = new Socks5ProxyHandler(new InetSocketAddress(socksProxyHost, socksProxyPort));
                ch.pipeline().addFirst(socks5ProxyHandler);
            }
        }
    });
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) InetSocketAddress(java.net.InetSocketAddress) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) RemotingException(org.apache.dubbo.remoting.RemotingException) Socks5ProxyHandler(io.netty.handler.proxy.Socks5ProxyHandler)

Aggregations

IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)61 ChannelPipeline (io.netty.channel.ChannelPipeline)29 SocketChannel (io.netty.channel.socket.SocketChannel)16 LoggingHandler (io.netty.handler.logging.LoggingHandler)15 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)12 SslHandler (io.netty.handler.ssl.SslHandler)11 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)11 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)10 EventLoopGroup (io.netty.channel.EventLoopGroup)8 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)8 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)8 Bootstrap (io.netty.bootstrap.Bootstrap)7 ChannelFuture (io.netty.channel.ChannelFuture)7 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)6 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)6 InetSocketAddress (java.net.InetSocketAddress)6 StringDecoder (io.netty.handler.codec.string.StringDecoder)5 IdleStateEvent (io.netty.handler.timeout.IdleStateEvent)5 DefaultEventExecutorGroup (io.netty.util.concurrent.DefaultEventExecutorGroup)5 ThreadFactory (java.util.concurrent.ThreadFactory)5