Class 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 Detail

      • 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:
        Constant Field Values
      • allowedInterval

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

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

        private java.util.concurrent.locks.Lock lock
        A lock used to protect the map from concurrent modifications
    • Constructor Detail

      • 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 Detail

      • 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