public interface Session<C>
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 |
accept(Consumer<C> event)
Sends an event to the client via the client proxy.
|
Session.State |
getState()
Returns the session state.
|
MemberId |
memberId()
Returns the member identifier to which the session belongs.
|
String |
primitiveName()
Returns the session's service name.
|
PrimitiveType |
primitiveType()
Returns the session's service type.
|
default void |
publish(EventType eventType)
Publishes an empty event to the session.
|
<T> void |
publish(EventType eventType,
T event)
Publishes an event to the session.
|
void |
publish(PrimitiveEvent event)
Publishes an event to the session.
|
SessionId |
sessionId()
Returns the session identifier.
|
SessionId sessionId()
String primitiveName()
PrimitiveType primitiveType()
MemberId memberId()
Session.State getState()
default void publish(EventType eventType)
eventType - the event type<T> void publish(EventType eventType, T event)
T - the event typeeventType - the event identifierevent - the event valuevoid publish(PrimitiveEvent event)
event - the event to publishCopyright © 2013–2018. All rights reserved.