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


Java ChannelState类代码示例

本文整理汇总了Java中org.jboss.netty.channel.ChannelState的典型用法代码示例。如果您正苦于以下问题:Java ChannelState类的具体用法?Java ChannelState怎么用?Java ChannelState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ChannelState类属于org.jboss.netty.channel包,在下文中一共展示了ChannelState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleServerChannel

import org.jboss.netty.channel.ChannelState; //导入依赖的package包/类
private void handleServerChannel(ChannelEvent e) {
    IsdnServerChannel channel = (IsdnServerChannel) e.getChannel();
    ChannelFuture future = e.getFuture();
    if (e instanceof ChannelStateEvent) {
        ChannelStateEvent stateEvent = (ChannelStateEvent) e;
        ChannelState state = stateEvent.getState();
        Object value = stateEvent.getValue();
        switch (state) {
        case OPEN:
            if (Boolean.FALSE.equals(value)) {
                close(channel, future);
            }
            break;
        case BOUND:
            if (value != null) {
                bind(channel, future, (IsdnSocketAddress) value);
            } else {
                logger.warn("eventSunk() :: UNHANDLED (BOUND value=null) --> {}", e);
                close(channel, future);
            }
            break;
        default:
            logger.warn("eventSunk() :: UNHANDLED --> {}", e);
        }
    }
}
 
开发者ID:rmarins,项目名称:netty-isdn-transport,代码行数:27,代码来源:IsdnServerPipelineSink.java

示例2: multiple_connected_same_ip

import org.jboss.netty.channel.ChannelState; //导入依赖的package包/类
@Test
public void multiple_connected_same_ip() throws Exception {
    final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);
    when(channel.getRemoteAddress()).thenReturn(remoteAddress);

    final ChannelEvent openEvent = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
    subject.handleUpstream(ctx, openEvent);
    subject.handleUpstream(ctx, openEvent);
    subject.handleUpstream(ctx, openEvent);

    verify(ctx, times(2)).sendUpstream(openEvent);
    verify(channel, times(1)).write(argThat(new ArgumentMatcher<Object>() {
        @Override
        public boolean matches(Object argument) {
            return QueryMessages.connectionsExceeded(MAX_CONNECTIONS_PER_IP).equals(argument);
        }
    }));
    verify(channelFuture, times(1)).addListener(ChannelFutureListener.CLOSE);
    verify(whoisLog).logQueryResult(anyString(), eq(0), eq(0), eq(QueryCompletionInfo.REJECTED), eq(0L), (InetAddress) Mockito.anyObject(), Mockito.anyInt(), eq(""));
    verify(ctx, times(2)).sendUpstream(openEvent);
}
 
开发者ID:RIPE-NCC,项目名称:whois,代码行数:22,代码来源:ConnectionPerIpLimitHandlerTest.java

示例3: multiple_connected_limit_disabled

import org.jboss.netty.channel.ChannelState; //导入依赖的package包/类
@Test
public void multiple_connected_limit_disabled() throws Exception {
    subject.setMaxConnectionsPerIp(0);

    final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);
    when(channel.getRemoteAddress()).thenReturn(remoteAddress);

    final ChannelEvent openEvent = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
    subject.handleUpstream(ctx, openEvent);
    subject.handleUpstream(ctx, openEvent);
    subject.handleUpstream(ctx, openEvent);

    final ChannelEvent closeEvent = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.FALSE);
    subject.handleUpstream(ctx, closeEvent);
    subject.handleUpstream(ctx, closeEvent);
    subject.handleUpstream(ctx, closeEvent);

    verify(ctx, times(3)).sendUpstream(openEvent);
    verify(ctx, times(3)).sendUpstream(closeEvent);
    verify(channel, never()).close();
    verify(channel, never()).write(anyObject());
    verify(channelFuture, never()).addListener(ChannelFutureListener.CLOSE);
}
 
开发者ID:RIPE-NCC,项目名称:whois,代码行数:24,代码来源:ConnectionPerIpLimitHandlerTest.java

示例4: multiple_connected_unlimited_allowed

import org.jboss.netty.channel.ChannelState; //导入依赖的package包/类
@Test
public void multiple_connected_unlimited_allowed() throws Exception {
    final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);

    when(ipResourceConfiguration.isUnlimitedConnections(any(IpInterval.class))).thenReturn(true);
    when(channel.getRemoteAddress()).thenReturn(remoteAddress);

    final ChannelEvent event = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
    subject.handleUpstream(ctx, event);
    subject.handleUpstream(ctx, event);
    subject.handleUpstream(ctx, event);

    verify(ctx, times(3)).sendUpstream(event);
    verify(channel, never()).close();
    verify(channel, never()).write(anyObject());
    verify(channelFuture, never()).addListener(ChannelFutureListener.CLOSE);
}
 
开发者ID:RIPE-NCC,项目名称:whois,代码行数:18,代码来源:ConnectionPerIpLimitHandlerTest.java

