public interface RaftTransport
| Modifier and Type | Interface and Description |
|---|---|
static class |
RaftTransport.Type
The enumeration of different transport types.
|
| Modifier and Type | Method and Description |
|---|---|
void |
bind(RaftAlgorithm listener)
Register a listener for RPCs.
|
java.util.Collection<RaftAlgorithm> |
boundAlgorithms()
Get the collection of algorithms that have been bound to this transport.
|
void |
broadcastTransport(java.lang.String sender,
EloquentRaftProto.RaftMessage message)
Broadcast an RPC request over the transport to all members of the cluster.
|
default void |
broadcastTransport(java.lang.String sender,
java.lang.Object messageProto) |
static RaftTransport |
create(java.lang.String serverName,
RaftTransport.Type type)
Create a new transport of the given type.
|
Span |
expectedNetworkDelay()
The expected delay, in milliseconds, for a round-trip on this transport.
|
default <E> E |
getFuture(java.util.concurrent.CompletableFuture<E> future,
java.time.Duration timeout)
Get a future.
|
default java.lang.String |
messageType(EloquentRaftProto.RaftMessage messageProto)
For debugging, get the message type of a given message proto object.
|
static EloquentRaftProto.RaftMessage |
mkRaftMessage(java.lang.String sender,
java.lang.Object requestProto)
Create a non-blocking RPC.
|
static EloquentRaftProto.RaftMessage |
mkRaftMessage(java.lang.String sender,
java.lang.Object requestProto,
boolean isRPC)
Create an RPC request to send over the transport.
|
static EloquentRaftProto.RaftMessage |
mkRaftRPC(java.lang.String sender,
java.lang.Object requestProto)
Create a blocking RPC.
|
default long |
now()
The current (local) time on the transport.
|
void |
rpcTransport(java.lang.String sender,
java.lang.String destination,
EloquentRaftProto.RaftMessage message,
java.util.function.Consumer<EloquentRaftProto.RaftMessage> onResponseReceived,
java.lang.Runnable onTimeout,
long timeout)
Send an RPC request over the transport, expecting a reply.
|
default void |
rpcTransport(java.lang.String sender,
java.lang.String destination,
java.lang.Object message,
java.util.function.Consumer<EloquentRaftProto.RaftMessage> onResponseReceived,
java.lang.Runnable onTimeout,
long timeout) |
default <E> java.util.concurrent.CompletableFuture<E> |
rpcTransportAsFuture(java.lang.String sender,
java.lang.String destination,
java.lang.Object message,
java.util.function.BiFunction<EloquentRaftProto.RaftMessage,java.lang.Throwable,E> onResponseReceived,
java.util.function.Consumer<java.lang.Runnable> runMethod) |
default <E> java.util.concurrent.CompletableFuture<E> |
rpcTransportAsFuture(java.lang.String sender,
java.lang.String destination,
java.lang.Object message,
java.util.function.BiFunction<EloquentRaftProto.RaftMessage,java.lang.Throwable,E> onResponseReceived,
java.util.function.Consumer<java.lang.Runnable> runMethod,
long timeout) |
default void |
schedule(SafeTimerTask timerTask,
long delay)
Schedule an event every |period| seconds.
|
default void |
scheduleAtFixedRate(SafeTimerTask timerTask,
long period)
Schedule an event every |period| seconds.
|
void |
sendTransport(java.lang.String sender,
java.lang.String destination,
EloquentRaftProto.RaftMessage message)
Send an RPC request over the transport, not necessarily expecting a reply.
|
default void |
sendTransport(java.lang.String sender,
java.lang.String destination,
java.lang.Object messageProto) |
default void |
sleep(long millis)
Sleep for the given number of milliseconds.
|
default void |
start()
For unit tests primarily -- most transports don't need to be started explicitly
|
default void |
stop()
For unit tests primarily -- stop this transport and clean up if necessary.
|
default boolean |
threadsCanBlock()
If true, we are allowed to block while running on this transport.
|
void bind(RaftAlgorithm listener) throws java.io.IOException
listener - The listener that should be called on all received RPC requests.java.io.IOExceptionjava.util.Collection<RaftAlgorithm> boundAlgorithms()
void rpcTransport(java.lang.String sender,
java.lang.String destination,
EloquentRaftProto.RaftMessage message,
java.util.function.Consumer<EloquentRaftProto.RaftMessage> onResponseReceived,
java.lang.Runnable onTimeout,
long timeout)
sender - The name of the node sending the message. In many implementations, this is redundant.destination - The destination we are sending the message to.
This is a server name
on the same cluster as the node this transport is bound to.message - The message to send, as a EloquentRaftProto.RaftMessage.onResponseReceived - The callback to run when a response is received from the server
for the RPC. Either this or onTimeout is always called.onTimeout - Called when no response is received in the given timeout threshold.timeout - The number of milliseconds to wait before considering an RPC timed out.void sendTransport(java.lang.String sender,
java.lang.String destination,
EloquentRaftProto.RaftMessage message)
sender - The name of the node sending the message. In many implementations, this is redundant.destination - The destination we are sending the message to.
This is a server name
on the same cluster as the node this transport is bound to.message - The message to send, as a EloquentRaftProto.RaftMessage.void broadcastTransport(java.lang.String sender,
EloquentRaftProto.RaftMessage message)
sender - The name of the node sending the message. In many implementations, this is redundant.message - The message to send, as a EloquentRaftProto.RaftMessage.Span expectedNetworkDelay()
default void start()
default void stop()
default boolean threadsCanBlock()
default long now()
System.currentTimeMillis() if this isn't
a mock.default void sleep(long millis)
default void scheduleAtFixedRate(SafeTimerTask timerTask, long period)
SafeTimer.scheduleAtFixedRate(SafeTimerTask, long, long), but mockabledefault void schedule(SafeTimerTask timerTask, long delay)
SafeTimer.schedule(SafeTimerTask, long), but mockabledefault <E> E getFuture(java.util.concurrent.CompletableFuture<E> future,
java.time.Duration timeout)
throws java.lang.InterruptedException,
java.util.concurrent.ExecutionException,
java.util.concurrent.TimeoutException
CompletableFuture.get(long, TimeUnit).java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.util.concurrent.TimeoutExceptiondefault void sendTransport(java.lang.String sender,
java.lang.String destination,
java.lang.Object messageProto)
default void broadcastTransport(java.lang.String sender,
java.lang.Object messageProto)
default void rpcTransport(java.lang.String sender,
java.lang.String destination,
java.lang.Object message,
java.util.function.Consumer<EloquentRaftProto.RaftMessage> onResponseReceived,
java.lang.Runnable onTimeout,
long timeout)
default <E> java.util.concurrent.CompletableFuture<E> rpcTransportAsFuture(java.lang.String sender,
java.lang.String destination,
java.lang.Object message,
java.util.function.BiFunction<EloquentRaftProto.RaftMessage,java.lang.Throwable,E> onResponseReceived,
java.util.function.Consumer<java.lang.Runnable> runMethod,
long timeout)
default <E> java.util.concurrent.CompletableFuture<E> rpcTransportAsFuture(java.lang.String sender,
java.lang.String destination,
java.lang.Object message,
java.util.function.BiFunction<EloquentRaftProto.RaftMessage,java.lang.Throwable,E> onResponseReceived,
java.util.function.Consumer<java.lang.Runnable> runMethod)
static EloquentRaftProto.RaftMessage mkRaftMessage(java.lang.String sender, java.lang.Object requestProto, boolean isRPC)
requestProto - The proto of the request, which we'll wrap in a
raft request.static EloquentRaftProto.RaftMessage mkRaftMessage(java.lang.String sender, java.lang.Object requestProto)
static EloquentRaftProto.RaftMessage mkRaftRPC(java.lang.String sender, java.lang.Object requestProto)
static RaftTransport create(java.lang.String serverName, RaftTransport.Type type) throws java.io.IOException
serverName - The name of us (our server)type - The type of transport to create.java.io.IOException - Thrown if we could not create the given transport.default java.lang.String messageType(EloquentRaftProto.RaftMessage messageProto)
messageProto - A raft message, of presumably unknown type.