c633337226769d14c281fc71537a71e1dd2e1586
[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 = 100000;
22
23     /**
24      * The maximum election time variance
25      */
26     private static final int ELECTION_TIME_MAX_VARIANCE = 100;
27
28
29     /**
30      * The interval at which a heart beat message will be sent to the remote
31      * RaftActor
32      * <p/>
33      * Since this is set to 100 milliseconds the Election timeout should be
34      * at least 200 milliseconds
35      */
36     protected static final FiniteDuration HEART_BEAT_INTERVAL =
37         new FiniteDuration(100, TimeUnit.MILLISECONDS);
38
39
40     @Override
41     public long getSnapshotBatchCount() {
42         return SNAPSHOT_BATCH_COUNT;
43     }
44
45     @Override
46     public FiniteDuration getHeartBeatInterval() {
47         return HEART_BEAT_INTERVAL;
48     }
49
50
51     @Override
52     public FiniteDuration getElectionTimeOutInterval() {
53         // returns 2 times the heart beat interval
54         return HEART_BEAT_INTERVAL.$times(2);
55     }
56
57     @Override
58     public int getElectionTimeVariance() {
59         return ELECTION_TIME_MAX_VARIANCE;
60     }
61 }