Interface Session<C>
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.-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classSession.StateSession state enums. -
Method Summary
Modifier and Type Method Description voidaccept(java.util.function.Consumer<C> event)Sends an event to the client via the client proxy.Session.StategetState()Returns the session state.io.atomix.cluster.MemberIdmemberId()Returns the member identifier to which the session belongs.StringprimitiveName()Returns the session's service name.PrimitiveTypeprimitiveType()Returns the session's service type.default voidpublish(EventType eventType)Publishes an empty event to the session.<T> voidpublish(EventType eventType, T event)Publishes an event to the session.voidpublish(PrimitiveEvent event)Publishes an event to the session.SessionIdsessionId()Returns the session identifier.
-
Method Details
-
sessionId
SessionId sessionId()Returns the session identifier.- Returns:
- The session identifier.
-
primitiveName
String primitiveName()Returns the session's service name.- Returns:
- The session's service name.
-
primitiveType
PrimitiveType primitiveType()Returns the session's service type.- Returns:
- The session's service type.
-
memberId
io.atomix.cluster.MemberId memberId()Returns the member identifier to which the session belongs.- Returns:
- The member to which the session belongs.
-
getState
Session.State getState()Returns the session state.- Returns:
- The session state.
-
publish
Publishes an empty event to the session.- Parameters:
eventType- the event type
-
publish
Publishes an event to the session.- Type Parameters:
T- the event type- Parameters:
eventType- the event identifierevent- the event value
-
publish
Publishes an event to the session.- Parameters:
event- the event to publish
-
accept
Sends an event to the client via the client proxy.- Parameters:
event- the client proxy operation
-