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=b4b44449c9972df3d4883d115e9e0044e01834d7;hb=048d61c7408875c1483d912c5837ae36fd689304;hp=f91dc3b2600dd09a5ed815b4d7a24f391d527404;hpb=2d60632f7cf63712e8357a3cf3fc40d83366e5e6;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 f91dc3b260..b4b44449c9 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 @@ -8,7 +8,6 @@ package org.opendaylight.controller.cluster.sharding; -import com.google.common.base.Optional; import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.Collection; @@ -17,6 +16,7 @@ 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; @@ -39,10 +39,10 @@ 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.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.api.schema.tree.TreeType; import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory; import org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaValidationFailedException; import org.slf4j.Logger; @@ -70,11 +70,27 @@ public class DistributedShardChangePublisher // TODO keeping the whole dataTree thats contained in subshards doesn't seem like a good idea // maybe the whole listener logic would be better in the backend shards where we have direct access to the // dataTree and wont have to cache it redundantly. - this.dataTree = InMemoryDataTreeFactory.getInstance().create( - TreeType.valueOf(prefix.getDatastoreType().name()), prefix.getRootIdentifier()); - dataTree.setSchemaContext(distributedDataStore.getActorContext().getSchemaContext()); + final DataTreeConfiguration baseConfig; + switch (prefix.getDatastoreType()) { + case CONFIGURATION: + baseConfig = DataTreeConfiguration.DEFAULT_CONFIGURATION; + break; + case OPERATIONAL: + baseConfig = DataTreeConfiguration.DEFAULT_OPERATIONAL; + break; + default: + throw new UnsupportedOperationException("Unknown prefix type " + prefix.getDatastoreType()); + } + + this.dataTree = new InMemoryDataTreeFactory().create(new DataTreeConfiguration.Builder(baseConfig.getTreeType()) + .setMandatoryNodesValidation(baseConfig.isMandatoryNodesValidationEnabled()) + .setUniqueIndexes(baseConfig.isUniqueIndexEnabled()) + .setRootPath(prefix.getRootIdentifier()) + .build()); + // XXX: can we guarantee that the root is present in the schemacontext? + this.dataTree.setSchemaContext(distributedDataStore.getActorContext().getSchemaContext()); this.shardPath = prefix.getRootIdentifier(); this.childShards = childShards; } @@ -138,8 +154,8 @@ 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 = @@ -149,7 +165,7 @@ public class DistributedShardChangePublisher listener.close(); DistributedShardChangePublisher.this.removeRegistration(node, this); registrationRemoved(this); - proxyReg.close(); + listenerReg.close(); } }; addRegistration(node, registration); @@ -178,30 +194,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(); @@ -363,13 +355,13 @@ public class DistributedShardChangePublisher @Nonnull @Override public Optional> getDataAfter() { - return Optional.absent(); + return Optional.empty(); } @Nonnull @Override public Optional> getDataBefore() { - return Optional.absent(); + return Optional.empty(); } } }