public interface Session
Each client that connects to a Raft cluster must open a Session in order to submit operations to the cluster.
When a client first connects to a server, it must register a new session. Once the session has been registered,
it can be used to submit commands and queries
to the cluster.
Sessions represent a connection between a single client and all servers in a Raft cluster. Session information is replicated via the Raft consensus algorithm, and clients can safely switch connections between servers without losing their session. All consistency guarantees are provided within the context of a session. Once a session is expired or closed, linearizability, sequential consistency, and other guarantees for events and operations are effectively lost.
Throughout the lifetime of a session it can transition between a number of different
states. Session states are indicative of the client's ability to
maintain its connections to the cluster and the cluster's ability to provide certain semantics within the context
of the session. The current state of a session can be read via the state() method, and users can react to
changes in the session state by registering a state change listener via onStateChange(Consumer).
The ideal state of a session is the OPEN state which indicates that the client has
registered a session and has successfully submitted a keep-alive request within the last session timeout. In the
event that a client cannot communicate with any server in the cluster or the cluster has not received a keep-alive
from a client within a session timeout, the session's state will be changed to UNSTABLE,
indicating that the session may be expired. While in the UNSTABLE state, Copycat cannot guarantee linearizable
semantics for operations. From the UNSTABLE state, the session will either transition back to the
OPEN state or into the EXPIRED state, indicating that linearizability guarantees
have been lost. Finally, sessions that are explicitly unregistered by a client will be transitioned to the
CLOSED state.
| Modifier and Type | Interface and Description |
|---|---|
static class |
Session.State
Represents the state of a session.
|
| Modifier and Type | Method and Description |
|---|---|
long |
id()
Returns the session ID.
|
Listener<Session.State> |
onStateChange(Consumer<Session.State> callback)
Registers a callback to be called when the session state changes.
|
Session.State |
state()
Returns the current session state.
|
long id()
The session ID is unique to an individual session within the cluster. That is, it is guaranteed that no two clients will have a session with the same ID.
Session.State state()
Listener<Session.State> onStateChange(Consumer<Session.State> callback)
callback - The callback to be called when the session state changes.Copyright © 2013–2016. All rights reserved.