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%2FDistributedShardChangePublisher.java;h=bcb73dbce2f50d418b3388aa5d2c37e145810c20;hb=refs%2Fchanges%2F70%2F91770%2F4;hp=759410a26eaf9a17fc33ff1e09ffbe9d11f2e701;hpb=20a32e6459fd1e27e7669bf1ebc7742b96787b94;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardChangePublisher.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardChangePublisher.java index 759410a26e..bcb73dbce2 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardChangePublisher.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardChangePublisher.java @@ -5,10 +5,11 @@ * 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.checkState; +import static java.util.Objects.requireNonNull; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -16,14 +17,11 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -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.AbstractDataStore; +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.spi.AbstractDOMDataTreeChangeListenerRegistration; @@ -34,15 +32,14 @@ import org.opendaylight.mdsal.dom.spi.store.DOMStoreTreeChangePublisher; 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.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNodes; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; -import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType; import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory; import org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaValidationFailedException; import org.slf4j.Logger; @@ -54,7 +51,7 @@ public class DistributedShardChangePublisher private static final Logger LOG = LoggerFactory.getLogger(DistributedShardChangePublisher.class); - private final AbstractDataStore distributedDataStore; + private final DistributedDataStoreInterface distributedDataStore; private final YangInstanceIdentifier shardPath; private final Map childShards; @@ -63,7 +60,7 @@ public class DistributedShardChangePublisher private final DataTree dataTree; public DistributedShardChangePublisher(final DataStoreClient client, - final AbstractDataStore distributedDataStore, + final DistributedDataStoreInterface distributedDataStore, final DOMDataTreeIdentifier prefix, final Map childShards) { this.distributedDataStore = distributedDataStore; @@ -90,7 +87,7 @@ public class DistributedShardChangePublisher .build()); // XXX: can we guarantee that the root is present in the schemacontext? - this.dataTree.setSchemaContext(distributedDataStore.getActorContext().getSchemaContext()); + this.dataTree.setEffectiveModelContext(distributedDataStore.getActorUtils().getSchemaContext()); this.shardPath = prefix.getRootIdentifier(); this.childShards = childShards; } @@ -154,18 +151,18 @@ public class DistributedShardChangePublisher findNodeFor(listenerPath.getPathArguments()); // register listener in CDS - final ProxyRegistration proxyReg = new ProxyRegistration(distributedDataStore - .registerProxyListener(shardLookup, listenerPath, listener), listener); + ListenerRegistration listenerReg = distributedDataStore + .registerProxyListener(shardLookup, listenerPath, listener); @SuppressWarnings("unchecked") final AbstractDOMDataTreeChangeListenerRegistration registration = - new AbstractDOMDataTreeChangeListenerRegistration((L) listener) { + new AbstractDOMDataTreeChangeListenerRegistration<>((L) listener) { @Override protected void removeRegistration() { listener.close(); DistributedShardChangePublisher.this.removeRegistration(node, this); registrationRemoved(this); - proxyReg.close(); + listenerReg.close(); } }; addRegistration(node, registration); @@ -194,30 +191,6 @@ public class DistributedShardChangePublisher return listenerPathArgs; } - private static final class ProxyRegistration implements ListenerRegistration { - - private final ListenerRegistration proxy; - private final 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(); - } - } - synchronized DataTreeCandidate applyChanges(final YangInstanceIdentifier listenerPath, final Collection changes) throws DataValidationFailedException { final DataTreeModification modification = dataTree.takeSnapshot().newModification(); @@ -225,7 +198,7 @@ public class DistributedShardChangePublisher try { DataTreeCandidates.applyToModification(modification, change); } catch (SchemaValidationFailedException e) { - LOG.error("Validation failed {}", e); + LOG.error("Validation failed", e); } } @@ -243,11 +216,12 @@ public class DistributedShardChangePublisher DataTreeCandidateNode modifiedChild = candidate.getRootNode(); for (final PathArgument pathArgument : listenerPath.getPathArguments()) { - modifiedChild = modifiedChild.getModifiedChild(pathArgument); + modifiedChild = modifiedChild.getModifiedChild(pathArgument).orElse(null); } + if (modifiedChild == null) { - modifiedChild = new EmptyDataTreeCandidateNode(dataTree.getRootPath().getLastPathArgument()); + modifiedChild = DataTreeCandidateNodes.empty(dataTree.getRootPath().getLastPathArgument()); } return DataTreeCandidates.newDataTreeCandidate(dataTree.getRootPath(), modifiedChild); @@ -266,12 +240,12 @@ public class DistributedShardChangePublisher DOMDataTreeListenerWithSubshards(final YangInstanceIdentifier listenerPath, final DOMDataTreeChangeListener delegate) { - this.listenerPath = Preconditions.checkNotNull(listenerPath); - this.delegate = Preconditions.checkNotNull(delegate); + this.listenerPath = requireNonNull(listenerPath); + this.delegate = requireNonNull(delegate); } @Override - public synchronized void onDataTreeChanged(@Nonnull final Collection changes) { + public synchronized void onDataTreeChanged(final Collection changes) { LOG.debug("Received data changed {}", changes); if (!stashedDataTreeCandidates.isEmpty()) { @@ -324,7 +298,7 @@ public class DistributedShardChangePublisher } void addSubshard(final ChildShardContext context) { - Preconditions.checkState(context.getShard() instanceof DOMStoreTreeChangePublisher, + checkState(context.getShard() instanceof DOMStoreTreeChangePublisher, "All subshards that are initialDataChangeEvent part of ListenerContext need to be listenable"); final DOMStoreTreeChangePublisher listenableShard = (DOMStoreTreeChangePublisher) context.getShard(); @@ -342,50 +316,4 @@ public class DistributedShardChangePublisher registrations.clear(); } } - - private static final class EmptyDataTreeCandidateNode implements DataTreeCandidateNode { - - private final PathArgument identifier; - - EmptyDataTreeCandidateNode(final PathArgument identifier) { - this.identifier = Preconditions.checkNotNull(identifier, "Identifier should not be null"); - } - - @Nonnull - @Override - public PathArgument getIdentifier() { - return identifier; - } - - @Nonnull - @Override - public Collection getChildNodes() { - return Collections.emptySet(); - } - - @Nullable - @Override - @SuppressWarnings("checkstyle:hiddenField") - public DataTreeCandidateNode getModifiedChild(final PathArgument identifier) { - return null; - } - - @Nonnull - @Override - public ModificationType getModificationType() { - return ModificationType.UNMODIFIED; - } - - @Nonnull - @Override - public Optional> getDataAfter() { - return Optional.empty(); - } - - @Nonnull - @Override - public Optional> getDataBefore() { - return Optional.empty(); - } - } }