Package com.variant.client
Interface Connection
public interface Connection
Connection to a particular experiment schema on a Variant server established by
VariantClient.connectTo(String)
.
Variant connections are stateless, i.e. no information about this connection is retained on the server.
New sessions are created against the live generation of the experiment schema named in the connection. If no
such schema exists on the server, the UnknownSchemaException
is thrown.- Since:
- 0.7
-
Method Summary
Modifier and TypeMethodDescriptionThe Variant client instance, which created this connection.getOrCreateSession
(Object userData, Optional<String> ownerId) Get, if exists, or create, if does not exist, a Variant session with the externally tracked ID.The name of the schema which is the target of this connection.getSession
(Object userData) Get, if exists, the Variant session with the externally tracked ID.getSessionById
(String sessionId) Get, if exists, the Variant session by its ID.
-
Method Details
-
getClient
VariantClient getClient()The Variant client instance, which created this connection.
- Returns:
- An instance of the
VariantClient
object, which originally created this connection withVariantClient.connectTo(String)
. - Since:
- 0.7
-
getOrCreateSession
Get, if exists, or create, if does not exist, a Variant session with the externally tracked ID. If the session with the ID tracked by the customsession ID tracker
was found on the server, it is returned. Otherwise, a new session with a new session ID is created and the session ID tracker is reset to track the new ID.- Parameters:
userData
- An opaque object which is passed, without interpretation, to the constructor of the user suppliedsession ID tracker
.ownerId
- AnOptional
containing an arbitrary string uniquely identifying the user actor, or empty if user actor is unknown.- Returns:
- An object of type
Session
.
-
getSession
Get, if exists, the Variant session with the externally tracked ID. If the session with the ID tracked by the customsession ID tracker
was found on the server, it is returned, wrapped inOptional
. Otherwise, an emptyOptional
is returned.- Parameters:
userData
- An opaque object which is passed, without interpretation, to the constructor of the user suppliedsession ID tracker
.- Returns:
- An
Optional
, containing theSession
object if the session exists on Variant server, or empty otherwise. - Since:
- 0.7
-
getSessionById
Get, if exists, the Variant session by its ID. Intended for downstream components of the host application, which do not implement an external session ID tracker, but rely on the upstream to create Variant session and pass down its ID. -
getSchemaName
String getSchemaName()The name of the schema which is the target of this connection. Note that only schema name is retained at the connection level. Individual sessions created with this connection object, will be bound to those generations of this schema which were live at the time of session creation.- Since:
- 0.9
-