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


Java ChannelState.CONNECTED属性代码示例

本文整理汇总了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);
}
 
开发者ID:mnip91,项目名称:proactive-component-monitoring,代码行数:20,代码来源:PNPClientFrameDecoder.java

示例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));
}
 
开发者ID:allengeorge,项目名称:libraft,代码行数:23,代码来源:AddressResolverHandlerTest.java

示例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));
}
 
开发者ID:allengeorge,项目名称:libraft,代码行数:26,代码来源:AddressResolverHandlerTest.java

示例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);
}
 
开发者ID:mgm-tp,项目名称:perfload-core,代码行数:29,代码来源:ServerHandler.java

示例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));
}
 
开发者ID:allengeorge,项目名称:libraft,代码行数:13,代码来源:AddressResolverHandlerTest.java

示例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));
}
 
开发者ID:allengeorge,项目名称:libraft,代码行数:13,代码来源:AddressResolverHandlerTest.java

示例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));
}
 
开发者ID:allengeorge,项目名称:libraft,代码行数:33,代码来源:AddressResolverHandlerTest.java


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