Class SessionInfo

java.lang.Object
com.iizix.SessionInfo
All Implemented Interfaces:
IPrivateStorage, Cloneable

public class SessionInfo extends Object implements IPrivateStorage, Cloneable
This class contains information of the remote party and its connection, etc.
Author:
Christopher Mindus
  • Field Details

    • COMMUNICATION_TRACE_INDEX

      public static final int COMMUNICATION_TRACE_INDEX
      The index for Communication trace.
      See Also:
    • CONNECTOR_TRACE_INDEX

      public static final int CONNECTOR_TRACE_INDEX
      The index for Connector trace.
      See Also:
    • ENDPOINT_TRACE_INDEX

      public static final int ENDPOINT_TRACE_INDEX
      The index for EndPoint trace.
      See Also:
    • API_TRACE_INDEX

      public static final int API_TRACE_INDEX
      The index for API trace.
      See Also:
    • TRACE_BIT_BINARY

      public static final int TRACE_BIT_BINARY
      The trace level bits.
      See Also:
    • TRACE_BIT_VERBOSE

      public static final int TRACE_BIT_VERBOSE
      The trace level bits for verbose trace.
      See Also:
    • user

      public SessionUserIdentifier user
      The session user identifier, null if not defined properly.
    • traceLevels

      public final byte[] traceLevels
      The trace levels of the subsystems Communication, Connector, EndPoint, API. The values are initially set to -1 indicating it used the default trace setting. The range of the trace is 0-3, or -1 for default.

      The values are:
      -1 = default trace,
      0 = no trace,
      1 = binary trace,
      2 = verbose trace,
      3 = binary and verbose trace.

      The indexes are:
      0 = Communication,
      1 = Connector,
      2 = EndPoint,
      3 = API.

    • creationTime

      public final long creationTime
      The creation time in milliseconds.
  • Constructor Details

    • SessionInfo

      public SessionInfo(SocketAddress remoteAddress)
      The constructor initiates the connection ID to -1 (none), the trace levels to defaults, and no User ID.
      Parameters:
      remoteAddress - The remote address of the party.
    • SessionInfo

      public SessionInfo(long connectionID, SocketAddress remoteAddress, String hostName)
      The constructor initiates the trace levels to defaults, and no User ID.
      Parameters:
      connectionID - The connection ID.
      remoteAddress - The remote address of the party.
      hostName - The host name of the remote party.
    • SessionInfo

      public SessionInfo(long connectionID, byte[] defaultTrace, SocketAddress remoteAddress, String hostName)
      The full constructor with all parameters.
      Parameters:
      connectionID - The connection ID.
      defaultTrace - The array of trace settings, non-null.
      remoteAddress - The remote address of the party.
      hostName - The host name of the remote party.
      Throws:
      NullPointerException - If defaultTrace is null.
      IllegalArgumentException - If defaultTrace is is not of length 4.
  • Method Details

    • getNextID

      public static long getNextID()
      Used to get the Session ID, used by IIZI core, terminal and test.
      Returns:
      The next unique Session ID.
    • getSessionInfo

      public static SessionInfo getSessionInfo()
      Tries to extract the SessionInfo from the current thread or the thread group.
      Returns:
      The SessionInfo instance for the current calling thread or thread group, or null if not found.
    • getSessionInfoFBTS

      public static SessionInfo getSessionInfoFBTS()
      Tries to extract the SessionInfo from the current thread or the thread group.
      Returns:
      The SessionInfo instance for the current calling thread or thread group, or the System SessionInfo if no other was found (FBS=FallBackToSystem).
    • unassignThread

      public static void unassignThread()
      Cleans up after assigning a SessionInfo object to a thread.

      This call is intended to be used with threads in thread-pools.

      This is needed to be called in order not to leak memory. When a SessionInfo object is disposed, it performs a clean-up.

    • getPrivateStorageMap

      public Map<String,Object> getPrivateStorageMap()
      Gets the concurrent hash map used to store the private data.
      Specified by:
      getPrivateStorageMap in interface IPrivateStorage
      Returns:
      The private storage map.
    • getUUID

      public UUID getUUID()
      Gets the unique session UUID for client reconnection purposes.
      Returns:
      The unique UUID.
    • getUUIDString

      public String getUUIDString()
      Gets the unique session UUID for client reconnection purposes.
      Returns:
      String The unique session UUID as UUID.toString().
    • assignRemoteAddress

      public void assignRemoteAddress(SocketAddress remoteAddress, String hostName, String domain, int port, boolean isSecure)
      Assigns a remote address.
      Parameters:
      remoteAddress - The remote address.
      hostName - The host name.
      domain - The domain name.
      port - The port number used for the connection, or zero for none specified.
      isSecure - The secure (SSL/TLS) flag.
      Throws:
      IllegalStateException - If the domain name is already set to another value.
    • assignServerSessionID

      public void assignServerSessionID(long serverSessionID)
      Assigns the connection ID for a Server Session ID.
      Parameters:
      serverSessionID - The server session ID to assign.
    • takeOverReconnection

      public void takeOverReconnection(SessionInfo link)
      Takes over the link of a completed reconnection into this instance, the SessionInfo of the session that survives it (CC-FIX-CACHESVG-RECONNECT).

      A session keeps one SessionInfo for its whole life. Everything bound to the session before the reconnection holds this instance: the thread group of its worker (whose threads find it as their ThreadData), its worker, its UUID and the private data its gyros and its runtime application stored here. The end point of the new link was constructed on the SessionInfo of the temporary reconnection session, link, and recorded there what it knows of the new link. That is copied here, and only that:

      • the remote address, host name, domain, port and secure flag, when the new link assigned a remote address;
      • the connection ID, when the new link assigned one;
      • the user, when the new link assigned one;
      • every private data entry of link, which replaces an entry of the same key here (the end point of the new link replaces the one of the old link).
      What the new link did not assign is kept. Before, the session adopted link itself, so that what was bound before the reconnection and what was bound after it lived in two different instances: a worker started before the reconnection never found a client gyro created after it, and every SVG image of the first panel was dropped (AppFactory.cacheSVG).
      Parameters:
      link - The SessionInfo of the temporary reconnection session, disposed of afterwards by the caller.
      Throws:
      NullPointerException - If link is null.
    • getRemoteAddress

      public SocketAddress getRemoteAddress()
      Gets the address of the remote party, null if none is yet provided.
      Returns:
      The address, or null if not yet assigned.
    • getHostName

      public String getHostName()
      Gets the host name, as provided by the (web) server for the connection without looking up using reverse DNS, null indicates not set.
      Returns:
      The host name, or null if not set.
    • getDomain

      public String getDomain()
      Gets the domain name of the server.
      Returns:
      The domain name.
    • getPort

      public int getPort()
      Gets the port used for the connection.
      Returns:
      The port number, or zero for none specified.
    • isSecure

      public boolean isSecure()
      Return if the connection is secured using SSL/TLS.
      Returns:
      The secure flag. Please note that if the server is behind a proxy, the connection might be secure anyway.
    • getExternalBaseURL

      public String getExternalBaseURL()
      Gets the external base URL of the session as the client reached the server: the scheme from isSecure(), the host name the Browser used (getDomain()) and the client's port (getPort()), the port omitted when it is the default of the scheme or unknown. The three are what the web server read of the connection at the WebSocket upgrade, from the request and the connector's port configuration (WSCreator, WSHelper) - never from a forwarding header or from the client's environment. A client that reaches the server directly, e.g. on http://192.168.10.100:8080, gets that address; one that comes through the front-end proxy gets the proxy's name and scheme.

      This is the one base of every absolute link the server mails for the session, e.g. the password reset link of the SignIn module, and what IUserAuthenticationUI.requestPasswordReset checks the link base it is passed against (CC-FIX-RESET-LINK-BASE).

      Returns:
      The base URL as https://host[:port] without a trailing slash, or null when the session has no domain (not a web client, or not yet connected).
    • assignThread

      public boolean assignThread()
      Temporarily assigns a SessionInfo object to a thread.

      This call is intended to be used with threads in thread-pools.

      It is very important to clean-up with a "fails-safe" try-finally or similar to call the unassignThread() method. This is needed EVEN if the thread will not be used for other purposes. Failure in doing so will cause a memory leak until this instance of SessionInfo is disposed of. It is ALSO very important to check the return code whether to call SessionInfo.unassignThread() or not.

      Returns:
      true for successfully assigned and that a call to SessionInfo.unassignThread() in the try-finally clause MUST be done, false if already assigned and SessionInfo.unassignThread() SHOULD NOT be called.
    • createClone

      public SessionInfo createClone()
      Creates a copy of an instance of this instance. This is used in the Administration Interface. The session ID and worker instances are cleared.
      Returns:
      A cloned SessionInfo instance.
    • getConnectionID

      public long getConnectionID()
      Gets the connection ID.
      Returns:
      This connection ID.
    • getConnectionIDString

      public static String getConnectionIDString(SessionInfo sessionInfo)
      Gets the connection ID as a string. If no data exists, i.e. source is null or -1, the string "<system>" is returned.
      Parameters:
      sessionInfo - The session information, or null for system.
      Returns:
      The string for the session ID in the parameter.
    • getConnectionIDString

      public static String getConnectionIDString(SessionInfo sessionInfo, String threadName, String threadID)
      Gets the connection ID as a string. If no data exists, i.e. source is null or -1, the string "<system>" is returned.
      Parameters:
      sessionInfo - The session information.
      threadName - The name of the thread.
      threadID - The thread ID.
      Returns:
      A string delimited with double spaces.
    • getTabDelimitedConnectionIDString

      public static String getTabDelimitedConnectionIDString(SessionInfo sessionInfo, String threadName, String threadID)
      Gets the connection ID as a string. If no data exists, i.e. source is null or -1, the string "<system>" is returned. The parameters are tab delimited instead of filled out with spaces.
      Parameters:
      sessionInfo - The session information.
      threadName - The name of the thread.
      threadID - The thread ID.
      Returns:
      A tab delimited string.
    • getConnectionIDString

      public String getConnectionIDString()
      Gets the connection ID as a string. If no data exists, i.e. source is -1, the string "<system>" is returned.
      Returns:
      The ID as a string or "<system>" when no ID is present.
    • getIDString

      public static String getIDString(long id)
      Converts an ID into a string.
      Parameters:
      id - The ID.
      Returns:
      The ID as a String with leading zero's.
    • doCommunicationBinaryTrace

      public boolean doCommunicationBinaryTrace()
      Checks if Communication binary trace is on.
      Returns:
      true if the trace option is selected.
    • doCommunicationVerboseTrace

      public boolean doCommunicationVerboseTrace()
      Checks if Communication verbose trace is on.
      Returns:
      true if the trace option is selected.
    • doConnectorBinaryTrace

      public boolean doConnectorBinaryTrace()
      Checks if Connector binary trace is on.
      Returns:
      true if the trace option is selected.
    • doConnectorVerboseTrace

      public boolean doConnectorVerboseTrace()
      Checks if Connector verbose trace is on.
      Returns:
      true if the trace option is selected.
    • doEndPointBinaryTrace

      public boolean doEndPointBinaryTrace()
      Checks if EndPoint binary trace is on.
      Returns:
      true if the trace option is selected.
    • doEndPointVerboseTrace

      public boolean doEndPointVerboseTrace()
      Checks if EndPoint verbose trace is on.
      Returns:
      true if the trace option is selected.
    • doAPIBinaryTrace

      public boolean doAPIBinaryTrace()
      Checks if API binary trace is on.
      Returns:
      true if the trace option is selected.
    • doAPIVerboseTrace

      public boolean doAPIVerboseTrace()
      Checks if API verbose trace is on.
      Returns:
      true if the trace option is selected.
    • setWorker

      public void setWorker(Worker worker)
      Sets the worker for the session. This can only be done once. This method should only be used internally by the server.
      Parameters:
      worker - The worker to assign to the session.
      Throws:
      NullPointerException - If worker is null.
      IllegalStateException - If a call to setWorker already has been made.
    • getWorker

      public Worker getWorker()
      Gets the worker for the session.
      Returns:
      The worker for the session or null if none is available or yet assigned.
    • getSessionID

      public SessionID getSessionID()
      Gets the session ID.
      Returns:
      The session ID or null if not set.
    • toString

      public String toString()
      Gets the string representation of the information in this instance.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the information of the session instance.
    • dispose

      public void dispose()
      Disposes of this instance and cleans up thread usage.
    • getReferenceLookupProperty

      public IGProp<?> getReferenceLookupProperty()
      Gets the Session's reference look-up property.
      Returns:
      The property to use for global look-ups with full references.