Class SessionMgr

java.lang.Object
com.iizix.comm.session.SessionMgr

public class SessionMgr extends Object
The Session Manager controls the open or dormant sessions and depending on server implementation, has a timer implementation or used the Java EE timers.
Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Default timeout before an app session is disposed of when no more client sessions are present, default 10 minutes.
    static final long
    Default heartbeat interval to keep the communication link up, 45 seconds: the default of the server setting $heartBeatInterval (ServerSettings.getClientHeartBeatInterval).
    static final long
    Default timeout before a client session is disposed when it has not processes any transactions, default 2 hours.
    static final long
    The longest heartbeat interval allowed, 5 minutes.
    static final long
    The shortest heartbeat interval allowed, 30 seconds.
    static final long
    The shortest idle time-out of a client's WebSocket link, 60 seconds, the fixed value it had before the time-out was derived from the heartbeat interval.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Gets the time-out of dormant sessions (paused/broken).
    long
    Gets the heart-beat interval in milliseconds.
    long
    Gets the idle time-out of session.
    static SessionMgr
    Gets the Session Manager singleton.
    long
    Gets the idle time-out of a client's WebSocket link, derived from the heartbeat interval in effect: max(MIN_LINK_IDLE_TIMEOUT, 2 x interval + 15 s) (WS-D-3).
    int
    Gets the maximum queued transaction to keep.
    void
    setup(long dormatTimeout, long idleTimeout, long heartBeatInterval)
    Assigns the timeouts and heartbeat interval.
  • Field Details

    • DEFAULT_IDLE_TIMEOUT

      public static final long DEFAULT_IDLE_TIMEOUT
      Default timeout before a client session is disposed when it has not processes any transactions, default 2 hours. Value in milliseconds.
      See Also:
    • DEFAULT_DORMANT_TIMEOUT

      public static final long DEFAULT_DORMANT_TIMEOUT
      Default timeout before an app session is disposed of when no more client sessions are present, default 10 minutes. Value in milliseconds.
      See Also:
    • DEFAULT_HEARTBEAT_INTERVAL

      public static final long DEFAULT_HEARTBEAT_INTERVAL
      Default heartbeat interval to keep the communication link up, 45 seconds: the default of the server setting $heartBeatInterval (ServerSettings.getClientHeartBeatInterval). Value in milliseconds.
      See Also:
    • MIN_HEARTBEAT_INTERVAL

      public static final long MIN_HEARTBEAT_INTERVAL
      The shortest heartbeat interval allowed, 30 seconds. Value in milliseconds.

      This is the one range of the heartbeat (WS-D-4): ServerSettings.getClientHeartBeatInterval clamps the configured value to MIN_HEARTBEAT_INTERVAL..MAX_HEARTBEAT_INTERVAL, and setup(long, long, long) accepts exactly that range - before, the setting allowed up to 300 seconds and the setup threw above 120, so a configured value above two minutes stopped the server at start-up.

      See Also:
    • MAX_HEARTBEAT_INTERVAL

      public static final long MAX_HEARTBEAT_INTERVAL
      The longest heartbeat interval allowed, 5 minutes. Value in milliseconds. See MIN_HEARTBEAT_INTERVAL.
      See Also:
  • Method Details

    • getInstance

      public static SessionMgr getInstance()
      Gets the Session Manager singleton.
      Returns:
      The singleton instance.
    • setup

      public void setup(long dormatTimeout, long idleTimeout, long heartBeatInterval)
      Assigns the timeouts and heartbeat interval. The new settings are taken into account directly. All values are in milliseconds.

      One INFO line names the values in effect: the heartbeat interval, the idle time-out of a client's WebSocket link derived from it, and the session idle and dormant time-outs (WS-D-6). The server calls this once at start-up, after its settings have clamped the configured values, so the line shows what runs, not what was configured.

      Parameters:
      dormatTimeout - Timeout of dormant sessions (paused/broken), 30_000 to 43_200_000.
      idleTimeout - Idle timeout of session, 120_000 to 172_800_000.
      heartBeatInterval - Heartbeat interval, MIN_HEARTBEAT_INTERVAL to MAX_HEARTBEAT_INTERVAL.
      Throws:
      IllegalArgumentException - If the values are out of range.
    • getHeartBeatInterval

      public long getHeartBeatInterval()
      Gets the heart-beat interval in milliseconds.
    • getLinkIdleTimeout

      public long getLinkIdleTimeout()
      Gets the idle time-out of a client's WebSocket link, derived from the heartbeat interval in effect: max(MIN_LINK_IDLE_TIMEOUT, 2 x interval + 15 s) (WS-D-3).

      The server's WebSocket (InternalWebSocket) sets this on every client link it opens. Jetty expires a link that moved no byte in either direction for this long. The heartbeat PING the server writes every interval is such a byte, so a link whose PINGs are written never expires, and the time-out ends a link whose PINGs can no longer be written. It is derived so that two heartbeat intervals, with the tolerance of SessionTransMgr.doTimeoutCheck, always fit inside it: with the fixed 60 seconds it had before, every interval of 60 seconds or more expired every idle client on every heartbeat, and a skipped 30 second tick raced the time-out.

      Returns:
      The time-out in milliseconds, at least MIN_LINK_IDLE_TIMEOUT.
    • getDormantTimeout

      public long getDormantTimeout()
      Gets the time-out of dormant sessions (paused/broken).

      This value is used to check if dormant sessions is allowed or not.

      Returns:
      Time-out in milliseconds, -1L for indefinite, zero for not allowed (dormant sessions not allowed).
    • getIdleTimeout

      public long getIdleTimeout()
      Gets the idle time-out of session. The idle-timeout includes dormant session time-out, i.e. when this time-out is reached, the session is disposed of.
      Returns:
      Timeout in milliseconds, -1 for indefinite (i.e. no time-out).
    • getMaxTransactionQueue

      public int getMaxTransactionQueue()
      Gets the maximum queued transaction to keep.