當前位置: 首頁>>代碼示例>>Java>>正文


Java IdleState類代碼示例

本文整理匯總了Java中io.netty.handler.timeout.IdleState的典型用法代碼示例。如果您正苦於以下問題:Java IdleState類的具體用法?Java IdleState怎麽用?Java IdleState使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IdleState類屬於io.netty.handler.timeout包,在下文中一共展示了IdleState類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: userEventTriggered

import io.netty.handler.timeout.IdleState; //導入依賴的package包/類
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    //心跳配置
    if (IdleStateEvent.class.isAssignableFrom(evt.getClass())) {
        IdleStateEvent event = (IdleStateEvent) evt;
        if (event.state() == IdleState.READER_IDLE) {
            SpringBeanUtils.getInstance().getBean(NettyClientService.class).doConnect();
        } else if (event.state() == IdleState.WRITER_IDLE) {
            //表示已經多久沒有發送數據了
            HEART_BEAT.setAction(NettyMessageActionEnum.HEART.getCode());
            ctx.writeAndFlush(HEART_BEAT);
            LogUtil.debug(LOGGER, () -> "向服務端發送的心跳");
        } else if (event.state() == IdleState.ALL_IDLE) {
            //表示已經多久既沒有收到也沒有發送數據了
            SpringBeanUtils.getInstance().getBean(NettyClientService.class).doConnect();
        }
    }
}
 
開發者ID:yu199195,項目名稱:happylifeplat-transaction,代碼行數:19,代碼來源:NettyClientMessageHandler.java

示例2: userEventTriggered

import io.netty.handler.timeout.IdleState; //導入依賴的package包/類
/**
 * 內部鏈路檢測
 * @param ctx
 * @param evt
 * @throws Exception
 */
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    //當通道空閑時由IdleStateHandler觸發的用戶事件
    if (evt instanceof IdleStateEvent){
       IdleStateEvent event = (IdleStateEvent) evt;
        // 判斷Channel是否讀空閑, 讀空閑時移除Channel
        if (event.state().equals(IdleState.READER_IDLE)) {
            final String address = NettyUtil.parseChannelRemoteAddr(ctx.channel());
            logger.warn("Netty Server UserAuthHandler: IDLE exception :{}", address);
            manager.removeChannel(ctx.channel());
            //廣播用戶數量
            manager.broadMessage(QuarkChatProtocol.buildSysUserInfo(manager.getUsers()));
        }
    }
}
 
開發者ID:ChinaLHR,項目名稱:JavaQuarkBBS,代碼行數:22,代碼來源:UserAuthHandler.java

示例3: userEventTriggered

import io.netty.handler.timeout.IdleState; //導入依賴的package包/類
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    //心跳配置
    if (IdleStateEvent.class.isAssignableFrom(evt.getClass())) {
        IdleStateEvent event = (IdleStateEvent) evt;
        if (event.state() == IdleState.READER_IDLE) {
            //表示已經多久沒有收到數據了
            //ctx.close();
        } else if (event.state() == IdleState.WRITER_IDLE) {
            //表示已經多久沒有發送數據了
            SocketUtils.sendMsg(ctx, heartJson);
            logger.info("心跳數據---" + heartJson);
        } else if (event.state() == IdleState.ALL_IDLE) {
            //表示已經多久既沒有收到也沒有發送數據了

        }
    }
}
 
開發者ID:1991wangliang,項目名稱:tx-lcn,代碼行數:19,代碼來源:TransactionHandler.java

示例4: userEventTriggered

import io.netty.handler.timeout.IdleState; //導入依賴的package包/類
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent event = (IdleStateEvent) evt;
        if (event.state().equals(IdleState.ALL_IDLE)) {
            final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
            log.warn("NETTY CLIENT PIPELINE: IDLE exception [{}]", remoteAddress);
            closeChannel(ctx.channel());
            if (NettyRemotingClient.this.channelEventListener != null) {
                NettyRemotingClient.this
                    .putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress, ctx.channel()));
            }
        }
    }

    ctx.fireUserEventTriggered(evt);
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:18,代碼來源:NettyRemotingClient.java

示例5: userEventTriggered

