X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Futils%2FActorContext.java;h=792064cd6700cc2d0cf6a09423e8964ee980eab1;hb=refs%2Fchanges%2F20%2F28420%2F6;hp=ad05a1ca71001285a8aed1f5afe16b1f511f3e96;hpb=daaef05cbf70e6cbec9af181258faead6d9620a6;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java index ad05a1ca71..792064cd67 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java @@ -15,30 +15,21 @@ import akka.actor.ActorSelection; import akka.actor.ActorSystem; import akka.actor.Address; import akka.actor.PoisonPill; -import akka.dispatch.Futures; import akka.dispatch.Mapper; import akka.dispatch.OnComplete; import akka.pattern.AskTimeoutException; import akka.util.Timeout; import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.Timer; -import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.base.Strings; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.RemovalListener; -import com.google.common.cache.RemovalNotification; -import com.google.common.util.concurrent.RateLimiter; -import java.util.ArrayList; -import java.util.Collection; import java.util.concurrent.TimeUnit; -import javax.annotation.concurrent.GuardedBy; -import org.opendaylight.controller.cluster.common.actor.CommonConfig; import org.opendaylight.controller.cluster.datastore.ClusterWrapper; -import org.opendaylight.controller.cluster.datastore.Configuration; +import org.opendaylight.controller.cluster.datastore.DataStoreVersions; import org.opendaylight.controller.cluster.datastore.DatastoreContext; +import org.opendaylight.controller.cluster.datastore.DatastoreContextFactory; +import org.opendaylight.controller.cluster.datastore.config.Configuration; import org.opendaylight.controller.cluster.datastore.exceptions.LocalShardNotFoundException; import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException; import org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException; @@ -53,6 +44,7 @@ import org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo; import org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound; import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext; +import org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategyFactory; import org.opendaylight.controller.cluster.reporting.MetricsReporter; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -70,7 +62,7 @@ import scala.concurrent.duration.FiniteDuration; * easily. An ActorContext can be freely passed around to local object instances * but should not be passed to actors especially remote actors */ -public class ActorContext implements RemovalListener> { +public class ActorContext { private static final Logger LOG = LoggerFactory.getLogger(ActorContext.class); private static final String DISTRIBUTED_DATA_STORE_METRIC_REGISTRY = "distributed-data-store"; private static final String METRIC_RATE = "rate"; @@ -90,6 +82,7 @@ public class ActorContext implements RemovalListener> primaryShardInfoCache; private volatile SchemaContext schemaContext; private volatile boolean updated; private final MetricRegistry metricRegistry = MetricsReporter.getInstance(DatastoreContext.METRICS_DOMAIN).getMetricsRegistry(); - @GuardedBy("shardInfoListeners") - private final Collection> shardInfoListeners = new ArrayList<>(); + + private final PrimaryShardInfoFutureCache primaryShardInfoCache; + private final ShardStrategyFactory shardStrategyFactory; public ActorContext(ActorSystem actorSystem, ActorRef shardManager, ClusterWrapper clusterWrapper, Configuration configuration) { this(actorSystem, shardManager, clusterWrapper, configuration, - DatastoreContext.newBuilder().build()); + DatastoreContext.newBuilder().build(), new PrimaryShardInfoFutureCache()); } public ActorContext(ActorSystem actorSystem, ActorRef shardManager, ClusterWrapper clusterWrapper, Configuration configuration, - DatastoreContext datastoreContext) { + DatastoreContext datastoreContext, PrimaryShardInfoFutureCache primaryShardInfoCache) { this.actorSystem = actorSystem; this.shardManager = shardManager; this.clusterWrapper = clusterWrapper; this.configuration = configuration; this.datastoreContext = datastoreContext; this.dispatchers = new Dispatchers(actorSystem.dispatchers()); + this.primaryShardInfoCache = primaryShardInfoCache; + this.shardStrategyFactory = new ShardStrategyFactory(configuration); setCachedProperties(); @@ -137,24 +131,18 @@ public class ActorContext implements RemovalListener reg : shardInfoListeners) { - reg.getInstance().onShardInfoUpdated(shardName, info); - } - } + PrimaryShardInfo info = new PrimaryShardInfo(actorSelection, primaryVersion, + Optional.fromNullable(localShardDataTree)); + primaryShardInfoCache.putSuccessful(shardName, info); return info; } @@ -430,6 +415,10 @@ public class ActorContext implements RemovalListener doAsk(ActorRef actorRef, Object message, Timeout timeout){ return ask(actorRef, message, timeout); } @@ -576,32 +548,7 @@ public class ActorContext implements RemovalListener> getPrimaryShardInfoCache() { + public PrimaryShardInfoFutureCache getPrimaryShardInfoCache() { return primaryShardInfoCache; } - - public ShardInfoListenerRegistration registerShardInfoListener(final T listener) { - final ShardInfoListenerRegistration reg = new ShardInfoListenerRegistration(listener, this); - - synchronized (shardInfoListeners) { - shardInfoListeners.add(reg); - } - return reg; - } - - protected void removeShardInfoListener(final ShardInfoListenerRegistration registration) { - synchronized (shardInfoListeners) { - shardInfoListeners.remove(registration); - } - } - - @Override - public void onRemoval(final RemovalNotification> notification) { - synchronized (shardInfoListeners) { - for (ShardInfoListenerRegistration reg : shardInfoListeners) { - reg.getInstance().onShardInfoUpdated(notification.getKey(), null); - } - } - } }