Search in sources :

Example 6 with IdleStateHandler

use of io.netty.handler.timeout.IdleStateHandler in project iris by chicc999.

the class NettyTransport method handler.

protected ChannelHandler handler() {
    return new ChannelInitializer() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(config.getFrameMaxSize(), 0, 4, 0, 4));
            ch.pipeline().addLast(new CommandDecoder());
            ch.pipeline().addLast(new CommandEncoder());
            ch.pipeline().addLast(new IdleStateHandler(0, 0, config.getChannelMaxIdleTime(), TimeUnit.MILLISECONDS));
            ch.pipeline().addLast(dispatcherHandler);
            ch.pipeline().addLast(connectionHandler);
        }
    };
}
Also used : CommandDecoder(pers.cy.iris.commons.network.protocol.CommandDecoder) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) CommandEncoder(pers.cy.iris.commons.network.protocol.CommandEncoder) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder)

Example 7 with IdleStateHandler

use of io.netty.handler.timeout.IdleStateHandler in project hbase by apache.

the class NettyRpcConnection method established.

private void established(Channel ch) throws IOException {
    ChannelPipeline p = ch.pipeline();
    String addBeforeHandler = p.context(BufferCallBeforeInitHandler.class).name();
    p.addBefore(addBeforeHandler, null, new IdleStateHandler(0, rpcClient.minIdleTimeBeforeClose, 0, TimeUnit.MILLISECONDS));
    p.addBefore(addBeforeHandler, null, new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
    p.addBefore(addBeforeHandler, null, new NettyRpcDuplexHandler(this, rpcClient.cellBlockBuilder, codec, compressor));
    p.fireUserEventTriggered(BufferCallEvent.success());
}
Also used : IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 8 with IdleStateHandler

use of io.netty.handler.timeout.IdleStateHandler in project apn-proxy by apn-proxy.

the class ApnProxyRemoteForwardChannelInitializer method initChannel.

@Override
public void initChannel(SocketChannel channel) throws Exception {
    ApnProxyRemote apnProxyRemote = uaChannel.attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY).get().getRemote();
    channel.attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY).set(uaChannel.attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY).get());
    ChannelPipeline pipeline = channel.pipeline();
    pipeline.addLast("idlestate", new IdleStateHandler(0, 0, 3, TimeUnit.MINUTES));
    pipeline.addLast("idlehandler", new ApnProxyIdleHandler());
    if (apnProxyRemote.getRemoteListenType() == ApnProxyListenType.SSL) {
        SSLEngine engine = ApnProxySSLContextFactory.createClientSSLEnginForRemoteAddress(apnProxyRemote.getRemoteHost(), apnProxyRemote.getRemotePort());
        engine.setUseClientMode(true);
        pipeline.addLast("ssl", new SslHandler(engine));
    } else if (apnProxyRemote.getRemoteListenType() == ApnProxyListenType.AES) {
        byte[] key = ((ApnProxyAESRemote) apnProxyRemote).getKey();
        byte[] iv = ((ApnProxyAESRemote) apnProxyRemote).getIv();
        pipeline.addLast("apnproxy.encrypt", new ApnProxyAESEncoder(key, iv));
        pipeline.addLast("apnproxy.decrypt", new ApnProxyAESDecoder(key, iv));
    }
    pipeline.addLast("codec", new HttpClientCodec());
    pipeline.addLast(ApnProxyRemoteForwardHandler.HANDLER_NAME, new ApnProxyRemoteForwardHandler(uaChannel, remoteChannelInactiveCallback));
}
Also used : SSLEngine(javax.net.ssl.SSLEngine) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) ApnProxyRemote(com.xx_dev.apn.proxy.remotechooser.ApnProxyRemote) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler)

Example 9 with IdleStateHandler

use of io.netty.handler.timeout.IdleStateHandler in project vert.x by eclipse.

the class NetServerImpl method initChannel.

@Override
protected void initChannel(ChannelPipeline pipeline) {
    if (sslHelper.isSSL()) {
        SslHandler sslHandler = sslHelper.createSslHandler(vertx);
        pipeline.addLast("ssl", sslHandler);
    }
    if (logEnabled) {
        pipeline.addLast("logging", new LoggingHandler());
    }
    if (sslHelper.isSSL()) {
        // only add ChunkedWriteHandler when SSL is enabled otherwise it is not needed as FileRegion is used.
        // For large file / sendfile support
        pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    }
    if (options.getIdleTimeout() > 0) {
        pipeline.addLast("idle", new IdleStateHandler(0, 0, options.getIdleTimeout()));
    }
}
Also used : LoggingHandler(io.netty.handler.logging.LoggingHandler) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) SslHandler(io.netty.handler.ssl.SslHandler)

Example 10 with IdleStateHandler

use of io.netty.handler.timeout.IdleStateHandler in project Glowstone by GlowstoneMC.

the class GlowChannelInitializer method initChannel.

@Override
protected void initChannel(SocketChannel c) {
    MessageHandler handler = new MessageHandler(connectionManager);
    CodecsHandler codecs = new CodecsHandler(ProtocolType.HANDSHAKE.getProtocol());
    FramingHandler framing = new FramingHandler();
    try {
        c.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException e) {
        // Not supported on all OSs, like Windows XP and lesser
        GlowServer.logger.warning("Your OS does not support type of service.");
    }
    c.config().setAllocator(PooledByteBufAllocator.DEFAULT);
    c.pipeline().addLast("idle_timeout", new IdleStateHandler(READ_IDLE_TIMEOUT, WRITE_IDLE_TIMEOUT, 0)).addLast("legacy_ping", new LegacyPingHandler(connectionManager)).addLast("encryption", NoopHandler.INSTANCE).addLast("framing", framing).addLast("compression", NoopHandler.INSTANCE).addLast("codecs", codecs).addLast("handler", handler);
}
Also used : LegacyPingHandler(net.glowstone.net.handler.legacyping.LegacyPingHandler) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) ChannelException(io.netty.channel.ChannelException)

Aggregations

IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)10 ChannelPipeline (io.netty.channel.ChannelPipeline)5 SslHandler (io.netty.handler.ssl.SslHandler)5 LoggingHandler (io.netty.handler.logging.LoggingHandler)4 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)3 SSLEngine (javax.net.ssl.SSLEngine)3 ApnProxyRemote (com.xx_dev.apn.proxy.remotechooser.ApnProxyRemote)2 Channel (io.netty.channel.Channel)2 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelException (io.netty.channel.ChannelException)1 ChannelOption (io.netty.channel.ChannelOption)1 FixedRecvByteBufAllocator (io.netty.channel.FixedRecvByteBufAllocator)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)1 HttpContentDecompressor (io.netty.handler.codec.http.HttpContentDecompressor)1 HttpRequestDecoder (io.netty.handler.codec.http.HttpRequestDecoder)1 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)1 ProtobufDecoder (io.netty.handler.codec.protobuf.ProtobufDecoder)1