Class ConsoleSession

All Implemented Interfaces:
Associator, Channel, Eligible, Subchannel, IOSubchannel

The server side representation of a window in the browser that displays a console page (a console session).

An instance is created when a new console window opens the WebSocket connection to the server for the first time. If the connection between the browser and the server is lost (e.g. due to temporary network failure), the console code in the browser tries to establish a new WebSocket connection to the same, already existing ConsoleSession. The ConsoleSession object is thus independent of the WebSocket connection that handles the actual transfer of notifications.

WebConsole Session

To allow reconnection and because there is no reliable way to be notified when a window in a browser closes, Closed events from the network are ignored and ConsoleSessions remain in an open state as long as they are in use. Only if no data is received (i.e. refresh() isn’t called) for the time span configured with ConsoleWeblet.setConsoleSessionNetworkTimeout(java.time.Duration) a Closed event is fired on the channel and the console session is closed. (Method isConnected() can be used to check the connection state.) In order to keep the console connection in an open state while the session is inactive, i.e. no data is sent due to user activity, the SPA automatically generates refresh messages as configured with ConsoleWeblet.setConsoleSessionRefreshInterval(Duration).

ConsoleSession implements the IOSubchannel interface. This allows the instances to be used as channels for exchanging console session scoped events with the WebConsole component. The upstream channel (see upstreamChannel()) is the channel of the WebSocket. It may be unavailable if the connection has been interrupted and not (yet) re-established. The IOSubchannel’s response EventPipeline must be used to send events (responses) to the console session in the browser. No other event pipeline may be used for this purpose, else messages will interleave.

To avoid having too many open WebSockets with inactive sessions, a maximum inactivity time can be configured with ConsoleWeblet.setConsoleSessionInactivityTimeout(Duration). The SPA always checks if the time since the last user activity has reached or exceeded the configured limit before sending the next refresh message. In case it has, the SPA stops sending refresh messages and displays a “suspended” dialog to the user.

When the user chooses to resume, a new WebSocket is opened by the SPA. If the Session used before the idle timeout is still available (hasn’t reached its idle timeout or absolute timeout) and refers to a ConsoleSession not yet closed, then this ConsoleSession is reused, else the SPA is reloaded.

As a convenience, the ConsoleSession provides direct access to the browser session, which can usually only be obtained from the HTTP event or WebSocket channel by looking for an association of type Session.

  • Method Details

    • byConsole

      public static Set<ConsoleSession> byConsole(WebConsole console)
      Return all sessions that belong to the given console as a new unmodifiable set.
      console - the console
      the sets the
    • setTimeout

      public ConsoleSession setTimeout(long timeout)
      Changes the timeout for this ConsoleSession to the given value.
      timeout - the timeout in milli seconds
      the console session for easy chaining
    • expiresAt

      public Instant expiresAt()
      Returns the time when this session will expire.
      the instant
    • refresh

      public void refresh()
      Resets the ConsoleSession’s timeout.
    • discard

      public void discard()
      Discards this session.
    • isStale

      public boolean isStale()
      Checks if the console session has become stale (inactive).
      true, if is stale
    • isConnected

      public boolean isConnected()
      Checks if a network connection with the browser exists.
      true, if is connected
    • webletChannel

      Provides access to the weblet’s channel.
      the channel
    • setUpstreamChannel

      Sets or updates the upstream channel.

      This method should only be invoked by the creator of the ConsoleSession, by default the ConsoleWeblet.

      upstreamChannel - the upstream channel (WebSocket connection)
      the console session for easy chaining
    • setSessionSupplier

      Sets or updates associated browser session.

      This method should only be invoked by the creator of the ConsoleSession, by default the ConsoleWeblet.

      sessionSupplier - the browser session supplier
      the console session for easy chaining
    • upstreamChannel

      the upstream channel
    • browserSession

      the browserSession
    • supportedLocales

      Returns the supported locales.
      the set of locales supported by the console
    • locale

      public Locale locale()
      Return the console session’s locale.

      The locale is initialized from the browser session’s locale.

      the locale
    • setLocale

      public ConsoleSession setLocale(Locale locale)
      Sets the locale for this console session.
      locale - the locale
      the console session
    • toString

      public String toString()
      toString in class Subchannel.DefaultSubchannel