public interface Session
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. Session implementations guarantee linearizability for session messages by coordinating between
the client and a single server at any given time. This means messages published
via the Session are guaranteed to arrive on the other side of the connection exactly once and in the order
in which they are sent by replicated state machines. In the event of a server-to-client message being lost, the
message will be resent so long as at least one Raft server is able to communicate with the client and the client's
session does not expire while switching between servers.
Messages are sent to the other side of the session using the publish(PrimitiveEvent) method:
session.publish("myEvent", "Hello world!");
When the message is published, it will be queued to be sent to the other side of the connection. Raft guarantees
that the message will eventually be received by the client unless the session itself times out or is closed.| Modifier and Type | Interface and Description |
|---|---|
static class |
Session.State
Session state enums.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(SessionEventListener listener)
Adds a state change listener to the session.
|
Session.State |
getState()
Returns the session state.
|
io.atomix.cluster.NodeId |
nodeId()
Returns the node identifier to which the session belongs.
|
default void |
publish(EventType eventType)
Publishes an empty event to the session.
|
default void |
publish(EventType eventType,
byte[] event)
Publishes an event to the session.
|
default <T> void |
publish(EventType eventType,
Function<T,byte[]> encoder,
T event)
Publishes an event to the session.
|
void |
publish(PrimitiveEvent event)
Publishes an event to the session.
|
void |
removeListener(SessionEventListener listener)
Removes a state change listener from the session.
|
String |
serviceName()
Returns the session's service name.
|
PrimitiveType |
serviceType()
Returns the session's service type.
|
SessionId |
sessionId()
Returns the session identifier.
|
SessionId sessionId()
String serviceName()
PrimitiveType serviceType()
io.atomix.cluster.NodeId nodeId()
Session.State getState()
void addListener(SessionEventListener listener)
listener - the state change listener to addvoid removeListener(SessionEventListener listener)
listener - the state change listener to removedefault void publish(EventType eventType)
eventType - the event typedefault <T> void publish(EventType eventType, Function<T,byte[]> encoder, T event)
T - the event typeeventType - the event identifierencoder - the event value encoderevent - the event valuedefault void publish(EventType eventType, byte[] event)
eventType - the event identifierevent - the event to publishNullPointerException - if the event is nullvoid publish(PrimitiveEvent event)
event - the event to publishCopyright © 2013–2018. All rights reserved.