Remove unnecessary declaration of <prerequisites> in features
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / DatastoreContext.java
1 /*
2  * Copyright (c) 2014 Brocade Communications 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
9 package org.opendaylight.controller.cluster.datastore;
10
11 import akka.util.Timeout;
12 import java.util.concurrent.TimeUnit;
13 import org.opendaylight.controller.cluster.datastore.config.ConfigurationReader;
14 import org.opendaylight.controller.cluster.datastore.config.FileConfigurationReader;
15 import org.opendaylight.controller.cluster.raft.ConfigParams;
16 import org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl;
17 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStoreConfigProperties;
18 import scala.concurrent.duration.Duration;
19 import scala.concurrent.duration.FiniteDuration;
20
21 /**
22  * Contains contextual data for a data store.
23  *
24  * @author Thomas Pantelis
25  */
26 public class DatastoreContext {
27
28     private final InMemoryDOMDataStoreConfigProperties dataStoreProperties;
29     private final Duration shardTransactionIdleTimeout;
30     private final int operationTimeoutInSeconds;
31     private final String dataStoreMXBeanType;
32     private final ConfigParams shardRaftConfig;
33     private final int shardTransactionCommitTimeoutInSeconds;
34     private final int shardTransactionCommitQueueCapacity;
35     private final Timeout shardInitializationTimeout;
36     private final Timeout shardLeaderElectionTimeout;
37     private final boolean persistent;
38     private final ConfigurationReader configurationReader;
39
40     private DatastoreContext(InMemoryDOMDataStoreConfigProperties dataStoreProperties,
41             ConfigParams shardRaftConfig, String dataStoreMXBeanType, int operationTimeoutInSeconds,
42             Duration shardTransactionIdleTimeout, int shardTransactionCommitTimeoutInSeconds,
43             int shardTransactionCommitQueueCapacity, Timeout shardInitializationTimeout,
44             Timeout shardLeaderElectionTimeout,
45             boolean persistent, ConfigurationReader configurationReader) {
46         this.dataStoreProperties = dataStoreProperties;
47         this.shardRaftConfig = shardRaftConfig;
48         this.dataStoreMXBeanType = dataStoreMXBeanType;
49         this.operationTimeoutInSeconds = operationTimeoutInSeconds;
50         this.shardTransactionIdleTimeout = shardTransactionIdleTimeout;
51         this.shardTransactionCommitTimeoutInSeconds = shardTransactionCommitTimeoutInSeconds;
52         this.shardTransactionCommitQueueCapacity = shardTransactionCommitQueueCapacity;
53         this.shardInitializationTimeout = shardInitializationTimeout;
54         this.shardLeaderElectionTimeout = shardLeaderElectionTimeout;
55         this.persistent = persistent;
56         this.configurationReader = configurationReader;
57     }
58
59     public static Builder newBuilder() {
60         return new Builder();
61     }
62
63     public InMemoryDOMDataStoreConfigProperties getDataStoreProperties() {
64         return dataStoreProperties;
65     }
66
67     public Duration getShardTransactionIdleTimeout() {
68         return shardTransactionIdleTimeout;
69     }
70
71     public String getDataStoreMXBeanType() {
72         return dataStoreMXBeanType;
73     }
74
75     public int getOperationTimeoutInSeconds() {
76         return operationTimeoutInSeconds;
77     }
78
79     public ConfigParams getShardRaftConfig() {
80         return shardRaftConfig;
81     }
82
83     public int getShardTransactionCommitTimeoutInSeconds() {
84         return shardTransactionCommitTimeoutInSeconds;
85     }
86
87     public int getShardTransactionCommitQueueCapacity() {
88         return shardTransactionCommitQueueCapacity;
89     }
90
91     public Timeout getShardInitializationTimeout() {
92         return shardInitializationTimeout;
93     }
94
95     public Timeout getShardLeaderElectionTimeout() {
96         return shardLeaderElectionTimeout;
97     }
98
99     public boolean isPersistent() {
100         return persistent;
101     }
102
103     public ConfigurationReader getConfigurationReader() {
104         return configurationReader;
105     }
106
107     public static class Builder {
108         private InMemoryDOMDataStoreConfigProperties dataStoreProperties;
109         private Duration shardTransactionIdleTimeout = Duration.create(10, TimeUnit.MINUTES);
110         private int operationTimeoutInSeconds = 5;
111         private String dataStoreMXBeanType;
112         private int shardTransactionCommitTimeoutInSeconds = 30;
113         private int shardJournalRecoveryLogBatchSize = 1000;
114         private int shardSnapshotBatchCount = 20000;
115         private int shardHeartbeatIntervalInMillis = 500;
116         private int shardTransactionCommitQueueCapacity = 20000;
117         private Timeout shardInitializationTimeout = new Timeout(5, TimeUnit.MINUTES);
118         private Timeout shardLeaderElectionTimeout = new Timeout(30, TimeUnit.SECONDS);
119         private boolean persistent = true;
120         private ConfigurationReader configurationReader = new FileConfigurationReader();
121         private int shardIsolatedLeaderCheckIntervalInMillis = shardHeartbeatIntervalInMillis * 10;
122         private int shardSnapshotDataThresholdPercentage = 12;
123
124         public Builder shardTransactionIdleTimeout(Duration shardTransactionIdleTimeout) {
125             this.shardTransactionIdleTimeout = shardTransactionIdleTimeout;
126             return this;
127         }
128
129         public Builder operationTimeoutInSeconds(int operationTimeoutInSeconds) {
130             this.operationTimeoutInSeconds = operationTimeoutInSeconds;
131             return this;
132         }
133
134         public Builder dataStoreMXBeanType(String dataStoreMXBeanType) {
135             this.dataStoreMXBeanType = dataStoreMXBeanType;
136             return this;
137         }
138
139         public Builder dataStoreProperties(InMemoryDOMDataStoreConfigProperties dataStoreProperties) {
140             this.dataStoreProperties = dataStoreProperties;
141             return this;
142         }
143
144         public Builder shardTransactionCommitTimeoutInSeconds(int shardTransactionCommitTimeoutInSeconds) {
145             this.shardTransactionCommitTimeoutInSeconds = shardTransactionCommitTimeoutInSeconds;
146             return this;
147         }
148
149         public Builder shardJournalRecoveryLogBatchSize(int shardJournalRecoveryLogBatchSize) {
150             this.shardJournalRecoveryLogBatchSize = shardJournalRecoveryLogBatchSize;
151             return this;
152         }
153
154         public Builder shardSnapshotBatchCount(int shardSnapshotBatchCount) {
155             this.shardSnapshotBatchCount = shardSnapshotBatchCount;
156             return this;
157         }
158
159         public Builder shardSnapshotDataThresholdPercentage(int shardSnapshotDataThresholdPercentage) {
160             this.shardSnapshotDataThresholdPercentage = shardSnapshotDataThresholdPercentage;
161             return this;
162         }
163
164
165         public Builder shardHeartbeatIntervalInMillis(int shardHeartbeatIntervalInMillis) {
166             this.shardHeartbeatIntervalInMillis = shardHeartbeatIntervalInMillis;
167             return this;
168         }
169
170         public Builder shardTransactionCommitQueueCapacity(int shardTransactionCommitQueueCapacity) {
171             this.shardTransactionCommitQueueCapacity = shardTransactionCommitQueueCapacity;
172             return this;
173         }
174
175         public Builder shardInitializationTimeout(long timeout, TimeUnit unit) {
176             this.shardInitializationTimeout = new Timeout(timeout, unit);
177             return this;
178         }
179
180         public Builder shardLeaderElectionTimeout(long timeout, TimeUnit unit) {
181             this.shardLeaderElectionTimeout = new Timeout(timeout, unit);
182             return this;
183         }
184
185         public Builder configurationReader(ConfigurationReader configurationReader){
186             this.configurationReader = configurationReader;
187             return this;
188         }
189
190         public Builder persistent(boolean persistent){
191             this.persistent = persistent;
192             return this;
193         }
194
195         public Builder shardIsolatedLeaderCheckIntervalInMillis(int shardIsolatedLeaderCheckIntervalInMillis) {
196             this.shardIsolatedLeaderCheckIntervalInMillis = shardIsolatedLeaderCheckIntervalInMillis;
197             return this;
198         }
199
200
201         public DatastoreContext build() {
202             DefaultConfigParamsImpl raftConfig = new DefaultConfigParamsImpl();
203             raftConfig.setHeartBeatInterval(new FiniteDuration(shardHeartbeatIntervalInMillis,
204                     TimeUnit.MILLISECONDS));
205             raftConfig.setJournalRecoveryLogBatchSize(shardJournalRecoveryLogBatchSize);
206             raftConfig.setSnapshotBatchCount(shardSnapshotBatchCount);
207             raftConfig.setSnapshotDataThresholdPercentage(shardSnapshotDataThresholdPercentage);
208             raftConfig.setIsolatedLeaderCheckInterval(
209                 new FiniteDuration(shardIsolatedLeaderCheckIntervalInMillis, TimeUnit.MILLISECONDS));
210
211             return new DatastoreContext(dataStoreProperties, raftConfig, dataStoreMXBeanType,
212                     operationTimeoutInSeconds, shardTransactionIdleTimeout,
213                     shardTransactionCommitTimeoutInSeconds, shardTransactionCommitQueueCapacity,
214                     shardInitializationTimeout, shardLeaderElectionTimeout,
215                     persistent, configurationReader);
216         }
217     }
218 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.