Bug 7521: Add FileBackedOutputStream and use for snapshot chunking
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / DefaultConfigParamsImpl.java
index 6faf5df2e89c12ab7ed30137757e9cc4c4339401..56fb63367207b94ad368214a569e2009f8c5648f 100644 (file)
@@ -20,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 {
 
@@ -33,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;
 
@@ -42,8 +40,9 @@ public class DefaultConfigParamsImpl implements ConfigParams {
 
     /**
      * The interval at which a heart beat message will be sent to the remote
-     * RaftActor
-     * <p/>
+     * RaftActor.
+     *
+     * <p>
      * Since this is set to 100 milliseconds the Election timeout should be
      * at least 200 milliseconds
      */
@@ -69,6 +68,10 @@ public class DefaultConfigParamsImpl implements ConfigParams {
 
     private PeerAddressResolver peerAddressResolver = NoopPeerAddressResolver.INSTANCE;
 
+    private String tempFileDirectory = "";
+
+    private int fileBackedStreamingThreshold = 128 * MEGABYTE;
+
     public void setHeartBeatInterval(FiniteDuration heartBeatInterval) {
         this.heartBeatInterval = heartBeatInterval;
         electionTimeOutInterval = null;
@@ -78,7 +81,7 @@ public class DefaultConfigParamsImpl implements ConfigParams {
         this.snapshotBatchCount = snapshotBatchCount;
     }
 
-    public void setSnapshotDataThresholdPercentage(int snapshotDataThresholdPercentage){
+    public void setSnapshotDataThresholdPercentage(int snapshotDataThresholdPercentage) {
         this.snapshotDataThresholdPercentage = snapshotDataThresholdPercentage;
     }
 
@@ -94,12 +97,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 setTempFileDirectory(String tempFileDirectory) {
+        this.tempFileDirectory = tempFileDirectory;
+    }
+
+    public void setFileBackedStreamingThreshold(int fileBackedStreamingThreshold) {
+        this.fileBackedStreamingThreshold = fileBackedStreamingThreshold;
+    }
+
+    public void setCustomRaftPolicyImplementationClass(String customRaftPolicyImplementationClass) {
         this.customRaftPolicyImplementationClass = customRaftPolicyImplementationClass;
     }
 
@@ -126,7 +137,7 @@ public class DefaultConfigParamsImpl implements ConfigParams {
 
     @Override
     public FiniteDuration getElectionTimeOutInterval() {
-        if(electionTimeOutInterval == null) {
+        if (electionTimeOutInterval == null) {
             electionTimeOutInterval = getHeartBeatInterval().$times(electionTimeoutFactor);
         }
 
@@ -163,23 +174,35 @@ public class DefaultConfigParamsImpl implements ConfigParams {
         return policySupplier.get();
     }
 
-    private class PolicySupplier implements Supplier<RaftPolicy>{
+    @Override
+    public String getTempFileDirectory() {
+        return tempFileDirectory;
+    }
+
+    @Override
+    public int getFileBackedStreamingThreshold() {
+        return fileBackedStreamingThreshold;
+    }
+
+    private class PolicySupplier implements Supplier<RaftPolicy> {
         @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);
-                return (RaftPolicy)c.newInstance();
+                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;