Interface Session<C>


public interface Session<C>
Provides an interface to communicating with a client via session events.

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 class  Session.State
    Session state enums.
  • Method Summary

    Modifier and Type Method Description
    void accept​(java.util.function.Consumer<C> event)
    Sends an event to the client via the client proxy.
    Session.State getState()
    Returns the session state.
    io.atomix.cluster.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.
  • 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

      default void publish​(EventType eventType)
      Publishes an empty event to the session.
      Parameters:
      eventType - the event type
    • publish

      <T> void publish​(EventType eventType, T event)
      Publishes an event to the session.
      Type Parameters:
      T - the event type
      Parameters:
      eventType - the event identifier
      event - the event value
    • publish

      void publish​(PrimitiveEvent event)
      Publishes an event to the session.
      Parameters:
      event - the event to publish
    • accept

      void accept​(java.util.function.Consumer<C> event)
      Sends an event to the client via the client proxy.
      Parameters:
      event - the client proxy operation