Interface Session
SessionIdTracker
interface. Variant sessions are discarded by Variant server
after a configurable period of inactivity. Once a session has expired on the server,
most methods of this class will throw a SessionExpiredException
.- Since:
- 0.5
-
Method Summary
Modifier and TypeMethodDescriptionvoid
deleteAttributes
(String... keys) Delete one or more session attributes.This session's attributes, as they existed at the time of the most recent state refresh.The connection object, which created this session.getId()
This session's unique identifier.The experiment schema, associated with this session.Optional<? extends StateRequest>
The most recent state request, obtained by this session as returned bytargetForState(State)
.long
Session timeout interval, as set by the server.This session's creation timestamp.The set of experiments, traversed by this session.The collection of states, traversed by this session, and their respective visit counts.void
refresh()
Refresh this session's local state with the most recent remote state, which may have changed if another session with the same session ID updated the session's attributes or targeted this session for a new state.void
setAttribute
(String key, String value) Set the value of a session attribute.void
setAttributes
(Map<String, String> map) Set the values of a set of session attributes in local and remote states.targetForState
(State state) Target this session for a given state.void
triggerTraceEvent
(TraceEvent event) Trigger a custom trace event.
-
Method Details
-
getId
String getId()This session's unique identifier. Generated by Variant as a random 128-bit number converted to a hexadecimal string.
- Since:
- 0.7
-
getTimestamp
Instant getTimestamp()This session's creation timestamp.
- Since:
- 0.7
-
getConnection
Connection getConnection()The connection object, which created this session.
- Returns:
- An object of type
Connection
. - Since:
- 0.7
-
getSchema
Schema getSchema()The experiment schema, associated with this session. This is the schema's generation that was live at the time when this session was created, which may not be its current live generation.- Returns:
- An object of type
Schema
. - Since:
- 0.9
-
refresh
void refresh()Refresh this session's local state with the most recent remote state, which may have changed if another session with the same session ID updated the session's attributes or targeted this session for a new state.- Since:
- 1.3
-
getTimeoutMillis
long getTimeoutMillis()Session timeout interval, as set by the server. The server will dispose of this session after this many milliseconds of inactivity.
- Since:
- 0.7
-
getTraversedStates
The collection of states, traversed by this session, and their respective visit counts. For each state S, the visit count is incremented by one whenever the session is targeted for the state S, and there exists a experiment V, which is instrumented on state S, is online, and this session qualified for.
- Returns:
- An immutable map, whose entries are keyed by objects of type
State
, and values areInteger
visit counts of that state. - Since:
- 0.7
-
getTraversedExperiments
Set<Experiment> getTraversedExperiments()The set of experiments, traversed by this session. A experiment V is traversed by a session when the session is targeted for a state instrumented by V, V is online, and the session is qualified for V.
- Returns:
- A set of object of type
Experiment
. - Since:
- 0.7
-
getStateRequest
Optional<? extends StateRequest> getStateRequest()The most recent state request, obtained by this session as returned by
targetForState(State)
. The state request may be still in progress or already committed or failed.- Returns:
- An
Optional
, containing the most recent state request, or empty if this session has not yet been targeted for a state. - Since:
- 0.5
-
triggerTraceEvent
Trigger a custom trace event. Implicitly, refreshes this session's local state with its current remote state.- Since:
- 0.7
-
getAttributes
This session's attributes, as they existed at the time of the most recent state refresh. Guaranteed to reflect the attributes set by this session, but may differ from the remote session state, if another session with the same session ID made a concurrent update.- Returns:
- An immutable map of session's attributes.
- Since:
- 0.6
-
setAttribute
Set the value of a session attribute. Implicitly, refreshes this session's local state with its current remote state, which includes this update. If you need to update multiple session attributes,setAttributes(Map)
is a better choice as it makes only one call to Variant server.- Since:
- 1.3
-
setAttributes
Set the values of a set of session attributes in local and remote states. Implicitly, refreshes this session's local state with its current remote state, including this update.- Since:
- 1.3
-
deleteAttributes
Delete one or more session attributes. Implicitly, refreshes this session's local state with its current remote state, including this update.- Since:
- 1.3
-