+ private final Supplier<RaftPolicy> policySupplier = Suppliers.memoize(this::getPolicy);
+
+ private FiniteDuration heartBeatInterval = HEART_BEAT_INTERVAL;
+ private long snapshotBatchCount = SNAPSHOT_BATCH_COUNT;
+ private int journalRecoveryLogBatchSize = JOURNAL_RECOVERY_LOG_BATCH_SIZE;
+ private int recoverySnapshotIntervalSeconds = RECOVERY_SNAPSHOT_INTERVAL_SECONDS;
+ private long isolatedLeaderCheckInterval = HEART_BEAT_INTERVAL.$times(1000).toMillis();
+ private FiniteDuration electionTimeOutInterval;
+
+ // 12 is just an arbitrary percentage. This is the amount of the total memory that a raft actor's
+ // in-memory journal can use before it needs to snapshot
+ private int snapshotDataThresholdPercentage = 12;
+
+ // max size of in-memory journal in MB
+ // 0 means direct threshold if disabled
+ private int snapshotDataThreshold = 0;
+
+ private int snapshotChunkSize = SNAPSHOT_CHUNK_SIZE;
+
+ private long electionTimeoutFactor = 2;
+ private long candidateElectionTimeoutDivisor = 1;
+ private String customRaftPolicyImplementationClass;
+
+ private PeerAddressResolver peerAddressResolver = NoopPeerAddressResolver.INSTANCE;
+
+ private String tempFileDirectory = "";
+
+ private int fileBackedStreamingThreshold = 128 * MEGABYTE;
+
+ private long syncIndexThreshold = 10;
+
+ public void setHeartBeatInterval(final FiniteDuration heartBeatInterval) {
+ this.heartBeatInterval = heartBeatInterval;
+ electionTimeOutInterval = null;
+ }
+
+ public void setSnapshotBatchCount(final long snapshotBatchCount) {
+ this.snapshotBatchCount = snapshotBatchCount;
+ }
+
+ public void setRecoverySnapshotIntervalSeconds(final int recoverySnapshotInterval) {
+ checkArgument(recoverySnapshotInterval >= 0);
+ recoverySnapshotIntervalSeconds = recoverySnapshotInterval;
+ }
+
+ public void setSnapshotDataThresholdPercentage(final int snapshotDataThresholdPercentage) {
+ this.snapshotDataThresholdPercentage = snapshotDataThresholdPercentage;
+ }
+
+ public void setSnapshotDataThreshold(final int snapshotDataThreshold) {
+ this.snapshotDataThreshold = snapshotDataThreshold;
+ }
+
+ public void setSnapshotChunkSize(final int snapshotChunkSize) {
+ this.snapshotChunkSize = snapshotChunkSize;
+ }
+
+ public void setJournalRecoveryLogBatchSize(final int journalRecoveryLogBatchSize) {
+ this.journalRecoveryLogBatchSize = journalRecoveryLogBatchSize;
+ }
+
+ public void setIsolatedLeaderCheckInterval(final FiniteDuration isolatedLeaderCheckInterval) {
+ this.isolatedLeaderCheckInterval = isolatedLeaderCheckInterval.toMillis();
+ }
+
+ public void setElectionTimeoutFactor(final long electionTimeoutFactor) {
+ this.electionTimeoutFactor = electionTimeoutFactor;
+ electionTimeOutInterval = null;
+ }
+
+ public void setCandidateElectionTimeoutDivisor(final long candidateElectionTimeoutDivisor) {
+ this.candidateElectionTimeoutDivisor = candidateElectionTimeoutDivisor;
+ }
+
+ public void setTempFileDirectory(final String tempFileDirectory) {
+ this.tempFileDirectory = tempFileDirectory;
+ }
+
+ public void setFileBackedStreamingThreshold(final int fileBackedStreamingThreshold) {
+ this.fileBackedStreamingThreshold = fileBackedStreamingThreshold;
+ }
+
+ public void setCustomRaftPolicyImplementationClass(final String customRaftPolicyImplementationClass) {
+ this.customRaftPolicyImplementationClass = customRaftPolicyImplementationClass;
+ }
+
+ @Override
+ public String getCustomRaftPolicyImplementationClass() {
+ return customRaftPolicyImplementationClass;
+ }