Interface RaftNodeExecutor


  • public interface RaftNodeExecutor
    The abstraction used by RaftNode to 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_model

    A 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, DefaultRaftNodeExecutor is provided and should be suitable for most of the use-cases.

    A RaftNodeExecutor implementation can implement RaftNodeLifecycleAware to perform initialization and clean up work during RaftNode startup and termination. However, there is one subtle point about the order of method calls. RaftNode calls execute(Runnable) before RaftNodeLifecycleAware.onRaftNodeStart() to submit the start task.

    See Also:
    RaftNode, DefaultRaftNodeExecutor, RaftNodeLifecycleAware
    • 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 future
        delay - the time from now to delay execution
        timeUnit - the time unit of the delay