Class ServerSessionThrottler

java.lang.Object
dev.katsute.simplehttpserver.handler.throttler.ServerSessionThrottler

public class ServerSessionThrottler extends Object
A throttler that limits the amount of simultaneous connections based on individual and total sessions.
Since:
5.0.0
Version:
5.0.0
Author:
Katsute
See Also:
  • Constructor Details

    • ServerSessionThrottler

      public ServerSessionThrottler(HttpSessionHandler sessionHandler)
      Creates a throttler with no total connection limit.
      Parameters:
      sessionHandler - session handler
      Since:
      5.0.0
      See Also:
    • ServerSessionThrottler

      public ServerSessionThrottler(HttpSessionHandler sessionHandler, int maxConnections)
      Creates a throttler with a limit on max total connections.
      Parameters:
      sessionHandler - session handler
      maxConnections - max total connections
      Since:
      5.0.0
      See Also:
  • Method Details

    • getMaxConnections

      public final int getMaxConnections(SimpleHttpExchange exchange)
      Returns the maximum number of connections allowed for an exchange. Return -1 for unlimited connections.
      Parameters:
      exchange - exchange
      Returns:
      maximum connections
      See Also:
    • getMaxConnections

      public int getMaxConnections(HttpSession session, SimpleHttpExchange exchange)
      Returns the maximum number of connections allowed for a session. Return -1 for unlimited connections.
      Parameters:
      session - session
      exchange - exchange
      Returns:
      maximum connections
      Since:
      5.0.0
      See Also:
    • canIgnoreConnectionLimit

      public boolean canIgnoreConnectionLimit(HttpSession session, SimpleHttpExchange exchange)
      If true, a session does not contribute to the total server connections and can bypass the maximum limit. Still limited by getMaxConnections(SimpleHttpExchange).
      Parameters:
      session - session
      exchange - exchange
      Returns:
      if exchange can bypass limit
      Since:
      5.0.0
      See Also:
    • setMaxServerConnections

      public final void setMaxServerConnections(int connections)
      Sets the maximum amount of server connections that is allowed.
      Parameters:
      connections - max connections
      Since:
      5.0.0
      See Also:
    • getMaxServerConnections

      public final int getMaxServerConnections()
      Returns the maximum amount of server connections that is allowed.
      Returns:
      max connections
      Since:
      5.0.0
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object