539797e65966e9d8dcdfbef11969223f8308f267
[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 org.opendaylight.controller.cluster.datastore.DatastoreContext;
4 import org.opendaylight.controller.cluster.datastore.DistributedDataStoreFactory;
5 import org.osgi.framework.BundleContext;
6
7 public class DistributedConfigDataStoreProviderModule extends
8     org.opendaylight.controller.config.yang.config.distributed_datastore_provider.AbstractDistributedConfigDataStoreProviderModule {
9     private BundleContext bundleContext;
10
11     public DistributedConfigDataStoreProviderModule(
12         org.opendaylight.controller.config.api.ModuleIdentifier identifier,
13         org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
14         super(identifier, dependencyResolver);
15     }
16
17     public DistributedConfigDataStoreProviderModule(
18         org.opendaylight.controller.config.api.ModuleIdentifier identifier,
19         org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
20         org.opendaylight.controller.config.yang.config.distributed_datastore_provider.DistributedConfigDataStoreProviderModule oldModule,
21         java.lang.AutoCloseable oldInstance) {
22         super(identifier, dependencyResolver, oldModule, oldInstance);
23     }
24
25     @Override
26     public void customValidation() {
27         // add custom validation form module attributes here.
28     }
29
30     @Override
31     public boolean canReuseInstance(AbstractDistributedConfigDataStoreProviderModule oldModule) {
32         return true;
33     }
34
35     @Override
36     public java.lang.AutoCloseable createInstance() {
37         ConfigProperties props = getConfigProperties();
38         if(props == null) {
39             props = new ConfigProperties();
40         }
41
42         DatastoreContext datastoreContext = DatastoreContext.newBuilder()
43                 .dataStoreType("config")
44                 .maxShardDataChangeExecutorPoolSize(props.getMaxShardDataChangeExecutorPoolSize().getValue().intValue())
45                 .maxShardDataChangeExecutorQueueSize(props.getMaxShardDataChangeExecutorQueueSize().getValue().intValue())
46                 .maxShardDataChangeListenerQueueSize(props.getMaxShardDataChangeListenerQueueSize().getValue().intValue())
47                 .maxShardDataStoreExecutorQueueSize(props.getMaxShardDataStoreExecutorQueueSize().getValue().intValue())
48                 .shardTransactionIdleTimeoutInMinutes(props.getShardTransactionIdleTimeoutInMinutes().getValue())
49                 .operationTimeoutInSeconds(props.getOperationTimeoutInSeconds().getValue())
50                 .shardJournalRecoveryLogBatchSize(props.getShardJournalRecoveryLogBatchSize().
51                         getValue().intValue())
52                 .shardSnapshotBatchCount(props.getShardSnapshotBatchCount().getValue().intValue())
53                 .shardSnapshotDataThresholdPercentage(props.getShardSnapshotDataThresholdPercentage().getValue().intValue())
54                 .shardHeartbeatIntervalInMillis(props.getShardHeartbeatIntervalInMillis().getValue())
55                 .shardInitializationTimeoutInSeconds(props.getShardInitializationTimeoutInSeconds().getValue())
56                 .shardLeaderElectionTimeoutInSeconds(props.getShardLeaderElectionTimeoutInSeconds().getValue())
57                 .shardTransactionCommitTimeoutInSeconds(
58                         props.getShardTransactionCommitTimeoutInSeconds().getValue().intValue())
59                 .shardTransactionCommitQueueCapacity(
60                         props.getShardTransactionCommitQueueCapacity().getValue().intValue())
61                 .persistent(props.getPersistent().booleanValue())
62                 .shardIsolatedLeaderCheckIntervalInMillis(
63                     props.getShardIsolatedLeaderCheckIntervalInMillis().getValue())
64                 .shardElectionTimeoutFactor(props.getShardElectionTimeoutFactor().getValue())
65                 .transactionCreationInitialRateLimit(props.getTransactionCreationInitialRateLimit().getValue())
66                 .shardBatchedModificationCount(props.getShardBatchedModificationCount().getValue().intValue())
67                 .shardCommitQueueExpiryTimeoutInSeconds(
68                         props.getShardCommitQueueExpiryTimeoutInSeconds().getValue().intValue())
69                 .build();
70
71         return DistributedDataStoreFactory.createInstance(getConfigSchemaServiceDependency(),
72                 datastoreContext, bundleContext);
73     }
74
75     public void setBundleContext(BundleContext bundleContext) {
76         this.bundleContext = bundleContext;
77     }
78 }