本文整理汇总了Java中org.jboss.netty.handler.timeout.IdleState类的典型用法代码示例。如果您正苦于以下问题:Java IdleState类的具体用法?Java IdleState怎么用?Java IdleState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IdleState类属于org.jboss.netty.handler.timeout包,在下文中一共展示了IdleState类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: channelIdle
import org.jboss.netty.handler.timeout.IdleState; //导入依赖的package包/类
@Override
public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) throws Exception {
if (!isHandshakeComplete()) {
return;
}
if (e.getState() == IdleState.READER_IDLE) {
// When no message is received on channel for read timeout, then close
// the channel
log.info("Disconnecting client {} due to read timeout", getClientInfoString());
ctx.getChannel().close();
} else if (e.getState() == IdleState.WRITER_IDLE) {
// Send keep alive message
log.debug("Sending keep alive message due to IdleState timeout " + pc.toString());
pc.sendMessage(Collections.singletonList(pc.factory().buildKeepaliveMsg().build()));
}
}
示例2: channelIdle
import org.jboss.netty.handler.timeout.IdleState; //导入依赖的package包/类
@Override
public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) throws Exception {
if (e.getState() == IdleState.WRITER_IDLE) {
Channel channel = e.getChannel();
if (channel != null) {
//写空闲 则发送心跳数据
channel.write(Heartbeat.getSingleton());
} else {
logger.warn("writer idle on channel({}), but hsfChannel is not managed.", e.getChannel());
}
} else if (e.getState() == IdleState.READER_IDLE) {
//读空闲 则断开连接
logger.error("channel:{} is time out.", e.getChannel());
handleUpstream(ctx, new DefaultExceptionEvent(e.getChannel(), new SocketTimeoutException(
"force to close channel(" + ctx.getChannel().getRemoteAddress() + "), reason: time out.")));
e.getChannel().close();
}
super.channelIdle(ctx, e);
}
示例3: channelIdle
import org.jboss.netty.handler.timeout.IdleState; //导入依赖的package包/类
private void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) {
if (e.getState() == IdleState.READER_IDLE) {
Object a = ctx.getChannel().getAttachment();
// connect/login timeout
if (a == null || a instanceof ChannelFuture) {
ctx.getChannel().close();
return;
}
ChannelData d = (ChannelData)a;
if (d.timer.elapsed() > TimeUnit.MILLISECONDS.convert(60, TimeUnit.SECONDS)) {
ctx.getChannel().close();
} else {
ctx.sendDownstream(new DownstreamMessageEvent(ctx.getChannel(),
new DefaultChannelFuture(ctx.getChannel(), false), PING, null));
}
}
}
示例4: channelIdle
import org.jboss.netty.handler.timeout.IdleState; //导入依赖的package包/类
@Override
public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) throws Exception {
// check if the client did nothing for too long
if (e.getState().equals(IdleState.ALL_IDLE)) {
ImapSession session = (ImapSession) attributes.get(ctx.getChannel());
InetSocketAddress address = (InetSocketAddress) ctx.getChannel().getRemoteAddress();
session.getLog().info("Logout client " + address.getHostName() + " (" + address.getAddress().getHostAddress() + ") because it idled for too long...");
// logout the client
session.logout();
// close the channel
ctx.getChannel().close();
}
super.channelIdle(ctx, e);
}
示例5: channelIdle
import org.jboss.netty.handler.timeout.IdleState; //导入依赖的package包/类
@Override
public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e)
throws Exception {
if (e.getState() == IdleState.ALL_IDLE) {
e.getChannel().close();
}
}
示例6: channelIdle
import org.jboss.netty.handler.timeout.IdleState; //导入依赖的package包/类
@Override
public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) throws Exception {
super.channelIdle(ctx, e);
if(e.getState() == IdleState.ALL_IDLE) {
e.getChannel().close();
System.out.println("idle channel was closed!");
}
}
示例7: channelIdle
import org.jboss.netty.handler.timeout.IdleState; //导入依赖的package包/类
@Override
public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) {
logger.info("In IDLE event handler for TCP...");
//there are 3 states. READER/WRITER/ALL
if (e.getState() == IdleState.ALL_IDLE){
int statusCodeInt = 0;
String statusCode = statusCodeInt + " SUCCESSFUL";
String errMsg="idleTimeout to finish";
tcpWorker.onComplete(tcpWorker.responseSb.toString(), false,
errMsg, errMsg, statusCode, statusCodeInt);
}
}
示例8: channelIdle
import org.jboss.netty.handler.timeout.IdleState; //导入依赖的package包/类
/**
* this case is like a read timeout where did not get anything from the
* server for a long time.
*
* For UDP need to mark as error
*
* @see org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler#channelIdle
* (org.jboss.netty.channel.ChannelHandlerContext,
* org.jboss.netty.handler.timeout.IdleStateEvent)
*/
@Override
public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) {
logger.debug("In IDLE event handler for UDP..timeout.");
// there are 3 states. READER/WRITER/ALL
if (e.getState() == IdleState.ALL_IDLE) {
int statusCodeInt = 1;
String statusCode = statusCodeInt + " FAILURE";
String errMsg = "UDP idle (read) timeout";
udpWorker.onComplete(udpWorker.responseSb.toString(), true,
errMsg, errMsg, statusCode, statusCodeInt);
}
}
示例9: channelIdle
import org.jboss.netty.handler.timeout.IdleState; //导入依赖的package包/类
public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) {
if (e.getState() == IdleState.READER_IDLE) {
if (_timer.elapsed() > TimeUnit.MILLISECONDS.convert(60, TimeUnit.SECONDS)) {
ctx.getChannel().close();
} else {
L.debug("send ping");
ctx.sendDownstream(new DownstreamMessageEvent(ctx.getChannel(),
new DefaultChannelFuture(ctx.getChannel(), false), PING, null));
}
}
}
示例10: channelIdle
import org.jboss.netty.handler.timeout.IdleState; //导入依赖的package包/类
@Override
public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e)
throws InterruptedException {
if (e.getState() == IdleState.ALL_IDLE) {
this.closeChannel(ctx, 1011, Text.REACH_MAX_IDLE);
this.logger.info(Text.REACH_MAX_IDLE_AND_CLOSE, this.maxIdleTimeSeconds);
}
}
示例11: channelIdle
import org.jboss.netty.handler.timeout.IdleState; //导入依赖的package包/类
@Override
public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) throws Exception {
if (e.getState().equals(IdleState.WRITER_IDLE)) {
e.getChannel().write(ChannelBuffers.wrappedBuffer("* OK Hang in there..\r\n".getBytes("US-ASCII")));
}
super.channelIdle(ctx, e);
}
示例12: channelIdle
import org.jboss.netty.handler.timeout.IdleState; //导入依赖的package包/类
@Override
public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) {
if (e.getState() == IdleState.WRITER_IDLE && enabledTimeout) {
e.getChannel().close();
}
}