Java Code Examples for io.netty.channel.ChannelConfig#setAutoRead()
The following examples show how to use
io.netty.channel.ChannelConfig#setAutoRead() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerBootstrap.java From arcusplatform with Apache License 2.0 | 6 votes |
@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(new Runnable() { @Override public void run() { config.setAutoRead(true); } }, 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); }
Example 2
Source File: DefaultRegistryServer.java From Jupiter with Apache License 2.0 | 6 votes |
@Override public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception { Channel ch = ctx.channel(); ChannelConfig config = ch.config(); // 高水位线: ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK // 低水位线: ChannelOption.WRITE_BUFFER_LOW_WATER_MARK if (!ch.isWritable()) { // 当前channel的缓冲区(OutboundBuffer)大小超过了WRITE_BUFFER_HIGH_WATER_MARK if (logger.isWarnEnabled()) { logger.warn("{} is not writable, high water mask: {}, the number of flushed entries that are not written yet: {}.", ch, config.getWriteBufferHighWaterMark(), ch.unsafe().outboundBuffer().size()); } config.setAutoRead(false); } else { // 曾经高于高水位线的OutboundBuffer现在已经低于WRITE_BUFFER_LOW_WATER_MARK了 if (logger.isWarnEnabled()) { logger.warn("{} is writable(rehabilitate), low water mask: {}, the number of flushed entries that are not written yet: {}.", ch, config.getWriteBufferLowWaterMark(), ch.unsafe().outboundBuffer().size()); } config.setAutoRead(true); } }
Example 3
Source File: AcceptorHandler.java From Jupiter with Apache License 2.0 | 6 votes |
@Override public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception { Channel ch = ctx.channel(); ChannelConfig config = ch.config(); // 高水位线: ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK // 低水位线: ChannelOption.WRITE_BUFFER_LOW_WATER_MARK if (!ch.isWritable()) { // 当前channel的缓冲区(OutboundBuffer)大小超过了WRITE_BUFFER_HIGH_WATER_MARK if (logger.isWarnEnabled()) { logger.warn("{} is not writable, high water mask: {}, the number of flushed entries that are not written yet: {}.", ch, config.getWriteBufferHighWaterMark(), ch.unsafe().outboundBuffer().size()); } config.setAutoRead(false); } else { // 曾经高于高水位线的OutboundBuffer现在已经低于WRITE_BUFFER_LOW_WATER_MARK了 if (logger.isWarnEnabled()) { logger.warn("{} is writable(rehabilitate), low water mask: {}, the number of flushed entries that are not written yet: {}.", ch, config.getWriteBufferLowWaterMark(), ch.unsafe().outboundBuffer().size()); } config.setAutoRead(true); } }
Example 4
Source File: ConnectorHandler.java From Jupiter with Apache License 2.0 | 6 votes |
@Override public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception { Channel ch = ctx.channel(); ChannelConfig config = ch.config(); // 高水位线: ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK // 低水位线: ChannelOption.WRITE_BUFFER_LOW_WATER_MARK if (!ch.isWritable()) { // 当前channel的缓冲区(OutboundBuffer)大小超过了WRITE_BUFFER_HIGH_WATER_MARK if (logger.isWarnEnabled()) { logger.warn("{} is not writable, high water mask: {}, the number of flushed entries that are not written yet: {}.", ch, config.getWriteBufferHighWaterMark(), ch.unsafe().outboundBuffer().size()); } config.setAutoRead(false); } else { // 曾经高于高水位线的OutboundBuffer现在已经低于WRITE_BUFFER_LOW_WATER_MARK了 if (logger.isWarnEnabled()) { logger.warn("{} is writable(rehabilitate), low water mask: {}, the number of flushed entries that are not written yet: {}.", ch, config.getWriteBufferLowWaterMark(), ch.unsafe().outboundBuffer().size()); } config.setAutoRead(true); } }
Example 5
Source File: ServerBootstrap.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
@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(new Runnable() { @Override public void run() { config.setAutoRead(true); } }, 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); }
Example 6
Source File: AbstractTrafficShapingHandler.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public void run() { Channel channel = ctx.channel(); ChannelConfig config = channel.config(); if (!config.isAutoRead() && isHandlerActive(ctx)) { // If AutoRead is False and Active is True, user make a direct setAutoRead(false) // Then Just reset the status if (logger.isDebugEnabled()) { logger.debug("Not unsuspend: " + config.isAutoRead() + ':' + isHandlerActive(ctx)); } channel.attr(READ_SUSPENDED).set(false); } else { // Anything else allows the handler to reset the AutoRead if (logger.isDebugEnabled()) { if (config.isAutoRead() && !isHandlerActive(ctx)) { logger.debug("Unsuspend: " + config.isAutoRead() + ':' + isHandlerActive(ctx)); } else { logger.debug("Normal unsuspend: " + config.isAutoRead() + ':' + isHandlerActive(ctx)); } } channel.attr(READ_SUSPENDED).set(false); config.setAutoRead(true); channel.read(); } if (logger.isDebugEnabled()) { logger.debug("Unsuspend final status => " + config.isAutoRead() + ':' + isHandlerActive(ctx)); } }
Example 7
Source File: ServerBootstrap.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@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); }
Example 8
Source File: ServerTransport.java From reactor-netty with Apache License 2.0 | 5 votes |
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { 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); }
Example 9
Source File: AbstractTrafficShapingHandler.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@Override public void run() { ChannelConfig config = ctx.channel().config(); if (!config.isAutoRead() && isHandlerActive(ctx)) { // If AutoRead is False and Active is True, user make a direct setAutoRead(false) // Then Just reset the status if (logger.isDebugEnabled()) { logger.debug("Not unsuspend: " + config.isAutoRead() + ':' + isHandlerActive(ctx)); } ctx.attr(READ_SUSPENDED).set(false); } else { // Anything else allows the handler to reset the AutoRead if (logger.isDebugEnabled()) { if (config.isAutoRead() && !isHandlerActive(ctx)) { logger.debug("Unsuspend: " + config.isAutoRead() + ':' + isHandlerActive(ctx)); } else { logger.debug("Normal unsuspend: " + config.isAutoRead() + ':' + isHandlerActive(ctx)); } } ctx.attr(READ_SUSPENDED).set(false); config.setAutoRead(true); ctx.channel().read(); } if (logger.isDebugEnabled()) { logger.debug("Unsupsend final status => " + config.isAutoRead() + ':' + isHandlerActive(ctx)); } }
Example 10
Source File: LoadControlHandler.java From tchannel-java with MIT License | 5 votes |
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { if (msg instanceof Request) { ChannelConfig config = ctx.channel().config(); if (++outstanding >= high && config.isAutoRead()) { config.setAutoRead(false); } } ctx.fireChannelRead(msg); }
Example 11
Source File: LoadControlHandler.java From tchannel-java with MIT License | 5 votes |
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { if (msg instanceof Response) { ChannelConfig config = ctx.channel().config(); if (--outstanding <= low && !config.isAutoRead()) { config.setAutoRead(true); } } ctx.write(msg, promise); }