本文整理汇总了Java中org.jboss.netty.channel.ChannelState.CONNECTED属性的典型用法代码示例。如果您正苦于以下问题:Java ChannelState.CONNECTED属性的具体用法?Java ChannelState.CONNECTED怎么用?Java ChannelState.CONNECTED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.jboss.netty.channel.ChannelState
的用法示例。
在下文中一共展示了ChannelState.CONNECTED属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleUpstream
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent event) throws Exception {
if (event instanceof MessageEvent) {
MessageEvent msgEvent = (MessageEvent) event;
Object msg = msgEvent.getMessage();
if (msg instanceof ChannelBuffer) {
callDecode(ctx, (ChannelBuffer) msg, msgEvent.getRemoteAddress());
return;
}
} else if (event instanceof ChannelStateEvent) {
ChannelStateEvent stateEvent = (ChannelStateEvent) event;
if (stateEvent.getState() == ChannelState.CONNECTED) {
if (stateEvent.getValue() != null) {
lengthBytesToRead = lengthFieldLength;
lengthBuffer = getBuffer(ctx.getChannel().getConfig().getBufferFactory(),
lengthBytesToRead);
}
}
}
ctx.sendUpstream(event);
}
示例2: shouldResolveAddressAndForwardEventWhenConnectIsCalledWithAnUnresolvedInetSocketAddress
@Test
public void shouldResolveAddressAndForwardEventWhenConnectIsCalledWithAnUnresolvedInetSocketAddress() throws Exception {
DefaultChannelFuture originalEventFuture = new DefaultChannelFuture(channel, false);
ChannelStateEvent event = new DownstreamChannelStateEvent(
channel,
originalEventFuture,
ChannelState.CONNECTED,
createUnresolvedRemoteAddress()
);
handler.connectRequested(ctx, event);
ArgumentCaptor<DownstreamChannelStateEvent> eventCaptor = ArgumentCaptor.forClass(DownstreamChannelStateEvent.class);
verify(ctx).sendDownstream(eventCaptor.capture());
DownstreamChannelStateEvent forwardedEvent = eventCaptor.getValue();
assertThat(forwardedEvent.getChannel(), equalTo(channel));
assertThat(forwardedEvent.getState(), equalTo(ChannelState.CONNECTED));
assertThat(forwardedEvent.getFuture(), Matchers.<ChannelFuture>equalTo(originalEventFuture));
InetSocketAddress forwardedAddress = (InetSocketAddress) forwardedEvent.getValue();
assertThat(forwardedAddress.isUnresolved(), equalTo(false));
}
示例3: shouldFireExceptionIfConnectEventCannotBeForwarded
@Test
public void shouldFireExceptionIfConnectEventCannotBeForwarded() throws Exception {
setupPipelineToRunFireEventLaterInline();
// setup the ctx to throw an exception when we attempt to send the connected event downstream
IllegalStateException resolveFailureCause = new IllegalStateException("downstream event failed");
doThrow(resolveFailureCause).when(ctx).sendDownstream(any(DownstreamChannelStateEvent.class));
// initiate the connect request
DefaultChannelFuture originalEventFuture = new DefaultChannelFuture(channel, false);
ChannelStateEvent event = new DownstreamChannelStateEvent(
channel,
originalEventFuture,
ChannelState.CONNECTED,
createUnresolvedRemoteAddress()
);
handler.connectRequested(ctx, event);
// firing the connect downstream should cause a "fireExceptionCaughtLater" call
ArgumentCaptor<DefaultExceptionEvent> exceptionEventCaptor = ArgumentCaptor.forClass(DefaultExceptionEvent.class);
verify(ctx).sendUpstream(exceptionEventCaptor.capture());
DefaultExceptionEvent exceptionEvent = exceptionEventCaptor.getValue();
assertThat(exceptionEvent.getCause(), Matchers.<Throwable>is(resolveFailureCause));
}
示例4: handleUpstream
/**
* <p>
* {@inheritDoc}
* </p>
* <p>
* Overriden to log ChannelStateEvents if they have a state other than
* {@link ChannelState#INTEREST_OPS}, i. e. OPEN, BOUND, CONNECTED.
* </p>
*
* @param ctx
* the context object for this handler
* @param e
* the upstream event to process or intercept
*/
@Override
public void handleUpstream(final ChannelHandlerContext ctx, final ChannelEvent e) throws Exception {
if (e instanceof ChannelStateEvent) {
ChannelStateEvent stateEvent = (ChannelStateEvent) e;
if (stateEvent.getState() != ChannelState.INTEREST_OPS) {
log.info(e.toString());
if (stateEvent.getState() == ChannelState.CONNECTED && stateEvent.getValue() == null) {
// Remove channel from container when client disconnects
channelContainer.removeChannel(e.getChannel());
}
}
}
super.handleUpstream(ctx, e);
}
示例5: shouldSimplyForwardEventWhenConnectIsCalledWithAResolvedInetSocketAddress
@Test
public void shouldSimplyForwardEventWhenConnectIsCalledWithAResolvedInetSocketAddress() throws Exception {
ChannelStateEvent event = new DownstreamChannelStateEvent(
channel,
new DefaultChannelFuture(channel, false),
ChannelState.CONNECTED,
new InetSocketAddress("localhost", 9999)
);
handler.connectRequested(ctx, event);
verify(ctx).sendDownstream(refEq(event));
}
示例6: shouldSimplyForwardEventWhenConnectIsCalledWithNonInetSocketAddress
@Test
public void shouldSimplyForwardEventWhenConnectIsCalledWithNonInetSocketAddress() throws Exception {
ChannelStateEvent event = new DownstreamChannelStateEvent(
channel,
new DefaultChannelFuture(channel, false),
ChannelState.CONNECTED,
new LocalAddress(LocalAddress.EPHEMERAL)
);
handler.connectRequested(ctx, event);
verify(ctx).sendDownstream(refEq(event));
}
示例7: shouldFireExceptionIfAddressResolutionTaskFails
@Test
public void shouldFireExceptionIfAddressResolutionTaskFails() throws Exception {
setupPipelineToRunFireEventLaterInline();
// setup the address resolver to throw an exception
final IllegalStateException resolveFailureCause = new IllegalStateException("simulate resolve failure");
AddressResolverHandler.ResolvedAddressProvider failingResolver = new AddressResolverHandler.ResolvedAddressProvider() {
@Override
public InetSocketAddress createResolved(InetSocketAddress unresolvedAddress) throws Exception {
throw resolveFailureCause;
}
};
// fire a connect request with an unresolved address
AddressResolverHandler failingHandler = new AddressResolverHandler(MoreExecutors.listeningDecorator(MoreExecutors.sameThreadExecutor()), failingResolver);
DefaultChannelFuture originalEventFuture = new DefaultChannelFuture(channel, false);
ChannelStateEvent event = new DownstreamChannelStateEvent(
channel,
originalEventFuture,
ChannelState.CONNECTED,
createUnresolvedRemoteAddress()
);
failingHandler.connectRequested(ctx, event);
// this should cause a "fireExceptionCaughtLater" call
ArgumentCaptor<DefaultExceptionEvent> exceptionEventCaptor = ArgumentCaptor.forClass(DefaultExceptionEvent.class);
verify(ctx).sendUpstream(exceptionEventCaptor.capture());
DefaultExceptionEvent exceptionEvent = exceptionEventCaptor.getValue();
assertThat(exceptionEvent.getCause(), Matchers.<Throwable>is(resolveFailureCause));
}