public interface RaftSession
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 RaftSession 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(RaftEvent) 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 |
RaftSession.State
Session state enums.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(RaftSessionEventListener listener)
Adds a state change listener to the session.
|
RaftSession.State |
getState()
Returns the session state.
|
long |
maxTimeout()
Returns the maximum session timeout.
|
MemberId |
memberId()
Returns the member identifier to which the session belongs.
|
long |
minTimeout()
Returns the minimum session timeout.
|
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(RaftEvent event)
Publishes an event to the session.
|
ReadConsistency |
readConsistency()
Returns the session's read consistency.
|
void |
removeListener(RaftSessionEventListener listener)
Removes a state change listener from the session.
|
String |
serviceName()
Returns the session's service name.
|
ServiceType |
serviceType()
Returns the session's service type.
|
SessionId |
sessionId()
Returns the session identifier.
|
default long |
timeout()
Deprecated.
|
SessionId sessionId()
String serviceName()
ServiceType serviceType()
MemberId memberId()
ReadConsistency readConsistency()
@Deprecated default long timeout()
long minTimeout()
long maxTimeout()
RaftSession.State getState()
void addListener(RaftSessionEventListener listener)
listener - the state change listener to addvoid removeListener(RaftSessionEventListener 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(RaftEvent event)
event - the event to publishCopyright © 2013–2017. All rights reserved.