public interface ServerSession
extends io.atomix.copycat.session.Session
Each client that connects to a Raft cluster must open a Session in order to submit operations to the cluster.
When a client first connects to a server, it must register a new session. Once the session has been registered,
it can be used to submit commands and queries
or publish 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(String, Object) 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. Copycat guarantees
that the message will eventually be received by the client unless the session itself times out or is closed.| Modifier and Type | Method and Description |
|---|---|
io.atomix.copycat.session.Session |
publish(String event)
Publishes a
null named event to the session. |
io.atomix.copycat.session.Session |
publish(String event,
Object message)
Publishes an event to the session.
|
io.atomix.copycat.session.Session publish(String event)
null named event to the session.
When an event is published via the Session, it is sent to the other side of the session's
connection. Events can only be sent from a server-side replicated state machine to a client. Attempts
to send events from the client-side of the session will result in the event being handled by the client,
Sessions guarantee serializable consistency. If an event is sent from a Raft server to a client that is
disconnected or otherwise can't receive the event, the event will be resent once the client connects to
another server as long as its session has not expired.
Event messages must be serializable. For fast serialization, message types should implement
CatalystSerializable or register a custom
TypeSerializer. Normal Java Serializable and
Externalizable are supported but not recommended.
The returned CompletableFuture will be completed once the event has been sent
but not necessarily received by the other side of the connection. In the event of a network or other
failure, the message may be resent.
event - The event to publish.NullPointerException - If event is nullio.atomix.copycat.session.ClosedSessionException - If the session is closedSerializationException - If message cannot be serializedio.atomix.copycat.session.Session publish(String event, Object message)
When an event is published via the Session, it is sent to the other side of the session's
connection. Events can only be sent from a server-side replicated state machine to a client. Attempts
to send events from the client-side of the session will result in the event being handled by the client,
Sessions guarantee serializable consistency. If an event is sent from a Raft server to a client that is
disconnected or otherwise can't receive the event, the event will be resent once the client connects to
another server as long as its session has not expired.
Event messages must be serializable. For fast serialization, message types should implement
CatalystSerializable or register a custom
TypeSerializer. Normal Java Serializable and
Externalizable are supported but not recommended.
The returned CompletableFuture will be completed once the event has been sent
but not necessarily received by the other side of the connection. In the event of a network or other
failure, the message may be resent.
event - The event to publish.message - The event message. The message must be serializable either by implementing
CatalystSerializable, providing a
TypeSerializer, or implementing Serializable.NullPointerException - If event is nullio.atomix.copycat.session.ClosedSessionException - If the session is closedSerializationException - If message cannot be serializedCopyright © 2013–2016. All rights reserved.