@Override public boolean continueReading(UncheckedBooleanSupplier maybeMoreDataSupplier) { return config.isAutoRead() && (!respectMaybeMoreData || maybeMoreDataSupplier.get()) && totalMessages < maxMessagePerRead && totalBytesRead > 0; }
@Override public boolean continueReading(UncheckedBooleanSupplier maybeMoreDataSupplier) { return config.isAutoRead() && (!respectMaybeMoreData || maybeMoreDataSupplier.get()) && totalMessages < maxMessagePerRead && totalBytesRead > 0; }
private void readIfIsAutoRead() { if (channel.config().isAutoRead()) { channel.read(); } }
@Override public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { // We might need keep reading the channel until the full message is aggregated. // // See https://github.com/netty/netty/issues/6583 if (currentMessage != null && !ctx.channel().config().isAutoRead()) { ctx.read(); } ctx.fireChannelReadComplete(); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { final ChannelConfig config = ctx.channel().config(); if (config.isAutoRead()) { // stop accept new connections for 1 second to allow the channel to recover // See https://github.com/netty/netty/issues/1328 config.setAutoRead(false); ctx.channel().eventLoop().schedule(enableAutoReadTask, 1, TimeUnit.SECONDS); } // still let the exceptionCaught event flow through the pipeline to give the user // a chance to do something with it ctx.fireExceptionCaught(cause); } }
private void readIfIsAutoRead() { if (channel.config().isAutoRead()) { channel.read(); } }
private void readIfNeeded(ChannelHandlerContext ctx) { // If handshake is not finished yet, we need more data. if (!ctx.channel().config().isAutoRead() && (!firedChannelRead || !handshakePromise.isDone())) { // No auto-read used and no message passed through the ChannelPipeline or the handshake was not complete // yet, which means we need to trigger the read to ensure we not encounter any stalls. ctx.read(); } }
@Override public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { // We might need keep reading the channel until the full message is aggregated. // // See https://github.com/netty/netty/issues/6583 if (currentMessage != null && !ctx.channel().config().isAutoRead()) { ctx.read(); } ctx.fireChannelReadComplete(); }
@Override public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { numReads = 0; discardSomeReadBytes(); if (decodeWasNull) { decodeWasNull = false; if (!ctx.channel().config().isAutoRead()) { ctx.read(); } } ctx.fireChannelReadComplete(); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { final ChannelConfig config = ctx.channel().config(); if (config.isAutoRead()) { // stop accept new connections for 1 second to allow the channel to recover // See https://github.com/netty/netty/issues/1328 config.setAutoRead(false); ctx.channel().eventLoop().schedule(enableAutoReadTask, 1, TimeUnit.SECONDS); } // still let the exceptionCaught event flow through the pipeline to give the user // a chance to do something with it ctx.fireExceptionCaught(cause); } }
/** * Notify all the handshake futures about the successfully handshake */ private void setHandshakeSuccess() { handshakePromise.trySuccess(ctx.channel()); if (logger.isDebugEnabled()) { logger.debug("{} HANDSHAKEN: {}", ctx.channel(), engine.getSession().getCipherSuite()); } ctx.fireUserEventTriggered(SslHandshakeCompletionEvent.SUCCESS); if (readDuringHandshake && !ctx.channel().config().isAutoRead()) { readDuringHandshake = false; ctx.read(); } }
@Override public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { numReads = 0; discardSomeReadBytes(); if (decodeWasNull) { decodeWasNull = false; if (!ctx.channel().config().isAutoRead()) { ctx.read(); } } ctx.fireChannelReadComplete(); }
private void checkLimitsOnDequeue( BoltConnection connection ) { Channel channel = connection.channel(); if ( queueSize <= lowWatermark && !channel.config().isAutoRead() ) { if ( log != null ) { log.warn( "Channel [%s]: consumed messages on the worker queue below %d, auto-read is being enabled.", channel.remoteAddress(), lowWatermark ); } channel.config().setAutoRead( true ); } }
private void checkLimitsOnEnqueue( BoltConnection connection ) { Channel channel = connection.channel(); if ( queueSize > highWatermark && channel.config().isAutoRead() ) { if ( log != null ) { log.warn( "Channel [%s]: client produced %d messages on the worker queue, auto-read is being disabled.", channel.remoteAddress(), queueSize ); } channel.config().setAutoRead( false ); } }
/** * Enables auto read for a netty channel. * * @param channel the netty channel */ public static void enableAutoRead(Channel channel) { if (!channel.config().isAutoRead()) { channel.config().setAutoRead(true); channel.read(); } }
@Test public void shouldNotDisableAutoReadBelowHighWatermark() { BoltConnectionReadLimiter limiter = newLimiter( 1, 2 ); assertTrue( channel.config().isAutoRead() ); limiter.enqueued( connection, job ); assertTrue( channel.config().isAutoRead() ); verify( log, never() ).warn( anyString(), any(), any() ); }
@Test public void shouldEnableAutoReadOnlyOnceWhenBelowLowWatermark() { BoltConnectionReadLimiter limiter = newLimiter( 1, 2 ); assertTrue( channel.config().isAutoRead() ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); limiter.drained( connection, Arrays.asList( job, job, job ) ); assertTrue( channel.config().isAutoRead() ); verify( log, times( 1 ) ).warn( contains( "disabled" ), eq( channel.remoteAddress() ), eq( 3 ) ); verify( log, times( 1 ) ).warn( contains( "enabled" ), eq( channel.remoteAddress() ), eq( 1 ) ); }
@Test public void shouldEnableAutoReadWhenAtLowWatermark() { BoltConnectionReadLimiter limiter = newLimiter( 1, 2 ); assertTrue( channel.config().isAutoRead() ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); limiter.drained( connection, Arrays.asList( job, job ) ); assertTrue( channel.config().isAutoRead() ); verify( log, times( 1 ) ).warn( contains( "disabled" ), eq( channel.remoteAddress() ), eq( 3 ) ); verify( log, times( 1 ) ).warn( contains( "enabled" ), eq( channel.remoteAddress() ), eq( 1 ) ); }
@Test public void shouldDisableAutoReadWhenAtHighWatermark() { BoltConnectionReadLimiter limiter = newLimiter( 1, 2 ); assertTrue( channel.config().isAutoRead() ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); assertFalse( channel.config().isAutoRead() ); verify( log ).warn( contains( "disabled" ), eq( channel.remoteAddress() ), eq( 3 ) ); }
@Test public void shouldDisableAutoReadOnlyOnceWhenAboveHighWatermark() { BoltConnectionReadLimiter limiter = newLimiter( 1, 2 ); assertTrue( channel.config().isAutoRead() ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); assertFalse( channel.config().isAutoRead() ); verify( log, times( 1 ) ).warn( contains( "disabled" ), eq( channel.remoteAddress() ), eq( 3 ) ); }