Add missing license headers
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / config / yang / config / distributed_datastore_provider / DistributedConfigDataStoreProviderModule.java
1 /*
2  * Copyright (c) 2014, 2015 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
9 package org.opendaylight.controller.config.yang.config.distributed_datastore_provider;
10
11 import org.opendaylight.controller.cluster.datastore.DatastoreContext;
12 import org.opendaylight.controller.cluster.datastore.DatastoreSnapshotRestore;
13 import org.opendaylight.controller.cluster.datastore.DistributedDataStoreFactory;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.osgi.framework.BundleContext;
16
17 public class DistributedConfigDataStoreProviderModule extends
18     org.opendaylight.controller.config.yang.config.distributed_datastore_provider.AbstractDistributedConfigDataStoreProviderModule {
19     private BundleContext bundleContext;
20
21     public DistributedConfigDataStoreProviderModule(
22         org.opendaylight.controller.config.api.ModuleIdentifier identifier,
23         org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
24         super(identifier, dependencyResolver);
25     }
26
27     public DistributedConfigDataStoreProviderModule(
28         org.opendaylight.controller.config.api.ModuleIdentifier identifier,
29         org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
30         org.opendaylight.controller.config.yang.config.distributed_datastore_provider.DistributedConfigDataStoreProviderModule oldModule,
31         java.lang.AutoCloseable oldInstance) {
32         super(identifier, dependencyResolver, oldModule, oldInstance);
33     }
34
35     @Override
36     public void customValidation() {
37         // add custom validation form module attributes here.
38     }
39
40     @Override
41     public boolean canReuseInstance(AbstractDistributedConfigDataStoreProviderModule oldModule) {
42         return true;
43     }
44
45     @Override
46     public java.lang.AutoCloseable createInstance() {
47         ConfigProperties props = getConfigProperties();
48         if(props == null) {
49             props = new ConfigProperties();
50         }
51
52         DatastoreContext datastoreContext = DatastoreContext.newBuilder()
53                 .logicalStoreType(LogicalDatastoreType.CONFIGURATION)
54                 .maxShardDataChangeExecutorPoolSize(props.getMaxShardDataChangeExecutorPoolSize().getValue().intValue())
55                 .maxShardDataChangeExecutorQueueSize(props.getMaxShardDataChangeExecutorQueueSize().getValue().intValue())
56                 .maxShardDataChangeListenerQueueSize(props.getMaxShardDataChangeListenerQueueSize().getValue().intValue())
57                 .maxShardDataStoreExecutorQueueSize(props.getMaxShardDataStoreExecutorQueueSize().getValue().intValue())
58                 .shardTransactionIdleTimeoutInMinutes(props.getShardTransactionIdleTimeoutInMinutes().getValue())
59                 .operationTimeoutInSeconds(props.getOperationTimeoutInSeconds().getValue())
60                 .shardJournalRecoveryLogBatchSize(props.getShardJournalRecoveryLogBatchSize().
61                         getValue().intValue())
62                 .shardSnapshotBatchCount(props.getShardSnapshotBatchCount().getValue().intValue())
63                 .shardSnapshotDataThresholdPercentage(props.getShardSnapshotDataThresholdPercentage().getValue().intValue())
64                 .shardHeartbeatIntervalInMillis(props.getShardHeartbeatIntervalInMillis().getValue())
65                 .shardInitializationTimeoutInSeconds(props.getShardInitializationTimeoutInSeconds().getValue())
66                 .shardLeaderElectionTimeoutInSeconds(props.getShardLeaderElectionTimeoutInSeconds().getValue())
67                 .shardTransactionCommitTimeoutInSeconds(
68                         props.getShardTransactionCommitTimeoutInSeconds().getValue().intValue())
69                 .shardTransactionCommitQueueCapacity(
70                         props.getShardTransactionCommitQueueCapacity().getValue().intValue())
71                 .persistent(props.getPersistent().booleanValue())
72                 .shardIsolatedLeaderCheckIntervalInMillis(
73                     props.getShardIsolatedLeaderCheckIntervalInMillis().getValue())
74                 .shardElectionTimeoutFactor(props.getShardElectionTimeoutFactor().getValue())
75                 .transactionCreationInitialRateLimit(props.getTransactionCreationInitialRateLimit().getValue())
76                 .shardBatchedModificationCount(props.getShardBatchedModificationCount().getValue().intValue())
77                 .shardCommitQueueExpiryTimeoutInSeconds(
78                         props.getShardCommitQueueExpiryTimeoutInSeconds().getValue().intValue())
79                 .transactionDebugContextEnabled(props.getTransactionDebugContextEnabled())
80                 .customRaftPolicyImplementation(props.getCustomRaftPolicyImplementation())
81                 .shardSnapshotChunkSize(props.getShardSnapshotChunkSize().getValue().intValue())
82                 .build();
83
84         return DistributedDataStoreFactory.createInstance(getConfigSchemaServiceDependency(),
85                 datastoreContext, DatastoreSnapshotRestore.instance().getAndRemove(datastoreContext.getDataStoreName()),
86                 getConfigActorSystemProviderDependency().getActorSystem(), bundleContext);
87     }
88
89     public void setBundleContext(BundleContext bundleContext) {
90         this.bundleContext = bundleContext;
91     }
92 }