2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.config.yang.config.distributed_entity_ownership_service;
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;
22 public class DistributedEntityOwnershipServiceProviderModule extends AbstractDistributedEntityOwnershipServiceProviderModule {
23 private EntityOwnerSelectionStrategyConfig strategyConfig;
24 private BundleContext bundleContext;
26 public DistributedEntityOwnershipServiceProviderModule(final ModuleIdentifier identifier,
27 final DependencyResolver dependencyResolver) {
28 super(identifier, dependencyResolver);
31 public DistributedEntityOwnershipServiceProviderModule(final ModuleIdentifier identifier,
32 final DependencyResolver dependencyResolver,
33 final DistributedEntityOwnershipServiceProviderModule oldModule, final AutoCloseable oldInstance) {
34 super(identifier, dependencyResolver, oldModule, oldInstance);
38 public void customValidation() {
39 strategyConfig = EntityOwnerSelectionStrategyConfigReader.loadStrategyWithConfig(bundleContext);
43 public boolean canReuseInstance(final AbstractDistributedEntityOwnershipServiceProviderModule oldModule) {
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");
54 final ActorContext context = ((DistributedDataStore)dataStore).getActorContext();
55 return DistributedEntityOwnershipService.start(context, strategyConfig);
58 public void setBundleContext(final BundleContext bundleContext) {
59 // What do we need from the bundle context?
60 this.bundleContext = bundleContext;