当前位置: 首页>>代码示例>>Java>>正文


Java IdleStateEvent.state方法代码示例

本文整理汇总了Java中io.netty.handler.timeout.IdleStateEvent.state方法的典型用法代码示例。如果您正苦于以下问题:Java IdleStateEvent.state方法的具体用法?Java IdleStateEvent.state怎么用?Java IdleStateEvent.state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.handler.timeout.IdleStateEvent的用法示例。


在下文中一共展示了IdleStateEvent.state方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: userEventTriggered

import io.netty.handler.timeout.IdleStateEvent; //导入方法依赖的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.IdleStateEvent; //导入方法依赖的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

示例3: userEventTriggered

import io.netty.handler.timeout.IdleStateEvent; //导入方法依赖的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

示例4: userEventTriggered

import io.netty.handler.timeout.IdleStateEvent; //导入方法依赖的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

示例5: userEventTriggered

import io.netty.handler.timeout.IdleStateEvent; //导入方法依赖的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

示例6: userEventTriggered

import io.netty.handler.timeout.IdleStateEvent; //导入方法依赖的package包/类
/**
 * 利用事件变化来做心跳检测
 */
@Override
public void userEventTriggered( ChannelHandlerContext _ctx , Object _obj ) throws Exception {
	logger.debug( _handler_info( _ctx , "userEventTriggered" ) );

	if ( _obj instanceof IdleStateEvent ) {
		IdleStateEvent event = ( IdleStateEvent ) _obj;
		if ( event.state() == IdleState.READER_IDLE ) {
			lost++;
			logger.debug( _handler_info( _ctx , " inactive with=" + lost ) );
			if ( lost > 2 ) {
				handler.stand( _ctx );
				logger.debug( _handler_info( _ctx , " was stand with=" + lost ) );
			}
		}
	} else {
		logger.warn( _handler_info( _ctx , " was discard" ) );
	}
}
 
开发者ID:aiyoyoyo,项目名称:jeesupport,代码行数:22,代码来源:NettyHandler.java

示例7: userEventTriggered

import io.netty.handler.timeout.IdleStateEvent; //导入方法依赖的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

示例8: userEventTriggered

import io.netty.handler.timeout.IdleStateEvent; //导入方法依赖的package包/类
@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);
	}
}
 
开发者ID:hdcuican,项目名称:java_learn,代码行数:20,代码来源:ServerHandler.java

示例9: userEventTriggered

import io.netty.handler.timeout.IdleStateEvent; //导入方法依赖的package包/类
/**
 * 判断是否是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);
	}
}
 
开发者ID:janzolau1987,项目名称:study-netty,代码行数:24,代码来源:HeartbeatServerHandler.java

示例10: userEventTriggered

import io.netty.handler.timeout.IdleStateEvent; //导入方法依赖的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.
            String subscriptionId = ctx.channel().attr(SubscriptionRegistry.SUBSCRIPTION_ID_ATTR).get();
            if (!StringUtils.isEmpty(subscriptionId)) {
                if (SubscriptionRegistry.get().containsKey(subscriptionId)) {
                    LOG.info("Closing subscription with subscription id {} due to idle event", subscriptionId);
                    SubscriptionRegistry.get().get(subscriptionId).close();
                }
            } else {
                LOG.warn("Channel idle, but no subscription id found on context. Unable to close subscriptions");
            }
        }
    } 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,项目名称:timely,代码行数:27,代码来源:WebSocketRequestDecoder.java

示例11: userEventTriggered

import io.netty.handler.timeout.IdleStateEvent; //导入方法依赖的package包/类
@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();
        }
    }
}
 
开发者ID:TFdream,项目名称:netty-tutorials,代码行数:17,代码来源:NettyConnHandler.java

示例12: userEventTriggered

import io.netty.handler.timeout.IdleStateEvent; //导入方法依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {

	Channel channel = ctx.channel();
	log.error("userEventTriggered={}, object={}", channel, evt);

	if (!(evt instanceof IdleStateEvent)) { return; }

	if (evt instanceof IdleStateEvent)  {
		IdleStateEvent e = (IdleStateEvent) evt;

		if (e.state() == IdleState.READER_IDLE) {
			log.debug("userEventTriggered(readIdle)={}", ctx.channel());

			if (isReadBytes == false) ctx.close();
		} else if (e.state() == IdleState.WRITER_IDLE) {
			log.debug("userEventTriggered(writeIdle)={}", ctx.channel());
			
			if (isReadBytes == false) ctx.close();
		} else {
			log.debug("userEventTriggered(allIdle)={}", ctx.channel());
			
			if (isReadBytes == false) ctx.close();
		}
	}
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:27,代码来源:HttpServerHandler.java

示例13: userEventTriggered

import io.netty.handler.timeout.IdleStateEvent; //导入方法依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    //处理超时未收到消息的事件
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent e = (IdleStateEvent) evt;
        switch (e.state()) {
            case READER_IDLE:
                onIdeled(ctx.channel());
                break;
            case WRITER_IDLE:

                break;
            case ALL_IDLE:

                break;
        }
    } else super.userEventTriggered(ctx, evt);

}
 
开发者ID:jayqqaa12,项目名称:jbase,代码行数:20,代码来源:NettyHeartHandler.java

示例14: userEventTriggered

import io.netty.handler.timeout.IdleStateEvent; //导入方法依赖的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) {
            // 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);
        }
    }
}
 
开发者ID:MOBX,项目名称:Thor,代码行数:17,代码来源:NettyServerHandler.java

示例15: userEventTriggered

import io.netty.handler.timeout.IdleStateEvent; //导入方法依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (!(evt instanceof IdleStateEvent)) {
        logger.warn("One user event Triggered. evt=" + evt);
        super.userEventTriggered(ctx, evt);
        return;
    }
    IdleStateEvent stateEvent = (IdleStateEvent) evt;
    switch (stateEvent.state()) {
        case READER_IDLE:
            channel.receiver.reconnect();
            logger.warn("heartbeat read timeout,chanel closed!");
            break;
        case WRITER_IDLE:
            ctx.writeAndFlush(Unpooled.buffer(1).writeByte(Constants.LF_10));
            logger.warn("heartbeat write timeout,do write an EOL.");
            break;
        case ALL_IDLE:
    }
}
 
开发者ID:ohun,项目名称:stomp-client,代码行数:21,代码来源:StompMessageHandler.java


注:本文中的io.netty.handler.timeout.IdleStateEvent.state方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。