X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fclustering%2Fservices_implementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fclustering%2Fservices_implementation%2Finternal%2FClusterManagerCommon.java;h=61681bc90add8d596a69658720cd170a65c9cd32;hb=312dabba7b74f8d0e78ef698a01866095eca912d;hp=7bf495426f61cfb4d177583b157beafa873d6edf;hpb=69bbdbb02e3f4755b95fa62b9a3610a3a11c9724;p=controller.git diff --git a/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerCommon.java b/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerCommon.java index 7bf495426f..61681bc90a 100644 --- a/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerCommon.java +++ b/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerCommon.java @@ -10,11 +10,15 @@ package org.opendaylight.controller.clustering.services_implementation.internal; import java.net.InetAddress; +import java.util.Collections; +import java.util.Dictionary; +import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; - import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; import javax.transaction.NotSupportedException; @@ -22,7 +26,7 @@ import javax.transaction.RollbackException; import javax.transaction.SystemException; import javax.transaction.Transaction; import javax.transaction.TransactionManager; - +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.CacheListenerAddException; @@ -35,20 +39,13 @@ import org.opendaylight.controller.clustering.services.ListenRoleChangeAddExcept import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Dictionary; -import java.util.Collections; -import java.util.HashSet; -import org.apache.felix.dm.Component; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -abstract public class ClusterManagerCommon implements IClusterServicesCommon { +public abstract class ClusterManagerCommon implements IClusterServicesCommon { protected String containerName = null; - private IClusterServices clusterService = null; + protected IClusterServices clusterService = null; protected static final Logger logger = LoggerFactory .getLogger(ClusterManagerCommon.class); - private Set cacheUpdateAware = Collections - .synchronizedSet(new HashSet()); + private ConcurrentMap cacheUpdateAware = + new ConcurrentHashMap(); private Set coordinatorChangeAware = Collections .synchronizedSet(new HashSet()); private ListenCoordinatorChange coordinatorChangeListener = null; @@ -85,15 +82,60 @@ abstract public class ClusterManagerCommon implements IClusterServicesCommon { } } - void setCacheUpdateAware(ICacheUpdateAware s) { + void setCacheUpdateAware(Map props, ICacheUpdateAware s) { + logger.trace("CacheUpdateAware being set on container:{}", + this.containerName); if (this.cacheUpdateAware != null) { - this.cacheUpdateAware.add(s); + Set caches = (Set)props.get("cachenames"); + if (caches != null) { + logger.trace("cachenames provided below:"); + for (String cache : caches) { + if (this.cacheUpdateAware.get(cache) != null) { + logger.error("cachename:{} on container:{} has " + + "already a listener", cache, + this.containerName); + } else { + GetUpdatesContainer up = + new GetUpdatesContainer(s, this.containerName, + cache); + if (up != null) { + try { + this.clusterService.addListener(this.containerName, + cache, up); + this.cacheUpdateAware.put(cache, up); + logger.trace("cachename:{} on container:{} has " + + "been registered", cache, + this.containerName); + } catch (CacheListenerAddException exc) { + // Do nothing, the important is that + // we don't register the listener in + // the shadow, and we are not doing + // that. + } + } + } + } + } } } - void unsetCacheUpdateAware(ICacheUpdateAware s) { + void unsetCacheUpdateAware(Map props, ICacheUpdateAware s) { + logger.trace("CacheUpdateAware being unset on container:{}", + this.containerName); if (this.cacheUpdateAware != null) { - this.cacheUpdateAware.remove(s); + Set caches = (Set)props.get("cachenames"); + if (caches != null) { + logger.trace("cachenames provided below:"); + GetUpdatesContainer up = null; + for (String cache : caches) { + up = this.cacheUpdateAware.get(cache); + if (up != null) { + this.cacheUpdateAware.remove(cache); + this.clusterService.removeListener(this.containerName, + cache, up); + } + } + } } }