public abstract static class RaftServer.Builder extends Object implements io.atomix.utils.Builder<RaftServer>
This builder should be used to programmatically configure and construct a new RaftServer instance.
The builder provides methods for configuring all aspects of a Raft server. The RaftServer.Builder
class cannot be instantiated directly. To create a new builder, use one of the
server builder factory methods.
RaftServer.Builder builder = RaftServer.builder(address);
Once the server has been configured, use the Builder.build() method to build the server instance:
RaftServer server = RaftServer.builder(address)
...
.build();
Each server must be configured with a RaftService. The state machine is the component of the
server that stores state and reacts to commands and queries submitted by clients to the cluster. State machines
are provided to the server in the form of a state machine factory to allow the server to reconstruct
its state when necessary.
RaftServer server = RaftServer.builder(address)
.withStateMachine(MyStateMachine::new)
.build();
| Modifier and Type | Method and Description |
|---|---|
RaftServer.Builder |
addService(String type,
Supplier<RaftService> factory)
Adds a Raft service factory.
|
RaftServer.Builder |
withElectionThreshold(int electionThreshold)
Sets the election failure detection threshold.
|
RaftServer.Builder |
withElectionTimeout(Duration electionTimeout)
Sets the Raft election timeout, returning the Raft configuration for method chaining.
|
RaftServer.Builder |
withHeartbeatInterval(Duration heartbeatInterval)
Sets the Raft heartbeat interval, returning the Raft configuration for method chaining.
|
RaftServer.Builder |
withName(String name)
Sets the server name.
|
RaftServer.Builder |
withProtocol(RaftServerProtocol protocol)
Sets the server protocol.
|
RaftServer.Builder |
withSessionFailureThreshold(int sessionFailureThreshold)
Sets the session failure detection threshold.
|
RaftServer.Builder |
withSessionTimeout(Duration sessionTimeout)
Sets the Raft session timeout, returning the Raft configuration for method chaining.
|
RaftServer.Builder |
withStorage(RaftStorage storage)
Sets the storage module.
|
RaftServer.Builder |
withThreadModel(ThreadModel threadModel)
Sets the server thread model.
|
RaftServer.Builder |
withThreadPoolSize(int threadPoolSize)
Sets the server thread pool size.
|
RaftServer.Builder |
withType(RaftMember.Type type)
Deprecated.
|
public RaftServer.Builder withName(String name)
The server name is used to
name - The server name.@Deprecated public RaftServer.Builder withType(RaftMember.Type type)
type - The initial server member type.public RaftServer.Builder withProtocol(RaftServerProtocol protocol)
protocol - The server protocol.public RaftServer.Builder withThreadModel(ThreadModel threadModel)
threadModel - the server thread modelpublic RaftServer.Builder withStorage(RaftStorage storage)
storage - The storage module.NullPointerException - if storage is nullpublic RaftServer.Builder addService(String type, Supplier<RaftService> factory)
type - The service type name.factory - The Raft service factory.NullPointerException - if the factory is nullpublic RaftServer.Builder withElectionTimeout(Duration electionTimeout)
electionTimeout - The Raft election timeout duration.IllegalArgumentException - If the election timeout is not positiveNullPointerException - if electionTimeout is nullpublic RaftServer.Builder withHeartbeatInterval(Duration heartbeatInterval)
heartbeatInterval - The Raft heartbeat interval duration.IllegalArgumentException - If the heartbeat interval is not positiveNullPointerException - if heartbeatInterval is nullpublic RaftServer.Builder withElectionThreshold(int electionThreshold)
This is the phi value at which a follower will attempt to start a new election after not receiving any communication from the leader.
electionThreshold - the election failure detection thresholdIllegalArgumentException - if the threshold is not positivepublic RaftServer.Builder withSessionTimeout(Duration sessionTimeout)
sessionTimeout - The Raft session timeout duration.IllegalArgumentException - If the session timeout is not positiveNullPointerException - if sessionTimeout is nullpublic RaftServer.Builder withSessionFailureThreshold(int sessionFailureThreshold)
The threshold is a phi value at which sessions will be expired if the leader cannot communicate with the client.
sessionFailureThreshold - the session failure thresholdIllegalArgumentException - if the threshold is not positivepublic RaftServer.Builder withThreadPoolSize(int threadPoolSize)
threadPoolSize - The server thread pool size.Copyright © 2013–2017. All rights reserved.