Interface Session


public interface Session
Variant client session. Provides a way of maintaining user state across multiple state requests. Variant sessions are managed by Variant Server and are completely distinct from those that may be provided by the host application. In order to track client sessions, Variant server relies on the host application to provide session ID tracking via an implementation of the 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 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
    • targetForState

      StateRequest targetForState(State state)

      Target this session for a given state. Implicitly, refreshes this session's local state with its current remote state.

      Returns:
      An object of type StateRequest, which may be further examined for more information about the outcome of this operation.
      Since:
      0.5
    • 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

      Map<State,Integer> 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 are Integer 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

      void triggerTraceEvent(TraceEvent event)
      Trigger a custom trace event. Implicitly, refreshes this session's local state with its current remote state.
      Since:
      0.7
    • getAttributes

      Map<String,String> 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

      void setAttribute(String key, String value)
      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

      void setAttributes(Map<String,String> map)
      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

      void deleteAttributes(String... keys)
      Delete one or more session attributes. Implicitly, refreshes this session's local state with its current remote state, including this update.
      Since:
      1.3