示例5: multiple_connected_proxy_allowed

import org.jboss.netty.channel.ChannelState; //导入依赖的package包/类
@Test
public void multiple_connected_proxy_allowed() throws Exception {
    final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);

    when(ipResourceConfiguration.isProxy(any(IpInterval.class))).thenReturn(true);
    when(channel.getRemoteAddress()).thenReturn(remoteAddress);

    final ChannelEvent event = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
    subject.handleUpstream(ctx, event);
    subject.handleUpstream(ctx, event);
    subject.handleUpstream(ctx, event);

    verify(ctx, times(3)).sendUpstream(event);
    verify(channel, never()).close();
    verify(channel, never()).write(anyObject());
    verify(channelFuture, never()).addListener(ChannelFutureListener.CLOSE);
}
 
开发者ID:RIPE-NCC,项目名称:whois,代码行数:18,代码来源:ConnectionPerIpLimitHandlerTest.java

示例6: multiple_connected_different_ip

import org.jboss.netty.channel.ChannelState; //导入依赖的package包/类
@Test
public void multiple_connected_different_ip() throws Exception {
    final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);
    final InetSocketAddress remoteAddress2 = new InetSocketAddress("10.0.0.1", 43);
    when(channel.getRemoteAddress()).thenReturn(remoteAddress).thenReturn(remoteAddress).thenReturn(remoteAddress2);

    final ChannelEvent event = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
    subject.handleUpstream(ctx, event);
    subject.handleUpstream(ctx, event);

    final ChannelEvent event2 = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
    subject.handleUpstream(ctx, event2);

    verify(ctx, times(2)).sendUpstream(event);
    verify(ctx, times(1)).sendUpstream(event2);
    verify(channel, never()).close();
    verify(channel, never()).write(anyObject());
    verify(channelFuture, never()).addListener(ChannelFutureListener.CLOSE);
}
 
开发者ID:RIPE-NCC,项目名称:whois,代码行数:20,代码来源:ConnectionPerIpLimitHandlerTest.java

示例7: multiple_connected_same_ip_and_closed

import org.jboss.netty.channel.ChannelState; //导入依赖的package包/类
@Test
public void multiple_connected_same_ip_and_closed() throws Exception {
    final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);
    when(channel.getRemoteAddress()).thenReturn(remoteAddress);

    final ChannelEvent openEvent = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
    subject.handleUpstream(ctx, openEvent);
    subject.handleUpstream(ctx, openEvent);

    final ChannelEvent closeEvent = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.FALSE);
    subject.handleUpstream(ctx, closeEvent);
    subject.handleUpstream(ctx, closeEvent);

    subject.handleUpstream(ctx, openEvent);
    subject.handleUpstream(ctx, openEvent);

    verify(ctx, times(4)).sendUpstream(openEvent);
    verify(ctx, times(2)).sendUpstream(closeEvent);
    verify(channel, never()).close();
    verify(channel, never()).write(anyObject());
    verify(channelFuture, never()).addListener(ChannelFutureListener.CLOSE);
}
 
开发者ID:RIPE-NCC,项目名称:whois,代码行数:23,代码来源:ConnectionPerIpLimitHandlerTest.java

示例8: handleUpstream

import org.jboss.netty.channel.ChannelState; //导入依赖的package包/类
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,代码行数:21,代码来源:PNPClientFrameDecoder.java

示例9: shouldThrowExceptionIfBadHandshakeIsReceived

import org.jboss.netty.channel.ChannelState; //导入依赖的package包/类
@Test
public void shouldThrowExceptionIfBadHandshakeIsReceived() throws Exception {
    final InetSocketAddress remoteAddress = new InetSocketAddress(0);

    // start off by simulating a 'channelConnected' event
    // this should set the internal state properly
    handler.channelConnected(ctx, new UpstreamChannelStateEvent(channel, ChannelState.CONNECTED, remoteAddress));

    // we shouldn't forward the event on
    Mockito.verifyNoMoreInteractions(ctx);

    // now simulate an incoming message
    // the handler is expecting a handshake message
    // but we're going to feed it something else, and we expect an exception as a result
    ChannelBuffer badHandshakeBuffer = ChannelBuffers.wrappedBuffer(new byte[]{0, 1, 3, 4});
    expectedException.expect(IOException.class);
    handler.messageReceived(ctx, new UpstreamMessageEvent(channel, badHandshakeBuffer, remoteAddress));
}
 
开发者ID:allengeorge,项目名称:libraft,代码行数:19,代码来源:IncomingHandshakeHandlerTest.java

示例10: shouldResolveAddressAndForwardEventWhenConnectIsCalledWithAnUnresolvedInetSocketAddress

import org.jboss.netty.channel.ChannelState; //导入依赖的package包/类
@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,代码行数:24,代码来源:AddressResolverHandlerTest.java

