Class ConsoleSession
- All Implemented Interfaces:
Associator
,Channel
,Eligible
,Subchannel
,IOSubchannel
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.
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 ConsoleSession
s
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
.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default
Nested classes/interfaces inherited from interface org.jgrapes.io.IOSubchannel
IOSubchannel.DefaultIOSubchannel
Nested classes/interfaces inherited from interface org.jgrapes.core.Subchannel
Subchannel.DefaultSubchannel
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Set<ConsoleSession>
byConsole
(WebConsole console) Return all sessions that belong to the given console as a new unmodifiable set.void
discard()
Discards this session.Returns the time when this session will expire.boolean
Checks if a network connection with the browser exists.boolean
isStale()
Checks if the console session has become stale (inactive).locale()
Return the console session’s locale.void
refresh()
Resets theConsoleSession
’s timeout.Sets the locale for this console session.setSessionSupplier
(Supplier<Optional<Session>> sessionSupplier) Sets or updates associated browser session.setTimeout
(long timeout) Changes the timeout for thisConsoleSession
to the given value.setUpstreamChannel
(IOSubchannel upstreamChannel) Sets or updates the upstream channel.Returns the supported locales.toString()
Provides access to the weblet’s channel.Methods inherited from class org.jgrapes.io.IOSubchannel.DefaultIOSubchannel
byteBufferPool, charBufferPool, responsePipeline, setByteBufferPool, setCharBufferPool
Methods inherited from class org.jgrapes.core.Subchannel.DefaultSubchannel
associated, mainChannel, setAssociated
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.jgrapes.core.Associator
associated, associated, associated, associated, associatedGet, setAssociated
Methods inherited from interface org.jgrapes.io.IOSubchannel
respond
Methods inherited from interface org.jgrapes.core.Subchannel
defaultCriterion, isEligibleFor, mainChannel
-
Method Details
-
byConsole
Return all sessions that belong to the given console as a new unmodifiable set.- Parameters:
console
- the console- Returns:
- the sets the
-
setTimeout
Changes the timeout for thisConsoleSession
to the given value.- Parameters:
timeout
- the timeout in milli seconds- Returns:
- the console session for easy chaining
-
expiresAt
Returns the time when this session will expire.- Returns:
- the instant
-
refresh
Resets theConsoleSession
’s timeout. -
discard
Discards this session. -
isStale
Checks if the console session has become stale (inactive).- Returns:
- true, if is stale
-
isConnected
Checks if a network connection with the browser exists.- Returns:
- true, if is connected
-
webletChannel
Provides access to the weblet’s channel.- Returns:
- the channel
-
setUpstreamChannel
Sets or updates the upstream channel.This method should only be invoked by the creator of the
ConsoleSession
, by default theConsoleWeblet
.- Parameters:
upstreamChannel
- the upstream channel (WebSocket connection)- Returns:
- 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 theConsoleWeblet
.- Parameters:
sessionSupplier
- the browser session supplier- Returns:
- the console session for easy chaining
-
upstreamChannel
- Returns:
- the upstream channel
-
browserSession
- Returns:
- the browserSession
-
supportedLocales
Returns the supported locales.- Returns:
- the set of locales supported by the console
-
locale
Return the console session’s locale.The locale is initialized from the browser session’s locale.
- Returns:
- the locale
-
setLocale
Sets the locale for this console session.- Parameters:
locale
- the locale- Returns:
- the console session
-
toString
- Overrides:
toString
in classSubchannel.DefaultSubchannel
-