8a1018586bb5273c2f992fb22c2e0ce84770c2a4
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / config / yang / config / distributed_entity_ownership_service / DistributedEntityOwnershipServiceProviderModule.java
1 /*
2  * Copyright (c) 2015 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.config.yang.config.distributed_entity_ownership_service;
10
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.controller.cluster.datastore.DistributedDataStore;
13 import org.opendaylight.controller.cluster.datastore.entityownership.DistributedEntityOwnershipService;
14 import org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.EntityOwnerSelectionStrategyConfig;
15 import org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.EntityOwnerSelectionStrategyConfigReader;
16 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
17 import org.osgi.framework.BundleContext;
18
19
20 public class DistributedEntityOwnershipServiceProviderModule extends org.opendaylight.controller.config.yang.config.distributed_entity_ownership_service.AbstractDistributedEntityOwnershipServiceProviderModule {
21     private BundleContext bundleContext;
22
23     public DistributedEntityOwnershipServiceProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
24         super(identifier, dependencyResolver);
25     }
26
27     public DistributedEntityOwnershipServiceProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.config.distributed_entity_ownership_service.DistributedEntityOwnershipServiceProviderModule oldModule, java.lang.AutoCloseable oldInstance) {
28         super(identifier, dependencyResolver, oldModule, oldInstance);
29     }
30
31     @Override
32     public void customValidation() {
33         // add custom validation form module attributes here.
34     }
35
36     @Override
37     public boolean canReuseInstance(AbstractDistributedEntityOwnershipServiceProviderModule oldModule) {
38         return true;
39     }
40
41     @Override
42     public java.lang.AutoCloseable createInstance() {
43         DOMStore dataStore = getDataStoreDependency();
44         Preconditions.checkArgument(dataStore instanceof DistributedDataStore,
45                 "Injected DOMStore must be an instance of DistributedDataStore");
46         EntityOwnerSelectionStrategyConfig strategyConfig = new EntityOwnerSelectionStrategyConfigReader(bundleContext).getConfig();
47         DistributedEntityOwnershipService service = new DistributedEntityOwnershipService((DistributedDataStore)dataStore, strategyConfig);
48         service.start();
49         return service;
50     }
51
52     public void setBundleContext(BundleContext bundleContext) {
53         this.bundleContext = bundleContext;
54     }
55 }