本文整理汇总了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);
}
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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);
}
示例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);
}