public class LocalTransport extends java.lang.Object implements RaftTransport
RaftTransport.Type| Modifier and Type | Field and Description |
|---|---|
long |
delayMax
The maximum amount of network delay.
|
long |
delayMin
The minimum amount of network delay.
|
double |
dropProb
The probability of dropping a packet on the "network."
|
java.util.List<java.lang.Throwable> |
exceptions
The list of exceptions encountered by the transport.
|
double |
ioExceptionProb
The probability of getting an IO exception when calling a transport function.
|
long |
numRPCsSent
The number of RPC messages this transport has sent.
|
boolean |
trueTime
If true, run in real-time (or close to).
|
| Constructor and Description |
|---|
LocalTransport()
Creates a stable transport.
|
LocalTransport(boolean stable)
A constructor that has presets for whether the transport is stable (i.e., lossless, etc.) or not
|
LocalTransport(boolean stable,
boolean trueTime)
A constructor that has presets for whether the transport is stable (i.e., lossless, etc.) or not, and whether we should run in true time
|
LocalTransport(long delayMin,
long delayMax,
double dropProb,
double ioExceptionProb,
boolean trueTime,
long randomSeed)
Create a mock transport.
|
| Modifier and Type | Method and Description |
|---|---|
void |
assertInvariantsHold()
This checks several invariants across all the Raft nodes attached to the LocalTransport.
|
LocalTransport |
assertNoErrors()
Checks that there are no errors on this transport in the course of operation.
|
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.
|
protected void |
finalize() |
<E> E |
getFuture(java.util.concurrent.CompletableFuture<E> future,
java.time.Duration timeout)
Get a future.
|
void |
liftPartitions()
Lift all of our network partitions.
|
long |
now()
The current (local) time on the transport.
|
void |
partitionOff(long fromMillis,
long toMillis,
java.lang.String... nodeNames)
Create a nework partition of the given nodes, separating them from the rest of the cluster
(but allowing them to talk to each other just fine).
|
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(long interval,
int count,
java.util.function.Consumer<java.lang.Long> task)
The current time on the transport.
|
void |
schedule(SafeTimerTask task,
long delay)
Schedule an event on the transport's time.
|
void |
scheduleAtFixedRate(SafeTimerTask task,
long period)
Schedule an event on the transport's time.
|
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.
|
void |
sleep(long millis)
Sleep for the given number of milliseconds.
|
void |
start()
Start the transport, if it hasn't already started
|
void |
stop()
Stop this transport.
|
void |
synchronizedRun(java.lang.Runnable r)
Run a block of code while synrhronizing on the current timestep.
|
boolean |
threadsCanBlock()
If true, we are allowed to block while running on this transport.
|
void |
waitForSilence()
Wait for the transport to fall silent.
|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbroadcastTransport, create, messageType, mkRaftMessage, mkRaftMessage, mkRaftRPC, rpcTransport, rpcTransportAsFuture, rpcTransportAsFuture, sendTransportpublic final long delayMin
public final long delayMax
public final double dropProb
public final double ioExceptionProb
public final boolean trueTime
public long numRPCsSent
public final java.util.List<java.lang.Throwable> exceptions
assertNoErrors().public LocalTransport(long delayMin,
long delayMax,
double dropProb,
double ioExceptionProb,
boolean trueTime,
long randomSeed)
public LocalTransport(boolean stable)
public LocalTransport(boolean stable,
boolean trueTime)
public LocalTransport()
public void synchronizedRun(java.lang.Runnable r)
r - The runnable to run.public void waitForSilence()
public void start()
start in interface RaftTransportpublic void stop()
stop in interface RaftTransportpublic boolean threadsCanBlock()
threadsCanBlock in interface RaftTransportprotected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwablepublic 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 Span expectedNetworkDelay()
expectedNetworkDelay 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 LocalTransport assertNoErrors()
public void assertInvariantsHold()
public void schedule(long interval,
int count,
java.util.function.Consumer<java.lang.Long> task)
public void partitionOff(long fromMillis,
long toMillis,
java.lang.String... nodeNames)
fromMillis - The time at which to install the network partition.toMillis - The time at which to lift the network partition.nodeNames - The names of the nodes forming the new partition. These can talk to each other,
but cannot talk to anyone else in the cluster (or visa versa).public void liftPartitions()
public long now()
System.currentTimeMillis() if this isn't
a mock.now in interface RaftTransportpublic void sleep(long millis)
sleep in interface RaftTransportpublic void scheduleAtFixedRate(SafeTimerTask task, long period)
scheduleAtFixedRate in interface RaftTransportpublic void schedule(SafeTimerTask task, long delay)
schedule in interface RaftTransportpublic <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).getFuture in interface RaftTransportjava.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.util.concurrent.TimeoutException