import io.netty.handler.timeout.IdleState; //導入依賴的package包/類
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
    	/**
         *IdleStateEvent事件,在指定時間沒有進行讀寫,會進行回調
         */
        IdleStateEvent event = (IdleStateEvent) evt;
        if (event.state().equals(IdleState.ALL_IDLE)) {
            final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
            log.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", remoteAddress);
            RemotingUtil.closeChannel(ctx.channel());  //關閉channel
            if (NettyRemotingServer.this.channelEventListener != null) {
                NettyRemotingServer.this
                    .putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress, ctx.channel()));
            }
        }
    }

    ctx.fireUserEventTriggered(evt);
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:21,代碼來源:NettyRemotingServer.java

示例6: userEventTriggered

import io.netty.handler.timeout.IdleState; //導入依賴的package包/類
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    Channel channel = ctx.channel();
    if (IdleStateEvent.class.isAssignableFrom(evt.getClass())) {
        IdleStateEvent event = (IdleStateEvent) evt;
        if (event.state() == IdleState.ALL_IDLE) {
            //發送心跳
            channel.writeAndFlush(PING);
        }
        if (event.state() == IdleState.READER_IDLE) {
            //發送心跳
            channel.writeAndFlush(PING);
        }
        if (event.state() == IdleState.WRITER_IDLE) {
            channel.writeAndFlush(PING);
        }
    } else {
        super.userEventTriggered(ctx, evt);
    }
}
 
開發者ID:lee123lee123,項目名稱:GoPush,代碼行數:21,代碼來源:NodeChannelInBoundHandler.java

示例7: userEventTriggered

import io.netty.handler.timeout.IdleState; //導入依賴的package包/類
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    Channel channel = ctx.channel();
    dataCenterChannelStore.isDcChannelToSave(channel);
    if (IdleStateEvent.class.isAssignableFrom(evt.getClass())) {
        IdleStateEvent event = (IdleStateEvent) evt;
        if (event.state() == IdleState.ALL_IDLE) {
            //發送心跳
            channel.writeAndFlush(PING);
        }
        if (event.state() == IdleState.READER_IDLE) {
            //發送心跳
            channel.writeAndFlush(PING);
        }
        if (event.state() == IdleState.WRITER_IDLE) {
            channel.writeAndFlush(PING);
        }
    } else {
        super.userEventTriggered(ctx, evt);
    }
}
 
開發者ID:lee123lee123,項目名稱:GoPush,代碼行數:22,代碼來源:NodeChannelInBoundHandler.java

示例8: userEventTriggered

import io.netty.handler.timeout.IdleState; //導入依賴的package包/類
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (IdleStateEvent.class.isAssignableFrom(evt.getClass())) {
        IdleStateEvent event = (IdleStateEvent) evt;
        if (event.state() == IdleState.READER_IDLE) {
            ctx.writeAndFlush(PING);
        }
        if (event.state() == IdleState.WRITER_IDLE) {
            ctx.writeAndFlush(PING);
        }
        if (event.state() == IdleState.ALL_IDLE) {
            ctx.writeAndFlush(PING);
        }
    } else {
        super.userEventTriggered(ctx, evt);
    }
}
 
開發者ID:lee123lee123,項目名稱:GoPush,代碼行數:18,代碼來源:DeviceChannelInboundHandler.java

示例9: userEventTriggered

import io.netty.handler.timeout.IdleState; //導入依賴的package包/類
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent evnet = (IdleStateEvent) evt;
        if (evnet.state().equals(IdleState.ALL_IDLE)) {
            final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
            log.warn("NETTY CLIENT PIPELINE: IDLE exception [{}]", remoteAddress);
            closeChannel(ctx.channel());
            if (NettyRemotingClient.this.channelEventListener != null) {
                NettyRemotingClient.this.putNettyEvent(new NettyEvent(NettyEventType.IDLE,
                    remoteAddress.toString(), ctx.channel()));
            }
        }
    }

    ctx.fireUserEventTriggered(evt);
}
 
開發者ID:y123456yz,項目名稱:reading-and-annotate-rocketmq-3.4.6,代碼行數:18,代碼來源:NettyRemotingClient.java

示例10: userEventTriggered

import io.netty.handler.timeout.IdleState; //導入依賴的package包/類
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent evnet = (IdleStateEvent) evt;
        if (evnet.state().equals(IdleState.ALL_IDLE)) {
            final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
            log.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", remoteAddress);
            RemotingUtil.closeChannel(ctx.channel());
            if (NettyRemotingServer.this.channelEventListener != null) {
                NettyRemotingServer.this
                    .putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress.toString(), ctx.channel()));
            }
        }
    }

    ctx.fireUserEventTriggered(evt);
}
 
