本文整理汇总了Java中io.netty.handler.timeout.IdleState.ALL_IDLE属性的典型用法代码示例。如果您正苦于以下问题:Java IdleState.ALL_IDLE属性的具体用法?Java IdleState.ALL_IDLE怎么用?Java IdleState.ALL_IDLE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类io.netty.handler.timeout.IdleState
的用法示例。
在下文中一共展示了IdleState.ALL_IDLE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: userEventTriggered
/**
* 判断是否是IdleStateEvent事件,是则处理
*/
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if(evt instanceof IdleStateEvent) {
IdleStateEvent event = (IdleStateEvent) evt;
String type = "";
if(event.state() == IdleState.READER_IDLE)
type = "read idle";
else if(event.state() == IdleState.WRITER_IDLE)
type = "write idle";
else if(event.state() == IdleState.ALL_IDLE)
type = "all idle";
//
ChannelFuture f = ctx.writeAndFlush(HEARTBEAT_SEQUENCE.duplicate());
f.addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
System.out.println(ctx.channel().remoteAddress() + "超时类型 : " + type);
} else {
super.userEventTriggered(ctx, evt);
}
}
示例2: userEventTriggered
@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();
}
}
}
示例3: userEventTriggered
@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) {
//表示已经多久既没有收到也没有发送数据了
}
}
}
示例4: userEventTriggered
@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);
}
}
示例5: userEventTriggered
@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);
}
}
示例6: userEventTriggered
@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);
}
}
示例7: userEventTriggered
@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) {
//表示已经多久既没有收到也没有发送数据了
}
}
}
示例8: userEventTriggered
@Override
public void userEventTriggered(final ChannelHandlerContext ctx, Object evt)
throws Exception {
if(evt instanceof IdleStateEvent) {
IdleStateEvent event = (IdleStateEvent) evt;
if (event.state() == IdleState.READER_IDLE) {
System.out.println("--- Reader Idle ---");
ctx.writeAndFlush("读取等待:客户端你在吗... ...\r\n");
} else if (event.state() == IdleState.WRITER_IDLE) {
System.out.println("--- Write Idle ---");
ctx.writeAndFlush("写入等待:客户端你在吗... ...\r\n");
} else if (event.state() == IdleState.ALL_IDLE) {
System.out.println("--- All_IDLE ---");
ctx.writeAndFlush("全部时间:客户端你在吗... ...\r\n");
}
}else{
super.userEventTriggered(ctx, evt);
}
}
示例9: userEventTriggered
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent e = (IdleStateEvent) evt;
if (e.state() == IdleState.READER_IDLE) {
logger.info("READER_IDLE 事件触发, 关闭连接");/*读超时*/
ctx.close();
} else if (e.state() == IdleState.WRITER_IDLE) {
logger.info("WRITER_IDLE 事件触发");
ctx.writeAndFlush(new PingMessage());
} else if (e.state() == IdleState.ALL_IDLE) {
logger.info("ALL_IDLE 事件触发, 关闭连接");
ctx.close();
}
}
}
示例10: userEventTriggered
@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) {
// logger.info("read idle");
} else if (event.state() == IdleState.WRITER_IDLE) {
// logger.info("write idle");
} else if (event.state() == IdleState.ALL_IDLE) {
JSyncPacket message = new JSyncPacket();
message.setPacketType(2);
ctx.channel().writeAndFlush(message);
logger.info("[Server 链路空闲!发送心跳!]" + message);
}
}
}
示例11: userEventTriggered
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent e = (IdleStateEvent) evt;
if (e.state() == IdleState.READER_IDLE) {
LOGGER.info("READER_IDLE");
// ctx.close(); // 断开客户端的连接
} else if (e.state() == IdleState.WRITER_IDLE) {
LOGGER.info("WRITER_IDLE");
} else if (e.state() == IdleState.ALL_IDLE) {
LOGGER.info("ALL_IDLE");
// ctx.close(); // 断开客户端的连接
}
}
super.userEventTriggered(ctx, evt);
}
示例12: userEventTriggered
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent e = (IdleStateEvent) evt;
if (e.state() == IdleState.READER_IDLE) {
System.out.println("Reader idle, closing channel");
//e.getChannel().close();
}
else if (e.state() == IdleState.WRITER_IDLE) {
System.out.println("Writer idle, sending heartbeat");
}
else if (e.state() == IdleState.ALL_IDLE) {
System.out.println("All idle, sending heartbeat");
}else if (e.state() == IdleState.ALL_IDLE) {
System.out.println("All idle, sending heartbeat");
}
//Send the heartbeat and close the connection if the send operation fails
ctx.writeAndFlush(HEARTBEAT_SEQUENCE.duplicate())
.addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
} else {
//Not of type IdleStateEvent pass it to the next handler in the ChannelPipeline
super.userEventTriggered(ctx, evt);
}
}
示例13: userEventTriggered
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent event = (IdleStateEvent) evt;
if (event.state() == IdleState.ALL_IDLE) {
ctx.close();
return;
}
if (event.state() == IdleState.READER_IDLE) {
ctx.close();
return;
}
if (event.state() == IdleState.WRITER_IDLE) {
ctx.close();
return;
}
}
}
示例14: userEventTriggered
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception
{
if (evt instanceof IdleStateEvent)
{
IdleStateEvent event = (IdleStateEvent) evt;
if (event.state() == IdleState.ALL_IDLE)
{
GridSession session = GridSessionFactory.getSession(ctx.channel());
String nodeId = GridRuntime.nodes().getNodeId(session.getId());
log.warn("Grid session " + session.remoteAddress() + " write and read is idle status.nodeId:" + nodeId);
if (nodeId == null || !GridRuntime.nodes().contains(nodeId) || !session.isActive())
{
log.warn("Grid session " + session.remoteAddress() + " isn't the node session.");
GridRuntime.network().removeWaitActive(session);
session.close();
if (nodeId != null)
GridRuntime.nodes().removeNode(session);
}
}
}
else
super.userEventTriggered(ctx, evt);
}
示例15: userEventTriggered
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
/* 心跳处理 */
if (evt instanceof IdleStateEvent) {
IdleStateEvent event = (IdleStateEvent) evt;
if (event.state() == IdleState.READER_IDLE) {
/* 读超时 */
Log.info("READER_IDLE 读超时");
ctx.disconnect();
} else if (event.state() == IdleState.WRITER_IDLE) {
/* 写超时 */
Log.info("WRITER_IDLE 写超时");
} else if (event.state() == IdleState.ALL_IDLE) {
/* 总超时 */
Log.info("ALL_IDLE 总超时");
}
}
}