use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project uploader by smoketurner.
the class UploadInitializer method initChannel.
@Override
public void initChannel(final SocketChannel ch) throws Exception {
final ChannelPipeline p = ch.pipeline();
// add the IP ACL filter first
if (ipFilter != null) {
p.addLast("acl", ipFilter);
}
if (sslCtx != null) {
if (configuration.isClientAuth()) {
final SSLEngine engine = sslCtx.newEngine(ch.alloc());
engine.setUseClientMode(false);
engine.setNeedClientAuth(true);
p.addLast("ssl", new SslHandler(engine));
} else {
p.addLast("ssl", sslCtx.newHandler(ch.alloc()));
}
}
// removes idle connections after READER_IDLE_SECONDS seconds
p.addLast("idleStateHandler", new IdleStateHandler(READER_IDLE_SECONDS, 0, 0));
// authenticate via an ACL and mutual certificates
p.addLast("auth", new AuthHandler(configuration.isClientAuth()));
// check to see if the data stream is gzipped or not
// p.addLast("gzipDetector", new OptionalGzipHandler());
// break each data chunk by newlines
p.addLast("line", new LineBasedFrameDecoder(Ints.checkedCast(maxLength), true, true));
// convert each data chunk into a byte array
p.addLast("decoder", new ByteArrayDecoder());
// batch and compress chunks of data up to maxUploadBytes
p.addLast("batcher", new BatchHandler(maxUploadBytes));
// upload the batch to S3
p.addLast("uploader", uploadHandler);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project rocketmq by apache.
the class NettyRemotingClient method start.
@Override
public void start() {
this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(nettyClientConfig.getClientWorkerThreads(), new ThreadFactory() {
private AtomicInteger threadIndex = new AtomicInteger(0);
@Override
public Thread newThread(Runnable r) {
return new Thread(r, "NettyClientWorkerThread_" + this.threadIndex.incrementAndGet());
}
});
Bootstrap handler = this.bootstrap.group(this.eventLoopGroupWorker).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_KEEPALIVE, false).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, nettyClientConfig.getConnectTimeoutMillis()).option(ChannelOption.SO_SNDBUF, nettyClientConfig.getClientSocketSndBufSize()).option(ChannelOption.SO_RCVBUF, nettyClientConfig.getClientSocketRcvBufSize()).handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
if (nettyClientConfig.isUseTLS()) {
if (null != sslContext) {
pipeline.addFirst(defaultEventExecutorGroup, "sslHandler", sslContext.newHandler(ch.alloc()));
log.info("Prepend SSL handler");
} else {
log.warn("Connections are insecure as SSLContext is null!");
}
}
pipeline.addLast(defaultEventExecutorGroup, new NettyEncoder(), new NettyDecoder(), new IdleStateHandler(0, 0, nettyClientConfig.getClientChannelMaxIdleTimeSeconds()), new NettyConnectManageHandler(), new NettyClientHandler());
}
});
this.timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
NettyRemotingClient.this.scanResponseTable();
} catch (Throwable e) {
log.error("scanResponseTable exception", e);
}
}
}, 1000 * 3, 1000);
if (this.channelEventListener != null) {
this.nettyEventExecutor.start();
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project rocketmq by apache.
the class NettyRemotingServer method start.
@Override
public void start() {
this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(nettyServerConfig.getServerWorkerThreads(), new ThreadFactory() {
private AtomicInteger threadIndex = new AtomicInteger(0);
@Override
public Thread newThread(Runnable r) {
return new Thread(r, "NettyServerCodecThread_" + this.threadIndex.incrementAndGet());
}
});
ServerBootstrap childHandler = this.serverBootstrap.group(this.eventLoopGroupBoss, this.eventLoopGroupSelector).channel(useEpoll() ? EpollServerSocketChannel.class : NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 1024).option(ChannelOption.SO_REUSEADDR, true).option(ChannelOption.SO_KEEPALIVE, false).childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_SNDBUF, nettyServerConfig.getServerSocketSndBufSize()).childOption(ChannelOption.SO_RCVBUF, nettyServerConfig.getServerSocketRcvBufSize()).localAddress(new InetSocketAddress(this.nettyServerConfig.getListenPort())).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(defaultEventExecutorGroup, HANDSHAKE_HANDLER_NAME, new HandshakeHandler(TlsSystemConfig.tlsMode)).addLast(defaultEventExecutorGroup, new NettyEncoder(), new NettyDecoder(), new IdleStateHandler(0, 0, nettyServerConfig.getServerChannelMaxIdleTimeSeconds()), new NettyConnectManageHandler(), new NettyServerHandler());
}
});
if (nettyServerConfig.isServerPooledByteBufAllocatorEnable()) {
childHandler.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
}
try {
ChannelFuture sync = this.serverBootstrap.bind().sync();
InetSocketAddress addr = (InetSocketAddress) sync.channel().localAddress();
this.port = addr.getPort();
} catch (InterruptedException e1) {
throw new RuntimeException("this.serverBootstrap.bind().sync() InterruptedException", e1);
}
if (this.channelEventListener != null) {
this.nettyEventExecutor.start();
}
this.timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
NettyRemotingServer.this.scanResponseTable();
} catch (Throwable e) {
log.error("scanResponseTable exception", e);
}
}
}, 1000 * 3, 1000);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project jim-framework by jiangmin168168.
the class RpcClientInitializer method initChannel.
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline cp = socketChannel.pipeline();
cp.addLast(new RpcEncoder(RpcRequest.class));
cp.addLast(new RpcDecoder(RpcResponse.class));
cp.addLast(new IdleStateHandler(0, 0, Constants.ALLIDLE_TIME_SECONDS));
cp.addLast(new ClientHeartbeatHandler());
cp.addLast(new RpcClientInvoker(this.getFilterMap()));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project cassandra by apache.
the class PipelineConfigurator method configureInitialPipeline.
public void configureInitialPipeline(Channel channel, Connection.Factory connectionFactory) {
ChannelPipeline pipeline = channel.pipeline();
// Add the ConnectionLimitHandler to the pipeline if configured to do so.
if (DatabaseDescriptor.getNativeTransportMaxConcurrentConnections() > 0 || DatabaseDescriptor.getNativeTransportMaxConcurrentConnectionsPerIp() > 0) {
// Add as first to the pipeline so the limit is enforced as first action.
pipeline.addFirst(CONNECTION_LIMIT_HANDLER, connectionLimitHandler);
}
long idleTimeout = DatabaseDescriptor.nativeTransportIdleTimeout();
if (idleTimeout > 0) {
pipeline.addLast(IDLE_STATE_HANDLER, new IdleStateHandler(false, 0, 0, idleTimeout, TimeUnit.MILLISECONDS) {
@Override
protected void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) {
logger.info("Closing client connection {} after timeout of {}ms", channel.remoteAddress(), idleTimeout);
ctx.close();
}
});
}
if (DEBUG)
pipeline.addLast(DEBUG_HANDLER, new LoggingHandler(LogLevel.INFO));
pipeline.addLast(ENVELOPE_ENCODER, Envelope.Encoder.instance);
pipeline.addLast(INITIAL_HANDLER, new InitialConnectionHandler(new Envelope.Decoder(), connectionFactory, this));
// The exceptionHandler will take care of handling exceptionCaught(...) events while still running
// on the same EventLoop as all previous added handlers in the pipeline. This is important as the used
// eventExecutorGroup may not enforce strict ordering for channel events.
// As the exceptionHandler runs in the EventLoop as the previous handlers we are sure all exceptions are
// correctly handled before the handler itself is removed.
// See https://issues.apache.org/jira/browse/CASSANDRA-13649
pipeline.addLast(EXCEPTION_HANDLER, PreV5Handlers.ExceptionHandler.instance);
onInitialPipelineReady(pipeline);
}
Aggregations