Class NewConnectionRateLimitHandler

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
org.jivesoftware.openfire.nio.NewConnectionRateLimitHandler
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler

@Sharable public class NewConnectionRateLimitHandler extends io.netty.channel.ChannelInboundHandlerAdapter
A Netty pipeline handler that enforces a rate limit on newly accepted inbound connections. For maximum efficiency, this handler should be placed at the head of the server-side child channel pipeline (via addFirst) so that it intercepts channelActive before any other handler runs. When a new connection arrives and the rate limit is exhausted, the channel is closed immediately and the event is not propagated further, preventing all downstream handlers from performing any work (TLS negotiation, XML parser allocation, session scaffolding, etc.) for the rejected connection. Rate limits are looked up per ConnectionType from NewConnectionLimiterRegistry, which maintains one TokenBucketRateLimiter per logical connection category (e.g. C2S, S2S). Connection types that do not have an active limit configured will receive an unlimited limiter and are always passed through. This handler is ChannelHandler.Sharable because it holds no per-channel state. A single instance may be shared across all child channels created by the same server socket acceptor.
Author:
Guus der Kinderen, guus@goodbytes.nl
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

    io.netty.channel.ChannelHandler.Sharable
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    channelActive(io.netty.channel.ChannelHandlerContext ctx)
     

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

    channelInactive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, handlerAdded, handlerRemoved, isSharable

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.netty.channel.ChannelHandler

    handlerAdded, handlerRemoved
  • Constructor Details

    • NewConnectionRateLimitHandler

      public NewConnectionRateLimitHandler(@Nonnull ConnectionType connectionType)
  • Method Details

    • channelActive

      public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      channelActive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelActive in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception