* It allows for notifications of client sessions starting and closing as well
* as the ability to manage client sessions (forcibly closing them etc).
*
*
* In order to perform operations that change a session's state (such as
* conflating, closing the session, or changing roles), both
* {@link GlobalPermission#VIEW_SESSION VIEW_SESSION} and
* {@link GlobalPermission#MODIFY_SESSION MODIFY_SESSION} permissions are
* required.
*
*
* When a listener is first set, it will be called with the required
* properties of all currently open client sessions. The amount of data
* transferred from the server is proportional to the number of connected
* clients and is potentially large. The amount of data can be reduced using
* the {@code requiredProperties} parameter.
*
* Each control session can register a single listener. When the listener is
* no longer required, it may be closed using the {@link Registration}
* provided by the CompletableFuture result. To change the listener, the
* previous listener must first be closed.
*
* The {@code requiredProperties} parameter is used to select the property
* values required.
*
* The requested property set controls the level of detail provided and
* whether the listener is called for updates to sessions. If no properties
* are requested, the listener is not called when session properties are
* updated.
*
* @param listener the listener to be called with session notifications
*
* @param requiredProperties a list of required property keys. See
* {@link Session} for a full list of available fixed property keys.
* To request no properties supply an empty list. To request all
* fixed properties include {@link Session#ALL_FIXED_PROPERTIES} as a
* key. In this case any other fixed property keys would be ignored.
* To request all user properties include
* {@link Session#ALL_USER_PROPERTIES} as a key. In this case any
* other user properties are ignored.
*
* @return a CompletableFuture that completes when the listener has been
* registered, returning a {@link Registration} which can be used to
* unregister the listener.
*
* Otherwise, the CompletableFuture will complete exceptionally with
* a {@link CompletionException}. Common reasons for failure, listed
* by the exception reported as the
* {@link CompletionException#getCause() cause}, include:
*
*
setSessionPropertiesListener(
SessionPropertiesStream listener,
String... requiredProperties);
/**
* Register a listener that will be notified when client sessions are
* opened, disconnected, reconnected, closed or when selected session
* property values are updated.
*
* When a listener is first set, it will be called with the required
* properties of all currently open client sessions. The amount of data
* transferred from the server is proportional to the number of connected
* clients and is potentially large. The amount of data can be reduced using
* the {@code requiredProperties} parameter.
*
* Each control session can register a single listener. (See
* {@link SessionPropertiesListener#onRegistered(Registration)}). A listener
* may be closed (using {@link Registration#close()}) if no longer required.
* To set a different listener the current listener must first be closed.
*
* The {@code requiredProperties} parameter is used to select the property
* values required.
*
* The requested property set controls the level of detail provided and
* whether the listener is called for updates to sessions. If no properties
* are requested, the listener is not called when session properties are
* updated.
*
* @param listener the listener to be called with session notifications
*
* @param requiredProperties a list of required property keys. See
* {@link Session} for a full list of available fixed property keys.
* To request no properties supply an empty list. To request all
* fixed properties include {@link Session#ALL_FIXED_PROPERTIES} as a
* key. In this case any other fixed property keys would be ignored.
* To request all user properties include
* {@link Session#ALL_USER_PROPERTIES} as a key. In this case any
* other user properties are ignored.
*
* @since 5.6
*
* @deprecated since 6.7
*
* The CompletableFuture-based alternative
* {@link #setSessionPropertiesListener(SessionPropertiesStream, String...)}
* should be preferred since it provides better error reporting.
*/
@Deprecated
void setSessionPropertiesListener(
SessionPropertiesListener listener,
String... requiredProperties);
/**
* The handler for session properties listener notifications.
*
* This is used along with
* {@link ClientControl#setSessionPropertiesListener(SessionPropertiesListener, String...)}
* to obtain notifications for client sessions.
*
* Callbacks with a {@code properties} parameter provide a map of the
* property values requested when registering the listener.
*
* @since 5.6
*
* @deprecated since 6.7
*
* Use {@link SessionPropertiesStream} instead.
*/
@Deprecated
interface SessionPropertiesListener extends ServerHandler {
/**
* Event type.
*/
enum EventType {
/**
* One or more relevant session properties have been updated.
*/
UPDATED,
/**
* Session has reconnected.
*/
RECONNECTED,
/**
* Use in a clustered configuration to indicate that the session
* failed over from another server.
*/
FAILED_OVER,
/**
* Session has disconnected.
*
* Clients that use an earlier version of the API, released before
* 5.8, will not be notified of session disconnections.
*
* @since 5.8
*/
DISCONNECTED
}
/**
* Notification that a new client session has been opened.
*
* When the listener is registered, this will be called for all existing
* sessions. It will then be called for every new session that opens
* whilst the listener is registered.
*
* This will be called for every client session regardless of requested
* session properties.
*
* @param sessionId the session identifier
*
* @param properties the map of requested session property values. This
* can be empty if no properties were requested. If a requested
* property did not exist, it will not be present in the map.
*/
void onSessionOpen(
SessionId sessionId,
Map properties);
/**
* Notification of a session event that can result in a change of
* properties.
*
* @param sessionId the client session id
*
* @param eventType indicates the type of event
*
* @param properties the map of current requested property values. This
* can be empty if no properties were requested. If a requested
* property did not exist, it will not be present in the map.
*
* @param previousValues a map of the previous values of keys that have
* changed. This will only contain keys that have changed and not
* the whole required property set. This can be empty if an event
* is being reported that did not result in the change of any of
* the required properties. When a new property is added, the
* value in this map will be null. When a property is removed, it
* will have a value in this map but not in {@code properties}.
*/
void onSessionEvent(
SessionId sessionId,
EventType eventType,
Map properties,
Map previousValues);
/**
* Notification that a client session has closed.
*
* This will be called for every client that closes whilst the listener
* is registered regardless of requested session properties.
*
* @param sessionId the session identifier of the client that has closed
*
* @param properties the map of requested property values at the point
* when the session was closed. This can be empty if no
* properties were requested. If a requested property did not
* exist, it will not be present in the map.
*
* @param closeReason why the session was closed
*/
void onSessionClose(
SessionId sessionId,
Map properties,
CloseReason closeReason);
/**
* This provides a default implementation of
* {@link SessionPropertiesListener} which will simply log session
* properties callbacks at debug level. This should only be used for
* diagnostic purposes.
*/
class Default extends ServerHandler.Default
implements SessionPropertiesListener {
private static final Logger LOG =
LoggerFactory
.getLogger(SessionPropertiesListener.Default.class);
@Override
public void onSessionOpen(
SessionId sessionId,
Map properties) {
LOG.debug(
"{} - Client session {} opened : {}",
this,
sessionId,
properties);
}
@Override
public void onSessionEvent(
SessionId sessionId,
EventType eventType,
Map properties,
Map previousValues) {
LOG.debug(
"{} - Client session {} event : {}, Properties={}, Previous Values={}",
this,
sessionId,
eventType,
properties,
previousValues);
}
@Override
public void onSessionClose(
SessionId sessionId,
Map properties,
CloseReason closeReason) {
LOG.debug(
"{} - Client session {} closed - {} : {}",
this,
sessionId,
closeReason,
properties);
}
}
}
/**
* Query the server for property values of a specified client session.
*
* @param sessionId identifies the client session
*
* @param requiredProperties a list of required property keys. See
* {@link Session} for a full list of available fixed property keys.
* To request no properties supply an empty list. To request all
* fixed properties include {@link Session#ALL_FIXED_PROPERTIES} as a
* key. In this case any other fixed property keys would be ignored.
* To request all user properties include
* {@link Session#ALL_USER_PROPERTIES} as a key. In this case any
* other user properties are ignored.
*
* @return a CompletableFuture that completes when a response is received
* from the server, returning a map of the requested session
* property values.
*
*
* If the session properties were retrieved, the CompletableFuture
* will complete successfully. The result type is a map of
* properties that were required. If no properties were selected,
* the map will be empty.
*
* Otherwise, the CompletableFuture will complete exceptionally with
* a {@link CompletionException}. Common reasons for failure, listed
* by the exception reported as the
* {@link CompletionException#getCause() cause}, include:
*
*
* - {@link NoSuchSessionException} – if the identified
* session was closed before the response was delivered;
*
*
- {@link PermissionsException} – if the calling
* session does not have the {@code VIEW_SESSION} permission;
*
*
- {@link SessionClosedException} – if the calling session
* is closed.
*
*
* @since 6.5
*/
CompletableFuture