/** * Writes one message to the inbound of this {@link Channel} and does not flush it. This * method is conceptually equivalent to {@link #write(Object, ChannelPromise)}. * * @see #writeOneOutbound(Object, ChannelPromise) */ public ChannelFuture writeOneInbound(Object msg, ChannelPromise promise) { if (checkOpen(true)) { pipeline().fireChannelRead(msg); } return checkException(promise); }
private void setup(boolean register, final ChannelHandler... handlers) { ObjectUtil.checkNotNull(handlers, "handlers"); ChannelPipeline p = pipeline(); p.addLast(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); for (ChannelHandler h: handlers) { if (h == null) { break; } pipeline.addLast(h); } } }); if (register) { ChannelFuture future = loop.register(this); assert future.isDone(); } }
/** * Writes one message to the inbound of this {@link Channel} and does not flush it. This * method is conceptually equivalent to {@link #write(Object, ChannelPromise)}. * * @see #writeOneOutbound(Object, ChannelPromise) */ public ChannelFuture writeOneInbound(Object msg, ChannelPromise promise) { if (checkOpen(true)) { pipeline().fireChannelRead(msg); } return checkException(promise); }
private void setup(boolean register, final ChannelHandler... handlers) { ObjectUtil.checkNotNull(handlers, "handlers"); ChannelPipeline p = pipeline(); p.addLast(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); for (ChannelHandler h: handlers) { if (h == null) { break; } pipeline.addLast(h); } } }); if (register) { ChannelFuture future = loop.register(this); assert future.isDone(); } }
private ChannelFuture flushInbound(boolean recordException, ChannelPromise promise) { if (checkOpen(recordException)) { pipeline().fireChannelReadComplete(); runPendingTasks(); } return checkException(promise); }
/** * Writes one message to the inbound of this {@link Channel} and does not flush it. This * method is conceptually equivalent to {@link #write(Object, ChannelPromise)}. * * @see #writeOneOutbound(Object, ChannelPromise) */ public ChannelFuture writeOneInbound(Object msg, ChannelPromise promise) { if (checkOpen(true)) { pipeline().fireChannelRead(msg); } return checkException(promise); }
private ChannelFuture flushInbound(boolean recordException, ChannelPromise promise) { if (checkOpen(recordException)) { pipeline().fireChannelReadComplete(); runPendingTasks(); } return checkException(promise); }
private ChannelFuture flushInbound(boolean recordException, ChannelPromise promise) { if (checkOpen(recordException)) { pipeline().fireChannelReadComplete(); runPendingTasks(); } return checkException(promise); }
@Test public void shouldNotPropagateExceptionCaught() throws Exception { ChannelInboundHandler next = mock( ChannelInboundHandler.class ); BoltConnection connection = mock( BoltConnection.class ); channel = new EmbeddedChannel( new HouseKeeper( connection, NullLog.getInstance() ), next ); channel.pipeline().fireExceptionCaught( new RuntimeException( "some exception" ) ); verify( next, never() ).exceptionCaught( any(), any() ); }
/** * Write messages to the inbound of this {@link Channel}. * * @param msgs the messages to be written * * @return {@code true} if the write operation did add something to the inbound buffer */ public boolean writeInbound(Object... msgs) { ensureOpen(); if (msgs.length == 0) { return isNotEmpty(inboundMessages); } ChannelPipeline p = pipeline(); for (Object m: msgs) { p.fireChannelRead(m); } flushInbound(false, voidPromise()); return isNotEmpty(inboundMessages); }
@Test public void shouldInstallChannelHandlersInCorrectOrder() throws Throwable { // Given BoltChannel boltChannel = newBoltChannel( channel ); BoltConnectionFactory connectionFactory = mock( BoltConnectionFactory.class ); when( connectionFactory.newConnection( eq( boltChannel ), any() ) ).thenReturn( mock( BoltConnection.class ) ); BoltProtocol boltProtocol = new BoltProtocolV1( boltChannel, connectionFactory, mock( BoltStateMachineFactory.class ), NullLogService.getInstance() ); // When boltProtocol.install(); Iterator<Map.Entry<String,ChannelHandler>> handlers = channel.pipeline().iterator(); assertThat( handlers.next().getValue(), instanceOf( ChunkDecoder.class ) ); assertThat( handlers.next().getValue(), instanceOf( MessageAccumulator.class ) ); assertThat( handlers.next().getValue(), instanceOf( MessageDecoder.class ) ); assertThat( handlers.next().getValue(), instanceOf( HouseKeeper.class ) ); assertFalse( handlers.hasNext() ); }
@Test public void shouldNotPropagateChannelInactive() throws Exception { ChannelInboundHandler next = mock( ChannelInboundHandler.class ); BoltConnection connection = mock( BoltConnection.class ); channel = new EmbeddedChannel( new HouseKeeper( connection, NullLog.getInstance() ), next ); channel.pipeline().fireChannelInactive(); verify( next, never() ).channelInactive( any() ); }
public void appendTransformer(AllocatingTransformer transformer) { @SuppressWarnings({"rawtypes", "unchecked"}) AppendTransformerEvent event = new AppendTransformerEvent(transformer); channel.pipeline().fireUserEventTriggered(event); } }
@Test(timeout = 60000) public void testShouldReadMoreOnUnsubscribe() throws Exception { producerRule.producer.request(1); assertThat("Unexpected requested count.", producerRule.producer.getRequested(), is(1L)); assertThat("Unexpected read more status.", producerRule.producer.shouldReadMore(producerRule.channel.pipeline().firstContext()), is(true)); producerRule.subscriber.unsubscribe(); assertThat("Unexpected read more status.", producerRule.producer.shouldReadMore(producerRule.channel.pipeline().firstContext()), is(false)); }
/** * Write messages to the inbound of this {@link Channel}. * * @param msgs the messages to be written * * @return {@code true} if the write operation did add something to the inbound buffer */ public boolean writeInbound(Object... msgs) { ensureOpen(); if (msgs.length == 0) { return isNotEmpty(inboundMessages); } ChannelPipeline p = pipeline(); for (Object m: msgs) { p.fireChannelRead(m); } flushInbound(false, voidPromise()); return isNotEmpty(inboundMessages); }
@Test public void shouldStopConnectionOnExceptionCaught() { BoltConnection connection = mock( BoltConnection.class ); channel = new EmbeddedChannel( new HouseKeeper( connection, NullLog.getInstance() ) ); channel.pipeline().fireExceptionCaught( new RuntimeException( "some exception" ) ); verify( connection ).stop(); }
@Test void shouldInstallTransportSelectionHandler() { SocketTransport socketTransport = newSocketTransport( NetworkConnectionTracker.NO_OP, NO_THROTTLE ); EmbeddedChannel channel = new EmbeddedChannel( socketTransport.channelInitializer() ); TransportSelectionHandler handler = channel.pipeline().get( TransportSelectionHandler.class ); assertNotNull( handler ); }
public void requestMessages(long requested) throws Exception { handler.incrementRequested(requested); channel.pipeline().fireUserEventTriggered(new RequestReadIfRequiredEvent() { @Override protected boolean shouldReadMore(ChannelHandlerContext ctx) { return true; } }); channel.runPendingTasks(); }
@Test public void shouldStopConnectionOnChannelInactive() { BoltConnection connection = mock( BoltConnection.class ); channel = new EmbeddedChannel( new HouseKeeper( connection, NullLog.getInstance() ) ); channel.pipeline().fireChannelInactive(); verify( connection ).stop(); }
@Test public void shouldLogExceptionOnExceptionCaught() { AssertableLogProvider logProvider = new AssertableLogProvider(); BoltConnection connection = mock( BoltConnection.class ); channel = new EmbeddedChannel( new HouseKeeper( connection, logProvider.getLog( HouseKeeper.class ) ) ); RuntimeException exception = new RuntimeException( "some exception" ); channel.pipeline().fireExceptionCaught( exception ); verify( connection ).stop(); logProvider.assertExactly( inLog( HouseKeeper.class ).error( startsWith( "Fatal error occurred when handling a client connection" ), equalTo( exception ) ) ); }