開發者ID:y123456yz,項目名稱:reading-and-annotate-rocketmq-3.4.6,代碼行數:18,代碼來源:NettyRemotingServer.java

示例11: userEventTriggered

import io.netty.handler.timeout.IdleState; //導入依賴的package包/類
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent evnet = (IdleStateEvent) evt;
        if (evnet.state().equals(IdleState.ALL_IDLE)) {
            final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
            log.warn("NETTY CLIENT PIPELINE: IDLE exception [{}]", remoteAddress);
            closeChannel(ctx.channel());
            if (NettyRemotingClient.this.channelEventListener != null) {
                NettyRemotingClient.this
                        .putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress.toString(), ctx.channel()));
            }
        }
    }

    ctx.fireUserEventTriggered(evt);
}
 
開發者ID:beyondfengyu,項目名稱:ConfigCenter,代碼行數:18,代碼來源:NettyRemotingClient.java

示例12: userEventTriggered

import io.netty.handler.timeout.IdleState; //導入依賴的package包/類
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent evnet = (IdleStateEvent) evt;
        if (evnet.state().equals(IdleState.ALL_IDLE)) {
            final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
            log.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", remoteAddress);
            RemotingUtil.closeChannel(ctx.channel());
            if (NettyRemotingServer.this.channelEventListener != null) {
                NettyRemotingServer.this
                        .putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress.toString(), ctx.channel()));
            }
        }
    }

    ctx.fireUserEventTriggered(evt);
}
 
開發者ID:beyondfengyu,項目名稱:ConfigCenter,代碼行數:18,代碼來源:NettyRemotingServer.java

示例13: userEventTriggered

import io.netty.handler.timeout.IdleState; //導入依賴的package包/類
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent evnet = (IdleStateEvent) evt;
        // 判斷Channel是否讀空閑, 讀空閑時移除Channel
        if (evnet.state().equals(IdleState.READER_IDLE)) {
            final String remoteAddress = NettyUtil.parseChannelRemoteAddr(ctx.channel());
            logger.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", remoteAddress);
            UserInfoManager.removeChannel(ctx.channel());
            UserInfoManager.broadCastInfo(ChatCode.SYS_USER_COUNT,UserInfoManager.getAuthUserCount());
        }
    }
    ctx.fireUserEventTriggered(evt);
}
 
開發者ID:beyondfengyu,項目名稱:HappyChat,代碼行數:15,代碼來源:UserAuthHandler.java

示例14: userEventTriggered

import io.netty.handler.timeout.IdleState; //導入依賴的package包/類
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent idle = (IdleStateEvent) evt;
        if (idle.state() == IdleState.READER_IDLE) {
            // We have not read any data from client in a while, let's close
            // the subscriptions for this context.
            LOG.info("Client {} is idle", ctx.channel());
        }
    } else if (evt instanceof SslCompletionEvent) {
        SslCompletionEvent ssl = (SslCompletionEvent) evt;
        if (!ssl.isSuccess()) {
            LOG.error("SSL error: {}", ssl.getClass().getSimpleName(), ssl.cause());
        }
    } else {
        LOG.warn("Received unhandled user event {}", evt);
    }
}
 
開發者ID:NationalSecurityAgency,項目名稱:qonduit,代碼行數:19,代碼來源:WebSocketRequestDecoder.java

示例15: userEventTriggered

import io.netty.handler.timeout.IdleState; //導入依賴的package包/類
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    //心跳配置
    if (IdleStateEvent.class.isAssignableFrom(evt.getClass())&& socketService.getSocketEventService().hasOpenHeartCheck()) {
        IdleStateEvent event = (IdleStateEvent) evt;
        String uniqueKey = ctx.channel().remoteAddress().toString();
        if (event.state() == IdleState.READER_IDLE) {
            //表示已經多久沒有收到數據了

            socketService.getSocketEventService().onHeartNoReadDataListener(ctx,uniqueKey);

        } else if (event.state() == IdleState.WRITER_IDLE) {
            //表示已經多久沒有發送數據了

            socketService.getSocketEventService().onHeartNoWriteDataListener(ctx,uniqueKey);

        } else if (event.state() == IdleState.ALL_IDLE) {
            //表示已經多久既沒有收到也沒有發送數據了

        }
    }
}
 
開發者ID:1991wangliang,項目名稱:sds,代碼行數:23,代碼來源:SocketHandler.java


注:本文中的io.netty.handler.timeout.IdleState類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。