public class NetRaftTransport extends java.lang.Object implements RaftTransport
RaftTransport.Type| Modifier and Type | Field and Description |
|---|---|
java.lang.String |
serverName
The name we should assign ourselves on the transport.
|
boolean |
thread
If true, run the handling of messages on the transport in a new thread.
|
| Constructor and Description |
|---|
NetRaftTransport(java.lang.String serverName) |
NetRaftTransport(java.lang.String serverName,
int rpcListenPort,
boolean async)
Create a UDP transport.
|
| 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.
|
Span |
expectedNetworkDelay()
The expected delay, in milliseconds, for a round-trip on this 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.
|
void |
schedule(SafeTimerTask timerTask,
long delay)
Schedule an event every |period| seconds.
|
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.
|
java.lang.String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitbroadcastTransport, create, getFuture, messageType, mkRaftMessage, mkRaftMessage, mkRaftRPC, now, rpcTransport, rpcTransportAsFuture, rpcTransportAsFuture, sendTransport, sleep, start, stop, threadsCanBlockpublic final java.lang.String serverName
public final boolean thread
public NetRaftTransport(java.lang.String serverName,
int rpcListenPort,
boolean async)
throws java.io.IOException
serverName - The name of our serverrpcListenPort - The gRPC port to listen on.async - If true, run messages on the transport in separate threads.java.net.UnknownHostException - Thrown if we could not get our own hostname.java.io.IOExceptionpublic NetRaftTransport(java.lang.String serverName)
throws java.io.IOException
java.io.IOExceptionNetRaftTransport(String, int, boolean)public void scheduleAtFixedRate(SafeTimerTask timerTask, long period)
SafeTimer.scheduleAtFixedRate(SafeTimerTask, long, long), but mockablescheduleAtFixedRate in interface RaftTransportpublic void schedule(SafeTimerTask timerTask, long delay)
SafeTimer.schedule(SafeTimerTask, long), but mockableschedule in interface RaftTransportpublic void bind(RaftAlgorithm listener)
bind in interface RaftTransportlistener - The listener that should be called on all received RPC requests.public java.util.Collection<RaftAlgorithm> boundAlgorithms()
boundAlgorithms in interface RaftTransportpublic 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)
rpcTransport in interface RaftTransportsender - 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.public void sendTransport(java.lang.String sender,
java.lang.String destination,
EloquentRaftProto.RaftMessage message)
sendTransport in interface RaftTransportsender - 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.public void broadcastTransport(java.lang.String sender,
EloquentRaftProto.RaftMessage message)
broadcastTransport in interface RaftTransportsender - The name of the node sending the message. In many implementations, this is redundant.message - The message to send, as a EloquentRaftProto.RaftMessage.public Span expectedNetworkDelay()
expectedNetworkDelay in interface RaftTransportpublic java.lang.String toString()
toString in class java.lang.Object