+ * + * If the given identifier is {@code null} then a {@link java.util.UUID} based unique identifier will be automatically + * generated. + * + * @param id The unique identifier of this instance of the Raft algorithm. + */ + public void setId(String id) { + if (id != null) { + this.config = config.withValue(RAFT_ID, ConfigValueFactory.fromAnyRef(id)); + } else if (!this.config.hasPath(RAFT_ID)) { + this.config = config.withValue(RAFT_ID, ConfigValueFactory.fromAnyRef(UUID.randomUUID().toString())); + } + } + + /** + * Returns the unique identifier of this instance of the Raft algorithm.
+ * + * If the unique ID for this instance has not yet been set, a {@link java.util.UUID} based identifier will be generated. + * + * @return The unique identifier of this instance of the Raft algorithm. + */ + public String getId() { + if (!config.hasPath(RAFT_ID)) { + setId(null); + } + return config.getString(RAFT_ID); + } + + /** + * Sets the unique identifier of this instance of the Raft algorithm, returning the configuration for method chaining.
+ *
+ * If the given identifier is {@code null} then a {@link java.util.UUID} based unique identifier will be automatically
+ * generated.
+ *
+ * @param id The unique identifier of this instance of the Raft algorithm.
+ * @return The Raft configuration.
+ */
+ public RaftConfig withId(String id) {
+ setId(id);
+ return this;
+ }
+
+ /**
+ * Sets the Raft algorithm name.
+ *
+ * @param name The algorithm name.
+ * @throws java.lang.NullPointerException If the name is {@code null}
+ */
+ public void setName(String name) {
+ this.config = config.withValue(RAFT_NAME, ConfigValueFactory.fromAnyRef(Assert.isNotNull(name, "name")));
+ }
+
+ /**
+ * Returns the Raft algorithm name.
+ *
+ * @return The Raft algorithm name.
+ * @throws java.lang.NullPointerException If the algorithm name has not been configured.
+ */
+ public String getName() {
+ return config.getString(RAFT_NAME);
+ }
+
+ /**
+ * Sets the Raft algorithm name, returning the configuration for method chaining.
+ *
+ * @param name The Raft algorithm name.
+ * @return The Raft configuration.
+ */
+ public RaftConfig withName(String name) {
+ setName(name);
+ return this;
+ }
+
/**
* Sets the resource election timeout.
*
@@ -60,7 +141,7 @@ public RaftConfig copy() {
* @throws java.lang.IllegalArgumentException If the election timeout is not positive
*/
public void setElectionTimeout(long electionTimeout) {
- this.config = config.withValue(RESOURCE_ELECTION_TIMEOUT, ConfigValueFactory.fromAnyRef(Assert.arg(electionTimeout, electionTimeout > 0, "election timeout must be positive")));
+ this.config = config.withValue(RAFT_ELECTION_TIMEOUT, ConfigValueFactory.fromAnyRef(Assert.arg(electionTimeout, electionTimeout > 0, "election timeout must be positive")));
}
/**
@@ -80,7 +161,7 @@ public void setElectionTimeout(long electionTimeout, TimeUnit unit) {
* @return The resource election timeout in milliseconds.
*/
public long getElectionTimeout() {
- return config.getLong(RESOURCE_ELECTION_TIMEOUT);
+ return config.getLong(RAFT_ELECTION_TIMEOUT);
}
/**
@@ -115,7 +196,7 @@ public RaftConfig withElectionTimeout(long electionTimeout, TimeUnit unit) {
* @throws java.lang.IllegalArgumentException If the heartbeat interval is not positive
*/
public void setHeartbeatInterval(long heartbeatInterval) {
- this.config = config.withValue(RESOURCE_HEARTBEAT_INTERVAL, ConfigValueFactory.fromAnyRef(Assert.arg(heartbeatInterval, heartbeatInterval > 0, "heartbeat interval must be positive")));
+ this.config = config.withValue(RAFT_HEARTBEAT_INTERVAL, ConfigValueFactory.fromAnyRef(Assert.arg(heartbeatInterval, heartbeatInterval > 0, "heartbeat interval must be positive")));
}
/**
@@ -135,7 +216,7 @@ public void setHeartbeatInterval(long heartbeatInterval, TimeUnit unit) {
* @return The interval at which nodes send heartbeats to each other.
*/
public long getHeartbeatInterval() {
- return config.getLong(RESOURCE_HEARTBEAT_INTERVAL);
+ return config.getLong(RAFT_HEARTBEAT_INTERVAL);
}
/**
@@ -180,7 +261,7 @@ public void setReplicas(String... replicas) {
* @throws java.lang.NullPointerException If {@code replicas} is {@code null}
*/
public void setReplicas(Collection