当前位置: 首页>>代码示例>>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;未经允许,请勿转载。