Class ConnectionThrottleFilter

java.lang.Object
org.apache.mina.core.filterchain.IoFilterAdapter
org.apache.mina.filter.firewall.ConnectionThrottleFilter
All Implemented Interfaces:
IoFilter

public class ConnectionThrottleFilter extends IoFilterAdapter
A IoFilter which blocks connections from connecting at a rate faster than the specified interval.
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
      A logger for this class
    • DEFAULT_TIME

      private static final long DEFAULT_TIME
      The default delay to wait for a session to be accepted again
      See Also:
    • allowedInterval

      private long allowedInterval
      The minimal delay the sessions will have to wait before being created again
    • clients

      private final Map<String,Long> clients
      The map of created sessiosn, associated with the time they were created
    • lock

      private Lock lock
      A lock used to protect the map from concurrent modifications
  • Constructor Details

    • ConnectionThrottleFilter

      public ConnectionThrottleFilter()
      Default constructor. Sets the wait time to 1 second
    • ConnectionThrottleFilter

      public ConnectionThrottleFilter(long allowedInterval)
      Constructor that takes in a specified wait time.
      Parameters:
      allowedInterval - The number of milliseconds a client is allowed to wait before making another successful connection
  • Method Details

    • setAllowedInterval

      public void setAllowedInterval(long allowedInterval)
      Sets the interval between connections from a client. This value is measured in milliseconds.
      Parameters:
      allowedInterval - The number of milliseconds a client is allowed to wait before making another successful connection
    • isConnectionOk

      protected boolean isConnectionOk(IoSession session)
      Method responsible for deciding if a connection is OK to continue
      Parameters:
      session - The new session that will be verified
      Returns:
      True if the session meets the criteria, otherwise false
    • sessionCreated

      public void sessionCreated(IoFilter.NextFilter nextFilter, IoSession session) throws Exception
      Description copied from class: IoFilterAdapter
      Specified by:
      sessionCreated in interface IoFilter
      Overrides:
      sessionCreated in class IoFilterAdapter
      Parameters:
      nextFilter - the IoFilter.NextFilter for this filter. You can reuse this object until this filter is removed from the chain.
      session - The IoSession which has received this event
      Throws:
      Exception - If an error occurred while processing the event