use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateEvent in project cdap by caskdata.
the class OutboundHandler method userEventTriggered.
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (!(evt instanceof IdleStateEvent)) {
ctx.fireUserEventTriggered(evt);
return;
}
if (IdleState.ALL_IDLE == ((IdleStateEvent) evt).state()) {
if (requestInProgress) {
LOG.trace("Request is in progress, so not closing channel.");
} else {
// No data has been sent or received for a while. Close channel.
Channel channel = ctx.channel();
channel.close();
LOG.trace("No data has been sent or received for channel '{}' for more than the configured idle timeout. " + "Closing the channel. Local Address: {}, Remote Address: {}", channel, channel.localAddress(), channel.remoteAddress());
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateEvent in project java by wavefrontHQ.
the class Ingester method addIdleTimeoutHandler.
/**
* Adds an idle timeout handler to the given pipeline
*
* @param pipeline the pipeline to add the idle timeout handler
*/
protected void addIdleTimeoutHandler(final ChannelPipeline pipeline) {
// Shared across all reports for proper batching
pipeline.addLast("idleStateHandler", new IdleStateHandler(CHANNEL_IDLE_TIMEOUT_IN_SECS_DEFAULT, 0, 0));
pipeline.addLast("idleChannelTerminator", new ChannelDuplexHandler() {
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
if (((IdleStateEvent) evt).state() == IdleState.READER_IDLE) {
logger.warning("terminating connection to graphite client due to inactivity after " + CHANNEL_IDLE_TIMEOUT_IN_SECS_DEFAULT + "s: " + ctx.channel());
ctx.close();
}
}
}
});
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateEvent in project java by wavefrontHQ.
the class HistogramLineIngester method initChannel.
@Override
protected void initChannel(Channel ch) throws Exception {
// Round robin channel to handler assignment.
int idx = (int) (Math.abs(connectionId.getAndIncrement()) % handlers.size());
ChannelHandler handler = handlers.get(idx);
// Add decoders and timeout, add handler()
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new LineBasedFrameDecoder(MAXIMUM_FRAME_LENGTH, true, false), new StringDecoder(Charsets.UTF_8), new IdleStateHandler(CHANNEL_IDLE_TIMEOUT_IN_SECS_DEFAULT, 0, 0), new ChannelDuplexHandler() {
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
if (((IdleStateEvent) evt).state() == IdleState.READER_IDLE) {
logger.warning("terminating connection to histogram client due to inactivity after " + CHANNEL_IDLE_TIMEOUT_IN_SECS_DEFAULT + "s: " + ctx.channel());
ctx.close();
}
}
}
}, handler);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateEvent in project web3sdk by FISCO-BCOS.
the class ChannelHandler method userEventTriggered.
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
String host = ((SocketChannel) ctx.channel()).remoteAddress().getAddress().getHostAddress();
Integer port = ((SocketChannel) ctx.channel()).remoteAddress().getPort();
if (evt instanceof IdleStateEvent) {
IdleStateEvent e = (IdleStateEvent) evt;
switch(e.state()) {
case READER_IDLE:
case WRITER_IDLE:
case ALL_IDLE:
logger.error("事件:{} 连接{}:{} 长时间没有活动,断连", e.state(), host, port);
channelInactive(ctx);
ctx.disconnect();
ctx.close();
break;
default:
break;
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateEvent in project web3sdk by FISCO-BCOS.
the class ChannelHandler method userEventTriggered.
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
String host = ((SocketChannel) ctx.channel()).remoteAddress().getAddress().getHostAddress();
Integer port = ((SocketChannel) ctx.channel()).remoteAddress().getPort();
if (evt instanceof IdleStateEvent) {
IdleStateEvent e = (IdleStateEvent) evt;
switch(e.state()) {
case READER_IDLE:
case WRITER_IDLE:
case ALL_IDLE:
logger.error(" idle state event:{} connect{}:{} long time Inactive,disconnect", e.state(), host, port);
channelInactive(ctx);
ctx.disconnect();
ctx.close();
break;
default:
break;
}
} else if (evt instanceof SslHandshakeCompletionEvent) {
SslHandshakeCompletionEvent e = (SslHandshakeCompletionEvent) evt;
if (e.isSuccess()) {
logger.info(" handshake success, host: {}, port: {}, ctx: {}", host, port, System.identityHashCode(ctx));
ChannelHandlerContext oldCtx = connections.setAndGetNetworkConnectionByHost(host, port, ctx);
connections.getCallback().onConnect(ctx);
if (Objects.nonNull(oldCtx)) {
oldCtx.close();
oldCtx.disconnect();
logger.warn(" disconnect old connection, host: {}, port: {}, ctx: {}", host, port, System.identityHashCode(ctx));
}
} else {
logger.error(" handshake failed, host: {}, port: {}, message: {}, cause: {} ", host, port, e.cause().getMessage(), e.cause());
ctx.disconnect();
ctx.close();
}
} else if (evt instanceof SslCloseCompletionEvent) {
logger.info(" ssl close completion event, host: {}, port: {}, ctx: {} ", host, port, System.identityHashCode(ctx));
} else {
logger.info(" userEventTriggered event, host: {}, port: {}, evt: {}, ctx: {} ", host, port, evt, System.identityHashCode(ctx));
}
}
Aggregations