public class RaftClient extends Object implements net.kuujo.catalyst.util.Managed<RaftClient>
| Modifier and Type | Class and Description |
|---|---|
static class |
RaftClient.Builder
Raft client builder.
|
| Modifier and Type | Method and Description |
|---|---|
static RaftClient.Builder |
builder(net.kuujo.catalyst.transport.Address... members)
Returns a new Raft client builder.
|
static RaftClient.Builder |
builder(Collection<net.kuujo.catalyst.transport.Address> members)
Returns a new Raft client builder.
|
CompletableFuture<Void> |
close() |
net.kuujo.catalyst.util.concurrent.Context |
context()
Returns the client execution context.
|
boolean |
isClosed() |
boolean |
isOpen() |
CompletableFuture<RaftClient> |
open() |
Session |
session()
Returns the client session.
|
<T> CompletableFuture<T> |
submit(Command<T> command)
Submits a command to the Raft cluster.
|
<T> CompletableFuture<T> |
submit(Operation<T> operation)
Submits an operation to the Raft cluster.
|
<T> CompletableFuture<T> |
submit(Query<T> query)
Submits a query to the Raft cluster.
|
public static RaftClient.Builder builder(net.kuujo.catalyst.transport.Address... members)
The provided set of members will be used to connect to the Raft cluster. The members list does not have to represent the complete list of servers in the cluster, but it must have at least one reachable member.
members - The cluster members to which to connect.public static RaftClient.Builder builder(Collection<net.kuujo.catalyst.transport.Address> members)
The provided set of members will be used to connect to the Raft cluster. The members list does not have to represent the complete list of servers in the cluster, but it must have at least one reachable member.
members - The cluster members to which to connect.public net.kuujo.catalyst.util.concurrent.Context context()
The execution context is the event loop that this client uses to communicate Raft servers.
Implementations must guarantee that all asynchronous CompletableFuture callbacks are
executed on a single thread via the returned Context.
The Context can also be used to access the Raft client's internal
serializer via Context.serializer().
public Session session()
The returned Session instance will remain constant throughout the lifetime of this client. Once the instance
is opened, the session will have been registered with the Raft cluster and listeners registered via
Session.onOpen(java.util.function.Consumer) will be called. In the event of a session expiration, listeners
registered via Session.onClose(java.util.function.Consumer) will be called.
public <T> CompletableFuture<T> submit(Operation<T> operation)
This method is provided for convenience. The submitted Operation must be an instance
of Command or Query.
T - The operation result type.operation - The operation to submit.IllegalArgumentException - If the Operation is not an instance of Command or Query.NullPointerException - if operation is nullpublic <T> CompletableFuture<T> submit(Command<T> command)
Commands are used to alter state machine state. All commands will be forwarded to the current Raft leader.
Once a leader receives the command, it will write the command to its internal Log and
replicate it to a majority of the cluster. Once the command has been replicated to a majority of the cluster, it
will apply the command to its state machine and respond with the result.
Once the command has been applied to a server state machine, the returned CompletableFuture
will be completed with the state machine output.
T - The command result type.command - The command to submit.NullPointerException - if command is nullpublic <T> CompletableFuture<T> submit(Query<T> query)
Queries are used to read state machine state. The behavior of query submissions is primarily dependent on the
query's ConsistencyLevel. For ConsistencyLevel.LINEARIZABLE
and ConsistencyLevel.LINEARIZABLE_LEASE consistency levels, queries will be forwarded
to the Raft leader. For lower consistency levels, queries are allowed to read from followers. All queries are executed
by applying queries to an internal server state machine.
Once the query has been applied to a server state machine, the returned CompletableFuture
will be completed with the state machine output.
T - The query result type.query - The query to submit.NullPointerException - if query is nullpublic CompletableFuture<RaftClient> open()
open in interface net.kuujo.catalyst.util.Managed<RaftClient>public boolean isOpen()
isOpen in interface net.kuujo.catalyst.util.Managed<RaftClient>public CompletableFuture<Void> close()
close in interface net.kuujo.catalyst.util.Managed<RaftClient>public boolean isClosed()
isClosed in interface net.kuujo.catalyst.util.Managed<RaftClient>Copyright © 2013–2015. All rights reserved.