75e45b1d4f856b6036674096409d39d72fb51c8b
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / config / yang / config / distributed_datastore_provider / DistributedConfigDataStoreProviderModule.java
1 package org.opendaylight.controller.config.yang.config.distributed_datastore_provider;
2
3 import java.util.concurrent.TimeUnit;
4 import org.opendaylight.controller.cluster.datastore.DatastoreContext;
5 import org.opendaylight.controller.cluster.datastore.DistributedDataStoreFactory;
6 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStoreConfigProperties;
7 import org.osgi.framework.BundleContext;
8 import scala.concurrent.duration.Duration;
9
10 public class DistributedConfigDataStoreProviderModule extends
11     org.opendaylight.controller.config.yang.config.distributed_datastore_provider.AbstractDistributedConfigDataStoreProviderModule {
12     private BundleContext bundleContext;
13
14     public DistributedConfigDataStoreProviderModule(
15         org.opendaylight.controller.config.api.ModuleIdentifier identifier,
16         org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
17         super(identifier, dependencyResolver);
18     }
19
20     public DistributedConfigDataStoreProviderModule(
21         org.opendaylight.controller.config.api.ModuleIdentifier identifier,
22         org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
23         org.opendaylight.controller.config.yang.config.distributed_datastore_provider.DistributedConfigDataStoreProviderModule oldModule,
24         java.lang.AutoCloseable oldInstance) {
25         super(identifier, dependencyResolver, oldModule, oldInstance);
26     }
27
28     @Override
29     public void customValidation() {
30         // add custom validation form module attributes here.
31     }
32
33     @Override
34     public java.lang.AutoCloseable createInstance() {
35
36         ConfigProperties props = getConfigProperties();
37         if(props == null) {
38             props = new ConfigProperties();
39         }
40
41         DatastoreContext datastoreContext = DatastoreContext.newBuilder()
42                 .dataStoreType("config")
43                 .dataStoreProperties(InMemoryDOMDataStoreConfigProperties.create(
44                         props.getMaxShardDataChangeExecutorPoolSize().getValue().intValue(),
45                         props.getMaxShardDataChangeExecutorQueueSize().getValue().intValue(),
46                         props.getMaxShardDataChangeListenerQueueSize().getValue().intValue(),
47                         props.getMaxShardDataStoreExecutorQueueSize().getValue().intValue()))
48                 .shardTransactionIdleTimeout(Duration.create(
49                         props.getShardTransactionIdleTimeoutInMinutes().getValue(), TimeUnit.MINUTES))
50                 .operationTimeoutInSeconds(props.getOperationTimeoutInSeconds().getValue())
51                 .shardJournalRecoveryLogBatchSize(props.getShardJournalRecoveryLogBatchSize().
52                         getValue().intValue())
53                 .shardSnapshotBatchCount(props.getShardSnapshotBatchCount().getValue().intValue())
54                 .shardSnapshotDataThresholdPercentage(props.getShardSnapshotDataThresholdPercentage().getValue().intValue())
55                 .shardHeartbeatIntervalInMillis(props.getShardHearbeatIntervalInMillis().getValue())
56                 .shardInitializationTimeout(props.getShardInitializationTimeoutInSeconds().getValue(),
57                         TimeUnit.SECONDS)
58                 .shardLeaderElectionTimeout(props.getShardLeaderElectionTimeoutInSeconds().getValue(),
59                         TimeUnit.SECONDS)
60                 .shardTransactionCommitTimeoutInSeconds(
61                         props.getShardTransactionCommitTimeoutInSeconds().getValue().intValue())
62                 .shardTransactionCommitQueueCapacity(
63                         props.getShardTransactionCommitQueueCapacity().getValue().intValue())
64                 .persistent(props.getPersistent().booleanValue())
65                 .shardIsolatedLeaderCheckIntervalInMillis(
66                     props.getShardIsolatedLeaderCheckIntervalInMillis().getValue())
67                 .shardElectionTimeoutFactor(props.getShardElectionTimeoutFactor().getValue())
68                 .transactionCreationInitialRateLimit(props.getTxCreationInitialRateLimit().getValue())
69                 .shardBatchedModificationCount(props.getShardBatchedModificationCount().getValue().intValue())
70                 .build();
71
72         return DistributedDataStoreFactory.createInstance(getConfigSchemaServiceDependency(),
73                 datastoreContext, bundleContext);
74     }
75
76     public void setBundleContext(BundleContext bundleContext) {
77         this.bundleContext = bundleContext;
78     }
79 }