本文整理汇总了Java中org.jboss.netty.channel.ChannelStateEvent.getState方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelStateEvent.getState方法的具体用法?Java ChannelStateEvent.getState怎么用?Java ChannelStateEvent.getState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.netty.channel.ChannelStateEvent
的用法示例。
在下文中一共展示了ChannelStateEvent.getState方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleUpstream
import org.jboss.netty.channel.ChannelStateEvent; //导入方法依赖的package包/类
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e)
throws Exception {
if (e instanceof ChannelStateEvent) {
ChannelStateEvent evt = (ChannelStateEvent) e;
switch (evt.getState()) {
case OPEN:
case BOUND:
// Special case: OPEND and BOUND events are before CONNECTED,
// but CLOSED and UNBOUND events are after DISCONNECTED: should
// those events be blocked too?
if (isBlocked(ctx) && !continues(ctx, evt)) {
// don't pass to next level since channel was blocked early
return;
} else {
ctx.sendUpstream(e);
return;
}
case CONNECTED:
if (evt.getValue() != null) {
// CONNECTED
InetSocketAddress inetSocketAddress = (InetSocketAddress) e
.getChannel().getRemoteAddress();
if (!accept(ctx, e, inetSocketAddress)) {
ctx.setAttachment(Boolean.TRUE);
final ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes("/".getBytes());
buffer.writeBytes("ok".getBytes());
ChannelFuture future = e.getChannel().write(buffer);
future.addListener(ChannelFutureListener.CLOSE);
LOG.info("Ignoring " + inetSocketAddress.getAddress().getHostAddress());
if (isBlocked(ctx) && !continues(ctx, evt)) {
// don't pass to next level since channel was
// blocked early
return;
}
}
// This channel is not blocked
ctx.setAttachment(null);
} else {
// DISCONNECTED
if (isBlocked(ctx) && !continues(ctx, evt)) {
// don't pass to next level since channel was blocked
// early
return;
}
}
break;
}
}
if (isBlocked(ctx) && !continues(ctx, e)) {
// don't pass to next level since channel was blocked early
return;
}
// Whatever it is, if not blocked, goes to the next level
ctx.sendUpstream(e);
}
示例2: handleDownstream
import org.jboss.netty.channel.ChannelStateEvent; //导入方法依赖的package包/类
@Override
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)
throws Exception {
logger.debug("handleDownstream e={}", e);
if (e instanceof MessageEvent) {
logger.debug("MessageEvent >> writeRequested");
writeRequested(ctx, (MessageEvent) e);
} else if (e instanceof ChannelStateEvent) {
ChannelStateEvent evt = (ChannelStateEvent) e;
switch (evt.getState()) {
case OPEN:
if (!Boolean.TRUE.equals(evt.getValue())) {
logger.debug("ChannelStateEvent >> closeRequested");
closeRequested(ctx, evt);
}
break;
case BOUND:
if (evt.getValue() != null) {
logger.debug("ChannelStateEvent >> bindRequested");
bindRequested(ctx, evt);
} else {
logger.debug("ChannelStateEvent >> unbindRequested");
unbindRequested(ctx, evt);
}
break;
case CONNECTED:
if (evt.getValue() != null) {
logger.debug("ChannelStateEvent >> connectRequested");
connectRequested(ctx, evt);
} else {
logger.debug("ChannelStateEvent >> disconnectRequested");
disconnectRequested(ctx, evt);
}
break;
case INTEREST_OPS:
logger.debug("ChannelStateEvent >> setInterestOpsRequested");
setInterestOpsRequested(ctx, evt);
break;
default:
logger.debug("ChannelStateEvent >> sendDownstream");
ctx.sendDownstream(e);
}
} else {
logger.debug("------ >> sendDownstream");
ctx.sendDownstream(e);
}
}