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


Java IdleState.READER_IDLE屬性代碼示例

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


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

示例1: 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();
        }
    }
}
 
開發者ID:yu199195,項目名稱:happylifeplat-transaction,代碼行數:18,代碼來源:NettyClientMessageHandler.java

示例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) {
            //表示已經多久沒有收到數據了
            //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,代碼行數:18,代碼來源:TransactionHandler.java

示例3: 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);
    }
}
 
開發者ID:lee123lee123,項目名稱:GoPush,代碼行數:20,代碼來源:NodeChannelInBoundHandler.java

示例4: 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);
    }
}
 
開發者ID:lee123lee123,項目名稱:GoPush,代碼行數:21,代碼來源:NodeChannelInBoundHandler.java

示例5: 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);
    }
}
 
開發者ID:lee123lee123,項目名稱:GoPush,代碼行數:17,代碼來源:DeviceChannelInboundHandler.java

示例6: userEventTriggered

@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,代碼行數:18,代碼來源:WebSocketRequestDecoder.java

示例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) {
            //表示已經多久既沒有收到也沒有發送數據了

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

示例8: userEventTriggered

/**
 * 利用事件變化來做心跳檢測
 */
@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,代碼行數:21,代碼來源:NettyHandler.java

示例9: 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);
	}
}
 
開發者ID:hdcuican,項目名稱:java_learn,代碼行數:19,代碼來源:ServerHandler.java

示例10: 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);
	}
}
 
開發者ID:janzolau1987,項目名稱:study-netty,代碼行數:23,代碼來源:HeartbeatServerHandler.java

示例11: userEventTriggered

@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,代碼行數:26,代碼來源:WebSocketRequestDecoder.java

示例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) {
            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,代碼行數:16,代碼來源:NettyConnHandler.java

示例13: userEventTriggered

@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,代碼行數:26,代碼來源:HttpServerHandler.java

示例14: 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);
        }
    }
}
 
開發者ID:MOBX,項目名稱:Thor,代碼行數:16,代碼來源:NettyServerHandler.java

示例15: userEventTriggered

/**
 * When a timeout occurs, notify listener and close the channel.
 *
 * @param ctx Channel context
 * @param evt Event
 * @throws Exception
 */
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent event = (IdleStateEvent) evt;
        if (event.state() == IdleState.READER_IDLE || event.state() == IdleState.WRITER_IDLE) {
            if (originalChannelContext == null) {
                originalChannelContext = ctx;
            }
            if (ctx == originalChannelContext) {
                originalChannelContext.fireUserEventTriggered(evt);
                isIdleHandlerOfTargetChannelRemoved = true;
            } else {
                sendTimeoutError(ctx);
            }
            /*Once a timeout occurs after sending the response, close the channel, otherwise we will still be
             getting response data  after the timeout, if backend sends data. */
            if (ctx != originalChannelContext) {
                ctx.close();
            }
        }
    }
}
 
開發者ID:wso2,項目名稱:carbon-transports,代碼行數:29,代碼來源:RedirectHandler.java


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