public abstract class AbstractRaftService extends Object implements RaftService
| Constructor and Description |
|---|
AbstractRaftService() |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
apply(Commit<byte[]> commit)
Applies a commit to the state machine.
|
void |
init(ServiceContext context)
Initializes the state machine.
|
void |
onClose(RaftSession session)
Called when a session was closed by the client.
|
void |
onExpire(RaftSession session)
Called when a session is expired by the system.
|
void |
onOpen(RaftSession session)
Called when a new session is registered.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcloseinstall, snapshotpublic void init(ServiceContext context)
RaftServiceinit in interface RaftServicecontext - The state machine context.public byte[] apply(Commit<byte[]> commit)
RaftServiceapply in interface RaftServicecommit - the commit to applypublic void onOpen(RaftSession session)
RaftSessionListener
A session is registered when a new client connects to the cluster or an existing client recovers its
session after being partitioned from the cluster. It's important to note that when this method is called,
the RaftSession is not yet open and so events cannot be published
to the registered session. This is because clients cannot reliably track messages pushed from server state machines
to the client until the session has been fully registered. Session event messages may still be published to
other already-registered sessions in reaction to a session being registered.
To push session event messages to a client through its session upon registration, state machines can use an asynchronous callback or schedule a callback to send a message.
public void onOpen(RaftSession session) {
executor.execute(() -> session.publish("foo", "Hello world!"));
}
Sending a session event message in an asynchronous callback allows the server time to register the session
and notify the client before the event message is sent. Published event messages sent via this method will
be sent the next time an operation is applied to the state machine.onOpen in interface RaftSessionListenersession - The session that was registered. State machines cannot RaftSession.publish(io.atomix.protocols.raft.event.RaftEvent) session
events to this session.public void onExpire(RaftSession session)
RaftSessionListener
This method is called when a client fails to keep its session alive with the cluster. If the leader hasn't heard
from a client for a configurable time interval, the leader will expire the session to free the related memory.
This method will always be called for a given session before RaftSessionListener.onClose(RaftSession), and RaftSessionListener.onClose(RaftSession)
will always be called following this method.
State machines are free to RaftSession.publish(io.atomix.protocols.raft.event.RaftEvent) session event messages to any session except
the one that expired. Session event messages sent to the session that expired will be lost since the session is closed once this
method call completes.
onExpire in interface RaftSessionListenersession - The session that was expired. State machines cannot RaftSession.publish(io.atomix.protocols.raft.event.RaftEvent) session
events to this session.public void onClose(RaftSession session)
RaftSessionListenerThis method is called when a client explicitly closes a session.
State machines are free to RaftSession.publish(io.atomix.protocols.raft.event.RaftEvent) session event messages to any session except
the one that was closed. Session event messages sent to the session that was closed will be lost since the session is closed once this
method call completes.
onClose in interface RaftSessionListenersession - The session that was closed. State machines cannot RaftSession.publish(io.atomix.protocols.raft.event.RaftEvent) session
events to this session.Copyright © 2013–2017. All rights reserved.