Merge "Bug-2277 : Isolated Leader Implementation"
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / DefaultConfigParamsImpl.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.raft;
9
10 import scala.concurrent.duration.FiniteDuration;
11
12 import java.util.concurrent.TimeUnit;
13
14 /**
15  * Default implementation of the ConfigParams
16  *
17  * If no implementation is provided for ConfigParams, then this will be used.
18  */
19 public class DefaultConfigParamsImpl implements ConfigParams {
20
21     private static final int SNAPSHOT_BATCH_COUNT = 20000;
22
23     private static final int JOURNAL_RECOVERY_LOG_BATCH_SIZE = 1000;
24
25     /**
26      * The maximum election time variance
27      */
28     private static final int ELECTION_TIME_MAX_VARIANCE = 100;
29
30     private static final int SNAPSHOT_CHUNK_SIZE = 2048 * 1000; //2MB
31
32
33     /**
34      * The interval at which a heart beat message will be sent to the remote
35      * RaftActor
36      * <p/>
37      * Since this is set to 100 milliseconds the Election timeout should be
38      * at least 200 milliseconds
39      */
40     public static final FiniteDuration HEART_BEAT_INTERVAL =
41         new FiniteDuration(100, TimeUnit.MILLISECONDS);
42
43
44     private FiniteDuration heartBeatInterval = HEART_BEAT_INTERVAL;
45     private long snapshotBatchCount = SNAPSHOT_BATCH_COUNT;
46     private int journalRecoveryLogBatchSize = JOURNAL_RECOVERY_LOG_BATCH_SIZE;
47     private FiniteDuration isolatedLeaderCheckInterval =
48         new FiniteDuration(HEART_BEAT_INTERVAL.length() * 1000, HEART_BEAT_INTERVAL.unit());
49
50     public void setHeartBeatInterval(FiniteDuration heartBeatInterval) {
51         this.heartBeatInterval = heartBeatInterval;
52     }
53
54     public void setSnapshotBatchCount(long snapshotBatchCount) {
55         this.snapshotBatchCount = snapshotBatchCount;
56     }
57
58     public void setJournalRecoveryLogBatchSize(int journalRecoveryLogBatchSize) {
59         this.journalRecoveryLogBatchSize = journalRecoveryLogBatchSize;
60     }
61
62     public void setIsolatedLeaderCheckInterval(FiniteDuration isolatedLeaderCheckInterval) {
63         this.isolatedLeaderCheckInterval = isolatedLeaderCheckInterval;
64     }
65
66     @Override
67     public long getSnapshotBatchCount() {
68         return snapshotBatchCount;
69     }
70
71     @Override
72     public FiniteDuration getHeartBeatInterval() {
73         return heartBeatInterval;
74     }
75
76     @Override
77     public FiniteDuration getElectionTimeOutInterval() {
78         // returns 2 times the heart beat interval
79         return getHeartBeatInterval().$times(2);
80     }
81
82     @Override
83     public int getElectionTimeVariance() {
84         return ELECTION_TIME_MAX_VARIANCE;
85     }
86
87     @Override
88     public int getSnapshotChunkSize() {
89         return SNAPSHOT_CHUNK_SIZE;
90     }
91
92     @Override
93     public int getJournalRecoveryLogBatchSize() {
94         return journalRecoveryLogBatchSize;
95     }
96
97     @Override
98     public FiniteDuration getIsolatedCheckInterval() {
99         return isolatedLeaderCheckInterval;
100     }
101 }