Package io.mats3.matssocket
Interface MatsSocketServer.ActiveMatsSocketSession
- All Superinterfaces:
MatsSocketServer.MatsSocketSession
- All Known Subinterfaces:
MatsSocketServer.LiveMatsSocketSession
- All Known Implementing Classes:
MatsSocketServer.ActiveMatsSocketSessionDto
- Enclosing interface:
- MatsSocketServer
public static interface MatsSocketServer.ActiveMatsSocketSession
extends MatsSocketServer.MatsSocketSession
Represents an active node-local MatsSocketSession - i.e. this instance represents a connected MatsSocketSession,
having - or just had - an open WebSocket, which by definition can only be connected to a single node. Note that
this means that in a fairly load balanced 3-node MatsSocketServer cluster, you should get approximately 1/3 of
the ActiveMatsSocketSessions residing on "this" node, while 2/3 of them will reside on the "other" two nodes.
Note: The difference between "active" and "live" is that the "active" are dumb "data transfer objects" (DTOs)
which will serialize nicely with both Mats and MatsSocket serialization mechanisms, while the "live" are an
interface to the actual live sessions in the MatsSocketServer, and as such has more information - but cannot be
(easily) serialized, and not passed as in- or out objects on Mats endpoints.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
The state of ActiveMatsSocketSession. -
Method Summary
Modifier and TypeMethodDescriptionTheAuthenticationPlugin
can set the originating remote IP address - which must be derived by headers likeX-Forwarded-For
(Wikipedia).If we have a way to find the connected (remote) address, it will be exposed here.Methods inherited from interface io.mats3.matssocket.MatsSocketServer.MatsSocketSession
getAppName, getAppVersion, getClientLibAndVersions, getMatsSocketSessionId, getNodeName, getSessionCreatedTimestamp, getSessionLivelinessTimestamp, getUserId
-
Method Details
-
getAuthorization
- Returns:
- the active Authorization value, only available when
MatsSocketServer.ActiveMatsSocketSession.MatsSocketSessionState.SESSION_ESTABLISHED
.
-
getPrincipalName
- Returns:
- The name of the Principal, as returned by
Principal.getName()
, only available whenMatsSocketServer.ActiveMatsSocketSession.MatsSocketSessionState.SESSION_ESTABLISHED
.
-
getRemoteAddr
If we have a way to find the connected (remote) address, it will be exposed here. It can be set/overridden in theAuthenticationPlugin
. Be advised that when the WebSocket Server (i.e. Servlet Container) is behind a proxy, you will get the proxy's address, not the end client's address, aka originating IP address. This can, if you add the functionality to theAuthenticationPlugin
, be gotten bygetOriginatingRemoteAddr()
. Note: The remote address is not exposed by the JSR 356 Java API for WebSockets - but there are hacks for different Servlet Containers to get it anyway. Check out classRemoteAddressContainerHacks
.- Returns:
- the remote address if available (should be an IP address).
-
getOriginatingRemoteAddr
TheAuthenticationPlugin
can set the originating remote IP address - which must be derived by headers likeX-Forwarded-For
(Wikipedia). Note the problems with this header: Since the originating client can set whatever he wants as initial value, you cannot rely on the "first IP address in the list", as this might well be bogus. You must go from the last and work your way up, and only trust the information given by proxies you are in control of: The first IP address in the list that you do not know, is what you should set as originating remote address. Each proxy adds the remote address that he sees (i.e. who is the remote address for him). This means that the last proxy's ip address is not in the list - this must be gotten bygetRemoteAddr()
.- Returns:
- the originating remote address if
AuthenticationPlugin
has set it (should be an IP address).
-
getTopicSubscriptions
- Returns:
- which Topics this session has subscribed to.
-
getSessionEstablishedTimestamp
Instant getSessionEstablishedTimestamp()- Returns:
- when this MatsSocketSession was established - this timestamp is "reset" on every
RECONNECT
(and of course set on initial connect, i.e.NEW
), as opposed toMatsSocketServer.MatsSocketSession.getSessionCreatedTimestamp()
which is set a single time when the session if first created.
-
getLastAuthenticatedTimestamp
Instant getLastAuthenticatedTimestamp()- Returns:
- timestamp (millis-since-epoch) of when we the client was last authenticated: When
AuthenticationPlugin.SessionAuthenticator.initialAuthentication(AuthenticationContext, String)
returnedAuthenticationPlugin.AuthenticationContext.authenticated(Principal, String)
, or whenAuthenticationPlugin.SessionAuthenticator.reevaluateAuthentication(AuthenticationContext, String, Principal)
returnedAuthenticationPlugin.AuthenticationContext.authenticated(Principal, String)
orAuthenticationPlugin.AuthenticationContext.stillValid()
.
-
getLastClientPingTimestamp
Instant getLastClientPingTimestamp()- Returns:
- timestamp (millis-since-epoch) of when we last received a PING message from the Client.
-
getLastActivityTimestamp
Instant getLastActivityTimestamp()- Returns:
- timestamp (millis-since-epoch) of when the Server last received an information bearing message (SEND, REQUEST, RESOLVE or REJECT) from the Client, or when the Server last sent an information bearing message (SEND, REQUEST, RESOLVE, REJECT or PUB) to the Client
-
getLastEnvelopes
List<MatsSocketServer.MatsSocketEnvelopeWithMetaDto> getLastEnvelopes()- Returns:
- snapshot (i.e. newly created ArrayList) of last 200 (per default) envelopes going between client and server in both directions.
-