c0a45852cc6db2e9a60bab225b757cb06c3068d5
[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.cluster.datastore.utils.ActorContext;
17 import org.opendaylight.controller.config.api.DependencyResolver;
18 import org.opendaylight.controller.config.api.ModuleIdentifier;
19 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
20 import org.osgi.framework.BundleContext;
21
22 public class DistributedEntityOwnershipServiceProviderModule extends AbstractDistributedEntityOwnershipServiceProviderModule {
23     private EntityOwnerSelectionStrategyConfig strategyConfig;
24     private BundleContext bundleContext;
25
26     public DistributedEntityOwnershipServiceProviderModule(final ModuleIdentifier identifier,
27             final DependencyResolver dependencyResolver) {
28         super(identifier, dependencyResolver);
29     }
30
31     public DistributedEntityOwnershipServiceProviderModule(final ModuleIdentifier identifier,
32             final DependencyResolver dependencyResolver,
33             final DistributedEntityOwnershipServiceProviderModule oldModule, final AutoCloseable oldInstance) {
34         super(identifier, dependencyResolver, oldModule, oldInstance);
35     }
36
37     @Override
38     public void customValidation() {
39         strategyConfig = EntityOwnerSelectionStrategyConfigReader.loadStrategyWithConfig(bundleContext);
40     }
41
42     @Override
43     public boolean canReuseInstance(final AbstractDistributedEntityOwnershipServiceProviderModule oldModule) {
44         return true;
45     }
46
47     @Override
48     public AutoCloseable createInstance() {
49         // FIXME: EntityOwnership needs only the ActorContext, not the entire datastore
50         DOMStore dataStore = getDataStoreDependency();
51         Preconditions.checkArgument(dataStore instanceof DistributedDataStore,
52                 "Injected DOMStore must be an instance of DistributedDataStore");
53
54         final ActorContext context = ((DistributedDataStore)dataStore).getActorContext();
55         return DistributedEntityOwnershipService.start(context, strategyConfig);
56     }
57
58     public void setBundleContext(final BundleContext bundleContext) {
59         // What do we need from the bundle context?
60         this.bundleContext = bundleContext;
61     }
62 }