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%2Fsharding%2FDistributedShardFrontend.java;h=4d7f4ef36d8c52fee192e761a2e0a22065e10833;hb=refs%2Fchanges%2F70%2F91770%2F4;hp=76648974799aee9d1ebfb80476a98586ef070454;hpb=61791b72e0137609d15c18efc64d227b6a4006ec;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardFrontend.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardFrontend.java index 7664897479..4d7f4ef36d 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardFrontend.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardFrontend.java @@ -5,19 +5,19 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.cluster.sharding; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; +import static java.util.Objects.requireNonNull; + import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.annotation.Nonnull; -import javax.annotation.concurrent.GuardedBy; +import org.checkerframework.checker.lock.qual.GuardedBy; import org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient; -import org.opendaylight.controller.cluster.datastore.DistributedDataStore; +import org.opendaylight.controller.cluster.datastore.DistributedDataStoreInterface; import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener; import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.mdsal.dom.api.DOMDataTreeShard; @@ -29,7 +29,6 @@ import org.opendaylight.mdsal.dom.spi.shard.SubshardProducerSpecification; import org.opendaylight.mdsal.dom.spi.shard.WriteableDOMDataTreeShard; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,21 +45,24 @@ class DistributedShardFrontend implements ReadableWriteableDOMDataTreeShard { private final Map childShards = new HashMap<>(); @GuardedBy("this") private final List producers = new ArrayList<>(); - private final DistributedDataStore distributedDataStore; - DistributedShardFrontend(final DistributedDataStore distributedDataStore, + private final DistributedShardChangePublisher publisher; + + DistributedShardFrontend(final DistributedDataStoreInterface distributedDataStore, final DataStoreClient client, final DOMDataTreeIdentifier shardRoot) { - this.distributedDataStore = Preconditions.checkNotNull(distributedDataStore); - this.client = Preconditions.checkNotNull(client); - this.shardRoot = Preconditions.checkNotNull(shardRoot); + this.client = requireNonNull(client); + this.shardRoot = requireNonNull(shardRoot); + + publisher = new DistributedShardChangePublisher(client, requireNonNull(distributedDataStore), shardRoot, + childShards); } @Override public synchronized DOMDataTreeShardProducer createProducer(final Collection paths) { for (final DOMDataTreeIdentifier prodPrefix : paths) { - Preconditions.checkArgument(paths.contains(prodPrefix), "Prefix %s is not contained under shard root", - prodPrefix, paths); + checkArgument(shardRoot.contains(prodPrefix), "Prefix %s is not contained under shard root", prodPrefix, + paths); } final ShardProxyProducer ret = @@ -72,7 +74,7 @@ class DistributedShardFrontend implements ReadableWriteableDOMDataTreeShard { @Override public synchronized void onChildAttached(final DOMDataTreeIdentifier prefix, final DOMDataTreeShard child) { LOG.debug("{} : Child shard attached at {}", shardRoot, prefix); - Preconditions.checkArgument(child != this, "Attempted to attach child %s onto self", this); + checkArgument(child != this, "Attempted to attach child %s onto self", this); addChildShard(prefix, child); updateProducers(); } @@ -86,7 +88,7 @@ class DistributedShardFrontend implements ReadableWriteableDOMDataTreeShard { } private void addChildShard(final DOMDataTreeIdentifier prefix, final DOMDataTreeShard child) { - Preconditions.checkArgument(child instanceof WriteableDOMDataTreeShard); + checkArgument(child instanceof WriteableDOMDataTreeShard); childShards.put(prefix, new ChildShardContext(prefix, (WriteableDOMDataTreeShard) child)); } @@ -106,11 +108,8 @@ class DistributedShardFrontend implements ReadableWriteableDOMDataTreeShard { continue; } - SubshardProducerSpecification spec = affectedSubshards.get(maybeAffected.getPrefix()); - if (spec == null) { - spec = new SubshardProducerSpecification(maybeAffected); - affectedSubshards.put(maybeAffected.getPrefix(), spec); - } + SubshardProducerSpecification spec = affectedSubshards.computeIfAbsent(maybeAffected.getPrefix(), + k -> new SubshardProducerSpecification(maybeAffected)); spec.addPrefix(bindPath); } } @@ -133,46 +132,9 @@ class DistributedShardFrontend implements ReadableWriteableDOMDataTreeShard { } } - @Nonnull @Override - @SuppressWarnings("unchecked") public ListenerRegistration registerTreeChangeListener( final YangInstanceIdentifier treeId, final L listener) { - - final List toStrip = new ArrayList<>(shardRoot.getRootIdentifier().getPathArguments()); - final List stripFrom = new ArrayList<>(treeId.getPathArguments()); - - while (!toStrip.isEmpty()) { - stripFrom.remove(0); - toStrip.remove(0); - } - - return (ListenerRegistration) new ProxyRegistration(distributedDataStore - .registerProxyListener(treeId, YangInstanceIdentifier.create(stripFrom), listener), listener); + return publisher.registerTreeChangeListener(treeId, listener); } - - private static class ProxyRegistration implements ListenerRegistration { - - private ListenerRegistration proxy; - private DOMDataTreeChangeListener listener; - - private ProxyRegistration( - final ListenerRegistration< - org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener> proxy, - final DOMDataTreeChangeListener listener) { - this.proxy = proxy; - this.listener = listener; - } - - @Override - public DOMDataTreeChangeListener getInstance() { - return listener; - } - - @Override - public void close() { - proxy.close(); - } - } - }