X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2FDefaultConfigParamsImpl.java;h=317ce6a220854f262dce8e5e65678223d6117ab9;hp=c8cc88c3edd45256011f050a5a4c83b749b37730;hb=000960f6451af770f5463e41e1fb6defb6f3ab27;hpb=b3cc695157dc7e8f3f7698ebc34403be57c65636 diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/DefaultConfigParamsImpl.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/DefaultConfigParamsImpl.java index c8cc88c3ed..317ce6a220 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/DefaultConfigParamsImpl.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/DefaultConfigParamsImpl.java @@ -7,10 +7,12 @@ */ package org.opendaylight.controller.cluster.raft; +import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import java.util.concurrent.TimeUnit; +import javax.annotation.Nonnull; import org.opendaylight.controller.cluster.raft.policy.DefaultRaftPolicy; import org.opendaylight.controller.cluster.raft.policy.RaftPolicy; import org.slf4j.Logger; @@ -18,9 +20,7 @@ import org.slf4j.LoggerFactory; import scala.concurrent.duration.FiniteDuration; /** - * Default implementation of the ConfigParams - * - * If no implementation is provided for ConfigParams, then this will be used. + * Default implementation of the ConfigParams. */ public class DefaultConfigParamsImpl implements ConfigParams { @@ -31,7 +31,7 @@ public class DefaultConfigParamsImpl implements ConfigParams { private static final int JOURNAL_RECOVERY_LOG_BATCH_SIZE = 1000; /** - * The maximum election time variance + * The maximum election time variance. */ private static final int ELECTION_TIME_MAX_VARIANCE = 100; @@ -40,8 +40,9 @@ public class DefaultConfigParamsImpl implements ConfigParams { /** * The interval at which a heart beat message will be sent to the remote - * RaftActor - *

+ * RaftActor. + * + *

* Since this is set to 100 milliseconds the Election timeout should be * at least 200 milliseconds */ @@ -63,7 +64,9 @@ public class DefaultConfigParamsImpl implements ConfigParams { private long electionTimeoutFactor = 2; private String customRaftPolicyImplementationClass; - Supplier policySupplier = Suppliers.memoize(new PolicySupplier()); + private final Supplier policySupplier = Suppliers.memoize(new PolicySupplier()); + + private PeerAddressResolver peerAddressResolver = NoopPeerAddressResolver.INSTANCE; public void setHeartBeatInterval(FiniteDuration heartBeatInterval) { this.heartBeatInterval = heartBeatInterval; @@ -74,7 +77,7 @@ public class DefaultConfigParamsImpl implements ConfigParams { this.snapshotBatchCount = snapshotBatchCount; } - public void setSnapshotDataThresholdPercentage(int snapshotDataThresholdPercentage){ + public void setSnapshotDataThresholdPercentage(int snapshotDataThresholdPercentage) { this.snapshotDataThresholdPercentage = snapshotDataThresholdPercentage; } @@ -90,15 +93,20 @@ public class DefaultConfigParamsImpl implements ConfigParams { this.isolatedLeaderCheckInterval = isolatedLeaderCheckInterval.toMillis(); } - public void setElectionTimeoutFactor(long electionTimeoutFactor){ + public void setElectionTimeoutFactor(long electionTimeoutFactor) { this.electionTimeoutFactor = electionTimeoutFactor; electionTimeOutInterval = null; } - public void setCustomRaftPolicyImplementationClass(String customRaftPolicyImplementationClass){ + public void setCustomRaftPolicyImplementationClass(String customRaftPolicyImplementationClass) { this.customRaftPolicyImplementationClass = customRaftPolicyImplementationClass; } + @Override + public String getCustomRaftPolicyImplementationClass() { + return customRaftPolicyImplementationClass; + } + @Override public long getSnapshotBatchCount() { return snapshotBatchCount; @@ -117,7 +125,7 @@ public class DefaultConfigParamsImpl implements ConfigParams { @Override public FiniteDuration getElectionTimeOutInterval() { - if(electionTimeOutInterval == null) { + if (electionTimeOutInterval == null) { electionTimeOutInterval = getHeartBeatInterval().$times(electionTimeoutFactor); } @@ -154,27 +162,37 @@ public class DefaultConfigParamsImpl implements ConfigParams { return policySupplier.get(); } - private class PolicySupplier implements Supplier{ + private class PolicySupplier implements Supplier { @Override + @SuppressWarnings("checkstyle:IllegalCatch") public RaftPolicy get() { - if(Strings.isNullOrEmpty(DefaultConfigParamsImpl.this.customRaftPolicyImplementationClass)){ + if (Strings.isNullOrEmpty(DefaultConfigParamsImpl.this.customRaftPolicyImplementationClass)) { LOG.debug("No custom RaftPolicy specified. Using DefaultRaftPolicy"); return DefaultRaftPolicy.INSTANCE; } + try { String className = DefaultConfigParamsImpl.this.customRaftPolicyImplementationClass; LOG.info("Trying to use custom RaftPolicy {}", className); - Class c = Class.forName(className); - RaftPolicy obj = (RaftPolicy)c.newInstance(); - return obj; + return (RaftPolicy)Class.forName(className).newInstance(); } catch (Exception e) { - if(LOG.isDebugEnabled()) { + if (LOG.isDebugEnabled()) { LOG.error("Could not create custom raft policy, will stick with default", e); } else { - LOG.error("Could not create custom raft policy, will stick with default : cause = {}", e.getMessage()); + LOG.error("Could not create custom raft policy, will stick with default : cause = {}", + e.getMessage()); } } return DefaultRaftPolicy.INSTANCE; } } + + @Override + public PeerAddressResolver getPeerAddressResolver() { + return peerAddressResolver; + } + + public void setPeerAddressResolver(@Nonnull PeerAddressResolver peerAddressResolver) { + this.peerAddressResolver = Preconditions.checkNotNull(peerAddressResolver); + } }