X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fclustered-data-store%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fdatastore%2Finternal%2FClusteredDataStoreManager.java;h=b0a099ff90e0e26f1fd408f6574c718529673590;hp=e6acdb0c3be0a0221c63a014bf11d7bcaeeb00ce;hb=d6c7e80b4372f994640863af3066039527c8d3e9;hpb=d542617f3486541cf9937009fb6aa1e3f2c9f0e2 diff --git a/opendaylight/md-sal/clustered-data-store/implementation/src/main/java/org/opendaylight/controller/datastore/internal/ClusteredDataStoreManager.java b/opendaylight/md-sal/clustered-data-store/implementation/src/main/java/org/opendaylight/controller/datastore/internal/ClusteredDataStoreManager.java index e6acdb0c3b..b0a099ff90 100644 --- a/opendaylight/md-sal/clustered-data-store/implementation/src/main/java/org/opendaylight/controller/datastore/internal/ClusteredDataStoreManager.java +++ b/opendaylight/md-sal/clustered-data-store/implementation/src/main/java/org/opendaylight/controller/datastore/internal/ClusteredDataStoreManager.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -7,69 +6,136 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ - - package org.opendaylight.controller.datastore.internal; +import java.util.Hashtable; + import com.google.common.base.Preconditions; -import org.apache.felix.dm.Component; + import org.opendaylight.controller.clustering.services.CacheConfigException; -import org.opendaylight.controller.clustering.services.CacheExistException; import org.opendaylight.controller.clustering.services.IClusterGlobalServices; import org.opendaylight.controller.datastore.ClusteredDataStore; import org.opendaylight.controller.md.sal.common.api.data.DataModification; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.util.tracker.ServiceTracker; +import org.osgi.util.tracker.ServiceTrackerCustomizer; -public class ClusteredDataStoreManager implements ClusteredDataStore { +public class ClusteredDataStoreManager implements // + ClusteredDataStore, // + ServiceTrackerCustomizer, // + AutoCloseable { - private ClusteredDataStoreImpl clusteredDataStore = null; + private ClusteredDataStore clusteredDataStore = null; private IClusterGlobalServices clusterGlobalServices = null; + private BundleContext context; + + private ServiceReference firstClusterGlobalReference; + private ServiceTracker clusterTracker; @Override - public DataCommitTransaction, Object> requestCommit(DataModification, Object> modification) { + public DataCommitTransaction requestCommit( + DataModification modification) { Preconditions.checkState(clusteredDataStore != null, "clusteredDataStore cannot be null"); return clusteredDataStore.requestCommit(modification); } @Override - public Object readOperationalData(InstanceIdentifier path) { + public CompositeNode readOperationalData(InstanceIdentifier path) { Preconditions.checkState(clusteredDataStore != null, "clusteredDataStore cannot be null"); return clusteredDataStore.readOperationalData(path); } @Override - public Object readConfigurationData(InstanceIdentifier path) { + public CompositeNode readConfigurationData(InstanceIdentifier path) { Preconditions.checkState(clusteredDataStore != null, "clusteredDataStore cannot be null"); return clusteredDataStore.readConfigurationData(path); } + public Iterable getStoredConfigurationPaths() { + Preconditions.checkState(clusteredDataStore != null, "clusteredDataStore cannot be null"); + return clusteredDataStore.getStoredConfigurationPaths(); + } + + public Iterable getStoredOperationalPaths() { + Preconditions.checkState(clusteredDataStore != null, "clusteredDataStore cannot be null"); + return clusteredDataStore.getStoredOperationalPaths(); + } - public void setClusterGlobalServices(IClusterGlobalServices clusterGlobalServices){ + public boolean containsConfigurationPath(InstanceIdentifier path) { + Preconditions.checkState(clusteredDataStore != null, "clusteredDataStore cannot be null"); + return clusteredDataStore.containsConfigurationPath(path); + } + + public boolean containsOperationalPath(InstanceIdentifier path) { + Preconditions.checkState(clusteredDataStore != null, "clusteredDataStore cannot be null"); + return clusteredDataStore.containsOperationalPath(path); + } + + public void setClusterGlobalServices(IClusterGlobalServices clusterGlobalServices) { this.clusterGlobalServices = clusterGlobalServices; + try { + // Adding creation of the clustered data store in its own method + // to make the method unit testable + clusteredDataStore = createClusteredDataStore(); + } catch (CacheConfigException e) { + throw new IllegalStateException("could not construct clusteredDataStore"); + } } - public void unsetClusterGlobalServices(IClusterGlobalServices clusterGlobalServices){ - this.clusterGlobalServices = null; - this.clusteredDataStore = null; + @Override + public IClusterGlobalServices addingService(ServiceReference reference) { + if (clusterGlobalServices == null) { + setClusterGlobalServices(context.getService(reference)); + return clusterGlobalServices; + } + return null; + } + + @Override + public void modifiedService(ServiceReference reference, IClusterGlobalServices service) { + + } + + @Override + public void removedService(ServiceReference reference, IClusterGlobalServices service) { + if (clusterGlobalServices == service) { + clusterGlobalServices = null; + clusteredDataStore = null; + } } + public BundleContext getContext() { + return context; + } + public void setContext(BundleContext context) { + this.context = context; + } + + /** * Function called by the dependency manager when all the required * dependencies are satisfied - * + * */ - void init(Component c) { - try { - //Adding creation of the clustered data store in its own method to make the method unit testable - clusteredDataStore = createClusteredDataStore(c); - } catch (CacheExistException e) { - throw new IllegalStateException("could not construct clusteredDataStore"); - } catch (CacheConfigException e) { - throw new IllegalStateException("could not construct clusteredDataStore"); + public void start() { + if (context != null) { + clusterTracker = new ServiceTracker<>(context, IClusterGlobalServices.class, this); + clusterTracker.open(); + + context.registerService(ClusteredDataStore.class, this, new Hashtable()); } } - protected ClusteredDataStoreImpl createClusteredDataStore(Component c) throws CacheExistException,CacheConfigException{ - return new ClusteredDataStoreImpl(clusterGlobalServices); + + protected ClusteredDataStore createClusteredDataStore() throws CacheConfigException { + return new ClusteredDataStoreImpl(clusterGlobalServices); + } + + @Override + public void close() throws Exception { + clusterTracker.close(); } }