示例11: shouldFireExceptionIfConnectEventCannotBeForwarded

import org.jboss.netty.channel.ChannelState; //导入依赖的package包/类
@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,代码行数:27,代码来源:AddressResolverHandlerTest.java

示例12: shouldPassOnProxyConnectRequestedEvent

import org.jboss.netty.channel.ChannelState; //导入依赖的package包/类
@Test
public void shouldPassOnProxyConnectRequestedEvent() throws Exception {
    ChannelFuture originalConnectFuture = Channels.future(channel);
    InetSocketAddress originalValue = new InetSocketAddress(0);

    // initiate the connect request
    handler.connectRequested(ctx, new DownstreamChannelStateEvent(channel, originalConnectFuture, ChannelState.CONNECTED, originalValue));

    // verify that a proxy event is sent instead of the original event
    ArgumentCaptor<DownstreamChannelStateEvent> downstreamEvent = ArgumentCaptor.forClass(DownstreamChannelStateEvent.class);
    verify(ctx, atLeastOnce()).getChannel();
    verify(ctx).sendDownstream(downstreamEvent.capture());
    verifyNoMoreInteractions(ctx);

    DownstreamChannelStateEvent forwardedEvent = downstreamEvent.getValue();
    assertThat(forwardedEvent.getChannel(), is(channel));
    assertThat(forwardedEvent.getFuture(), notNullValue());
    assertThat(forwardedEvent.getFuture(), not(originalConnectFuture));
    assertThat(forwardedEvent.getState(), is(ChannelState.CONNECTED));
    assertThat((InetSocketAddress) forwardedEvent.getValue(), is(originalValue));
}
 
开发者ID:allengeorge,项目名称:libraft,代码行数:22,代码来源:OutgoingHandshakeHandlerTest.java

示例13: shouldFailOriginalConnectFutureWhenProxyConnectFutureIsMarkedAsFailed

import org.jboss.netty.channel.ChannelState; //导入依赖的package包/类
@Test
public void shouldFailOriginalConnectFutureWhenProxyConnectFutureIsMarkedAsFailed() throws Exception {
    ChannelFuture originalConnectFuture = Channels.future(channel);
    InetSocketAddress originalValue = new InetSocketAddress(0);

    // initiate the connect request
    handler.connectRequested(ctx, new DownstreamChannelStateEvent(channel, originalConnectFuture, ChannelState.CONNECTED, originalValue));

    // get the proxy event
    ArgumentCaptor<DownstreamChannelStateEvent> downstreamEvent = ArgumentCaptor.forClass(DownstreamChannelStateEvent.class);
    verify(ctx, atLeastOnce()).getChannel();
    verify(ctx).sendDownstream(downstreamEvent.capture());
    verifyNoMoreInteractions(ctx);

    // mark the proxy event future as having failed
    DownstreamChannelStateEvent forwardedEvent = downstreamEvent.getValue();

    Exception failureCause = new Exception();
    forwardedEvent.getFuture().setFailure(failureCause);

    // and check that we've triggered the original future as well
    assertThat(originalConnectFuture.isDone(), equalTo(true));
    assertThat(originalConnectFuture.isSuccess(), equalTo(false));
}
 
开发者ID:allengeorge,项目名称:libraft,代码行数:25,代码来源:OutgoingHandshakeHandlerTest.java

示例14: shouldNotTriggerOriginalConnectFutureIfProxyConnectFutureSucceeds

import org.jboss.netty.channel.ChannelState; //导入依赖的package包/类
@Test
public void shouldNotTriggerOriginalConnectFutureIfProxyConnectFutureSucceeds() throws Exception {
    ChannelFuture originalConnectFuture = Channels.future(channel);
    InetSocketAddress originalValue = new InetSocketAddress(0);

    // initiate the connect request
    handler.connectRequested(ctx, new DownstreamChannelStateEvent(channel, originalConnectFuture, ChannelState.CONNECTED, originalValue));

    // get the proxy event
    ArgumentCaptor<DownstreamChannelStateEvent> downstreamEvent = ArgumentCaptor.forClass(DownstreamChannelStateEvent.class);
    verify(ctx, atLeastOnce()).getChannel();
    verify(ctx).sendDownstream(downstreamEvent.capture());

    // mark the proxy event future as having succeeded
    DownstreamChannelStateEvent forwardedEvent = downstreamEvent.getValue();
    forwardedEvent.getFuture().setSuccess();

    // and check that original future _is not triggered_ and no events are forwarded!
    assertThat(originalConnectFuture.isDone(), equalTo(false));
    verifyNoMoreInteractions(ctx);
}
 
开发者ID:allengeorge,项目名称:libraft,代码行数:22,代码来源:OutgoingHandshakeHandlerTest.java

示例15: handleUpstream

import org.jboss.netty.channel.ChannelState; //导入依赖的package包/类
/**
 * <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,代码行数:30,代码来源:ServerHandler.java


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