Interface RaftNodeExecutor
-
public interface RaftNodeExecutorThe abstraction used byRaftNodeto execute the Raft consensus algorithm with the Actor model. You can read about the Actor Model at the following link: https://en.wikipedia.org/wiki/Actor_modelA Raft node runs by submitting tasks to its Raft node executor. All tasks submitted by a Raft node must be executed serially, with maintaining the happens-before relationship, so that the Raft consensus algorithm and the user-provided state machine logic could be executed without synchronization.
A default implementation,
DefaultRaftNodeExecutoris provided and should be suitable for most of the use-cases.A
RaftNodeExecutorimplementation can implementRaftNodeLifecycleAwareto perform initialization and clean up work duringRaftNodestartup and termination. However, there is one subtle point about the order of method calls.RaftNodecallsexecute(Runnable)beforeRaftNodeLifecycleAware.onRaftNodeStart()to submit the start task.- See Also:
RaftNode,DefaultRaftNodeExecutor,RaftNodeLifecycleAware
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidexecute(Runnable task)Executes the given task on the underlying platform.voidschedule(Runnable task, long delay, TimeUnit timeUnit)Schedules the task on the underlying platform to be executed after the given delay.voidsubmit(Runnable task)Submits the given task for execution.
-
-
-
Method Detail
-
execute
void execute(@Nonnull Runnable task)Executes the given task on the underlying platform.Please note that all tasks of a single Raft node must be executed in a single-threaded manner and the happens-before relationship must be maintained between given tasks of the Raft node.
The underlying platform is free to execute the given task immediately if it fits to the defined guarantees.
- Parameters:
task- the task to be executed.
-
submit
void submit(@Nonnull Runnable task)Submits the given task for execution.If the caller is already on the thread that runs the Raft node, the given task cannot be executed immediately and it must be put into the internal task queue for execution in future.
- Parameters:
task- the task object to be executed later.
-
schedule
void schedule(@Nonnull Runnable task, long delay, @Nonnull TimeUnit timeUnit)Schedules the task on the underlying platform to be executed after the given delay.Please note that even though the scheduling can be offloaded to another thread, the given task must be executed in a single-threaded manner and the happens-before relationship must be maintained between given tasks of the Raft node.
- Parameters:
task- the task to be executed in futuredelay- the time from now to delay executiontimeUnit- the time unit of the delay
-
-