use of io.netty.handler.timeout.IdleStateEvent in project zuul by Netflix.
the class OriginResponseReceiver method userEventTriggered.
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof CompleteEvent) {
final CompleteReason reason = ((CompleteEvent) evt).getReason();
if ((reason != SESSION_COMPLETE) && (edgeProxy != null)) {
LOG.error("Origin request completed with reason other than COMPLETE: {}, {}", reason.name(), ChannelUtils.channelInfoForLogging(ctx.channel()));
final ZuulException ze = new ZuulException("CompleteEvent", reason.name(), true);
edgeProxy.errorFromOrigin(ze);
}
// See channelWrite() where these vars are first set onto the channel.
try {
super.userEventTriggered(ctx, evt);
} finally {
postCompleteHook(ctx, evt);
}
} else if (evt instanceof SslHandshakeCompletionEvent && !((SslHandshakeCompletionEvent) evt).isSuccess()) {
Throwable cause = ((SslHandshakeCompletionEvent) evt).cause();
ctx.channel().attr(SSL_HANDSHAKE_UNSUCCESS_FROM_ORIGIN_THROWABLE).set(cause);
} else if (evt instanceof IdleStateEvent) {
if (edgeProxy != null) {
LOG.error("Origin request received IDLE event: {}", ChannelUtils.channelInfoForLogging(ctx.channel()));
edgeProxy.errorFromOrigin(new OutboundException(READ_TIMEOUT, edgeProxy.getRequestAttempts()));
}
super.userEventTriggered(ctx, evt);
} else {
super.userEventTriggered(ctx, evt);
}
}
use of io.netty.handler.timeout.IdleStateEvent in project dubbo by alibaba.
the class TelnetIdleEventHandler method userEventTriggered.
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
// server will close channel when server don't receive any request from client util timeout.
if (evt instanceof IdleStateEvent) {
Channel channel = ctx.channel();
log.info("IdleStateEvent triggered, close channel " + channel);
channel.close();
} else {
super.userEventTriggered(ctx, evt);
}
}
use of io.netty.handler.timeout.IdleStateEvent in project dubbo by alibaba.
the class NettyClientHandler method userEventTriggered.
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
// send heartbeat when read idle.
if (evt instanceof IdleStateEvent) {
try {
NettyChannel channel = NettyChannel.getOrAddChannel(ctx.channel(), url, handler);
if (logger.isDebugEnabled()) {
logger.debug("IdleStateEvent triggered, send heartbeat to channel " + channel);
}
Request req = new Request();
req.setVersion(Version.getProtocolVersion());
req.setTwoWay(true);
req.setEvent(HEARTBEAT_EVENT);
channel.send(req);
} finally {
NettyChannel.removeChannelIfDisconnected(ctx.channel());
}
} else {
super.userEventTriggered(ctx, evt);
}
}
use of io.netty.handler.timeout.IdleStateEvent in project rocketmq-externals by apache.
the class MqttConnectionHandlerTest method testHandleIdleStateEvent.
@Test
public void testHandleIdleStateEvent() throws Exception {
IdleStateEvent idleStateEvent = IdleStateEvent.ALL_IDLE_STATE_EVENT;
handler.userEventTriggered(ctx, idleStateEvent);
Mockito.verify(clientManager, Mockito.times(1)).remove(channel);
Mockito.verify(channel, Mockito.times(1)).close();
}
use of io.netty.handler.timeout.IdleStateEvent in project BRFS by zhangnianli.
the class AsyncTcpClientGroup method createClient.
@Override
public TcpClient<BaseMessage, BaseResponse> createClient(TcpClientConfig config, Executor executor) throws InterruptedException {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group);
bootstrap.channel(NioSocketChannel.class);
bootstrap.option(ChannelOption.TCP_NODELAY, true);
bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator());
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.connectTimeoutMillis());
if (executor == null) {
executor = new Executor() {
@Override
public void execute(Runnable command) {
command.run();
}
};
}
AsyncTcpClient client = new AsyncTcpClient(executor);
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new IdleStateHandler(0, DEFAULT_WRITE_IDLE_TIMEOUT_SECONDS, 0)).addLast(new BaseMessageEncoder()).addLast(new BaseResponseDecoder()).addLast(new SimpleChannelInboundHandler<TokenMessage<BaseResponse>>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, TokenMessage<BaseResponse> msg) throws Exception {
client.handle(msg.messageToken(), msg.message());
}
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent e = (IdleStateEvent) evt;
if (e.state() == IdleState.WRITER_IDLE) {
ctx.writeAndFlush(new BaseMessage(-1));
}
}
}
});
}
});
ChannelFuture future = bootstrap.connect(config.remoteAddress()).sync();
if (!future.isSuccess()) {
return null;
}
Channel channel = future.channel();
channelList.add(channel);
channel.closeFuture().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
channelList.remove(channel);
}
});
LOG.info("create tcp client for {}", config.remoteAddress());
client.attach(channel);
return client;
}
Aggregations