Class ConnectionLimitHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
com.linkedin.alpini.netty4.handlers.ConnectionLimitHandler
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler
- Direct Known Subclasses:
ConnectionControlHandler
@Sharable
public class ConnectionLimitHandler
extends io.netty.channel.ChannelInboundHandlerAdapter
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Field Summary
FieldsModifier and TypeFieldDescription -
Constructor Summary
ConstructorsConstructorDescriptionConnectionLimitHandler(IntSupplier limit, Consumer<Integer> connectionCountRecorder, Consumer<Integer> rejectedConnectionCountRecorder) Construct with a preset connection limit. -
Method Summary
Modifier and TypeMethodDescriptionvoidchannelActive(io.netty.channel.ChannelHandlerContext ctx) CallsChannelHandlerContext.fireChannelActive()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidchannelInactive(io.netty.channel.ChannelHandlerContext ctx) CallsChannelHandlerContext.fireChannelInactive()to forward to the nextChannelInboundHandlerin theChannelPipeline.intReturn the current number of connections.intReturn the current connection limit.voidsetConnectionLimit(int limit) Set the maximum number of connections.Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Field Details
-
_connectionCountRecorder
-
_rejectedConnectionCountRecorder
-
-
Constructor Details
-
ConnectionLimitHandler
public ConnectionLimitHandler(IntSupplier limit, Consumer<Integer> connectionCountRecorder, Consumer<Integer> rejectedConnectionCountRecorder) Construct with a preset connection limit.- Parameters:
limit- Maximum number of connections.
-
-
Method Details
-
getConnectedCount
public int getConnectedCount()Return the current number of connections.- Returns:
- number of connections.
-
setConnectionLimit
public void setConnectionLimit(int limit) Set the maximum number of connections.- Parameters:
limit- new connection limit.
-
getConnectionLimit
public int getConnectionLimit()Return the current connection limit.- Returns:
- number of connections.
-
channelActive
CallsChannelHandlerContext.fireChannelActive()to forward to the nextChannelInboundHandlerin theChannelPipeline.Sub-classes may override this method to change behavior.
- Specified by:
channelActivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelActivein classio.netty.channel.ChannelInboundHandlerAdapter- Parameters:
ctx-- Throws:
Exception
-
channelInactive
CallsChannelHandlerContext.fireChannelInactive()to forward to the nextChannelInboundHandlerin theChannelPipeline.Sub-classes may override this method to change behavior.
- Specified by:
channelInactivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelInactivein classio.netty.channel.ChannelInboundHandlerAdapter- Parameters:
ctx-- Throws:
Exception
-