Search in sources :

Example 6 with IdleStateEvent

use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateEvent in project xian by happyyangyuan.

the class IdleEventListener method userEventTriggered.

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent event = (IdleStateEvent) evt;
        LOG.info(ctx.channel().remoteAddress() + "超时类型:" + event.state().name());
        if (event.state() == IdleState.WRITER_IDLE) {
            List<Request> timeoutRequests = ctx.channel().attr(ReqQueue.REQ_QUEUE).get().removeTimeout();
            for (Request timeoutRequest : timeoutRequests) {
                timeoutRequest.getChannelHandlerContext().writeAndFlush(buildTimeoutResponse(timeoutRequest));
            }
        }
    } else {
        super.userEventTriggered(ctx, evt);
    }
}
Also used : IdleStateEvent(io.netty.handler.timeout.IdleStateEvent) Request(info.xiancloud.nettyhttpserver.http.bean.Request)

Example 7 with IdleStateEvent

use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateEvent in project iris by chicc999.

the class DefaultConnectionHandler method userEventTriggered.

@Override
public void userEventTriggered(final ChannelHandlerContext ctx, final Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent event = (IdleStateEvent) evt;
        if (event.state().equals(IdleState.ALL_IDLE)) {
            logger.debug("channel {} is idle.", ctx.channel());
            ctx.writeAndFlush(new HeartBeat()).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
        }
    }
    super.userEventTriggered(ctx, evt);
}
Also used : IdleStateEvent(io.netty.handler.timeout.IdleStateEvent) HeartBeat(pers.cy.iris.commons.network.protocol.request.HeartBeat)

Example 8 with IdleStateEvent

use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateEvent in project netty by netty.

the class UptimeClientHandler method userEventTriggered.

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
    if (!(evt instanceof IdleStateEvent)) {
        return;
    }
    IdleStateEvent e = (IdleStateEvent) evt;
    if (e.state() == IdleState.READER_IDLE) {
        // The connection was OK but there was no traffic for last period.
        println("Disconnecting due to no inbound traffic");
        ctx.close();
    }
}
Also used : IdleStateEvent(io.netty.handler.timeout.IdleStateEvent)

Example 9 with IdleStateEvent

use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateEvent in project netty by netty.

the class MqttHeartBeatClientHandler method userEventTriggered.

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        MqttFixedHeader pingreqFixedHeader = new MqttFixedHeader(MqttMessageType.PINGREQ, false, MqttQoS.AT_MOST_ONCE, false, 0);
        MqttMessage pingreqMessage = new MqttMessage(pingreqFixedHeader);
        ctx.writeAndFlush(pingreqMessage);
        System.out.println("Sent PINGREQ");
    } else {
        super.userEventTriggered(ctx, evt);
    }
}
Also used : IdleStateEvent(io.netty.handler.timeout.IdleStateEvent) MqttMessage(io.netty.handler.codec.mqtt.MqttMessage) MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader)

Example 10 with IdleStateEvent

use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateEvent in project netty by netty.

the class FlowControlHandlerTest method testSwallowedReadComplete.

@Test
public void testSwallowedReadComplete() throws Exception {
    final long delayMillis = 100;
    final Queue<IdleStateEvent> userEvents = new LinkedBlockingQueue<IdleStateEvent>();
    final EmbeddedChannel channel = new EmbeddedChannel(false, false, new FlowControlHandler(), new IdleStateHandler(delayMillis, 0, 0, MILLISECONDS), new ChannelInboundHandlerAdapter() {

        @Override
        public void channelActive(ChannelHandlerContext ctx) {
            ctx.fireChannelActive();
            ctx.read();
        }

        @Override
        public void channelRead(ChannelHandlerContext ctx, Object msg) {
            ctx.fireChannelRead(msg);
            ctx.read();
        }

        @Override
        public void channelReadComplete(ChannelHandlerContext ctx) {
            ctx.fireChannelReadComplete();
            ctx.read();
        }

        @Override
        public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
            if (evt instanceof IdleStateEvent) {
                userEvents.add((IdleStateEvent) evt);
            }
            ctx.fireUserEventTriggered(evt);
        }
    });
    channel.config().setAutoRead(false);
    assertFalse(channel.config().isAutoRead());
    channel.register();
    // Reset read timeout by some message
    assertTrue(channel.writeInbound(Unpooled.EMPTY_BUFFER));
    channel.flushInbound();
    assertEquals(Unpooled.EMPTY_BUFFER, channel.readInbound());
    // Emulate 'no more messages in NIO channel' on the next read attempt.
    channel.flushInbound();
    assertNull(channel.readInbound());
    Thread.sleep(delayMillis + 20L);
    channel.runPendingTasks();
    assertEquals(IdleStateEvent.FIRST_READER_IDLE_STATE_EVENT, userEvents.poll());
    assertFalse(channel.finish());
}
Also used : IdleStateEvent(io.netty.handler.timeout.IdleStateEvent) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Test(org.junit.jupiter.api.Test)

Aggregations

IdleStateEvent (io.netty.handler.timeout.IdleStateEvent)30 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)7 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)6 ChannelDuplexHandler (io.netty.channel.ChannelDuplexHandler)4 Channel (io.netty.channel.Channel)3 SocketChannel (io.netty.channel.socket.SocketChannel)3 SslHandshakeCompletionEvent (io.netty.handler.ssl.SslHandshakeCompletionEvent)3 CompleteEvent (com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent)2 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelFutureListener (io.netty.channel.ChannelFutureListener)2 ChannelPipeline (io.netty.channel.ChannelPipeline)2 SslHandler (io.netty.handler.ssl.SslHandler)2 InetSocketAddress (java.net.InetSocketAddress)2 JSONObject (com.alibaba.fastjson.JSONObject)1 BaseMessage (com.bonree.brfs.common.net.tcp.BaseMessage)1 BaseResponse (com.bonree.brfs.common.net.tcp.BaseResponse)1 TokenMessage (com.bonree.brfs.common.net.tcp.TokenMessage)1 CompleteReason (com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteReason)1 HttpRequestReadTimeoutEvent (com.netflix.netty.common.HttpRequestReadTimeoutEvent)1 OutboundException (com.netflix.zuul.exception.OutboundException)1