import org.opendaylight.mdsal.dom.api.DOMDataTreeShard;
import org.opendaylight.mdsal.dom.api.DOMDataTreeShardingConflictException;
import org.opendaylight.mdsal.dom.api.DOMDataTreeShardingService;
+import org.opendaylight.mdsal.dom.spi.DOMDataTreePrefixTable;
+import org.opendaylight.mdsal.dom.spi.DOMDataTreePrefixTableEntry;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreTreeChangePublisher;
import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
private static final Logger LOG = LoggerFactory.getLogger(ShardedDOMDataTree.class);
@GuardedBy("this")
- private final ShardingTable<ShardRegistration<?>> shards = ShardingTable.create();
+ private final DOMDataTreePrefixTable<ShardRegistration<?>> shards = DOMDataTreePrefixTable.create();
@GuardedBy("this")
- private final ShardingTable<DOMDataTreeProducer> producers = ShardingTable.create();
+ private final DOMDataTreePrefixTable<DOMDataTreeProducer> producers = DOMDataTreePrefixTable.create();
void removeShard(final ShardRegistration<?> reg) {
* and if it exists, check if its registration prefix does not collide with
* this registration.
*/
- final ShardingTableEntry<ShardRegistration<?>> parent = shards.lookup(prefix);
+ final DOMDataTreePrefixTableEntry<ShardRegistration<?>> parent = shards.lookup(prefix);
if (parent != null) {
parentReg = parent.getValue();
if (parentReg != null && prefix.equals(parentReg.getPrefix())) {
@GuardedBy("this")
private DOMDataTreeProducer findProducer(final DOMDataTreeIdentifier subtree) {
- ShardingTableEntry<DOMDataTreeProducer> producerEntry = producers.lookup(subtree);
+ DOMDataTreePrefixTableEntry<DOMDataTreeProducer> producerEntry = producers.lookup(subtree);
if (producerEntry != null) {
return producerEntry.getValue();
}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * 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.mdsal.dom.broker;
-
-import java.util.EnumMap;
-import java.util.Map;
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-final class ShardingTable<V> {
-
- private static final Logger LOG = LoggerFactory.getLogger(ShardingTable.class);
- private final Map<LogicalDatastoreType, ShardingTableEntry<V>> roots = new EnumMap<>(LogicalDatastoreType.class);
-
- private ShardingTable() {
-
- }
-
- static <V> ShardingTable<V> create() {
- return new ShardingTable<>();
- }
-
- ShardingTableEntry<V> lookup(final DOMDataTreeIdentifier prefix) {
- final ShardingTableEntry<V> t = roots.get(prefix.getDatastoreType());
- if (t == null) {
- return null;
- }
-
- return t.lookup(prefix.getRootIdentifier());
- }
-
- void store(final DOMDataTreeIdentifier prefix, final V reg) {
- ShardingTableEntry<V> t = roots.get(prefix.getDatastoreType());
- if (t == null) {
- t = new ShardingTableEntry<V>();
- roots.put(prefix.getDatastoreType(), t);
- }
-
- t.store(prefix.getRootIdentifier(), reg);
- }
-
- void remove(final DOMDataTreeIdentifier prefix) {
- final ShardingTableEntry<V> t = roots.get(prefix.getDatastoreType());
- if (t == null) {
- LOG.warn("Shard registration {} points to non-existent table", t);
- return;
- }
-
- t.remove(prefix.getRootIdentifier());
- }
-
-}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.mdsal.dom.spi;
+
+import com.google.common.annotations.Beta;
+import java.util.EnumMap;
+import java.util.Map;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import javax.annotation.concurrent.NotThreadSafe;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Prefix table indexed by {@link DOMDataTreeIdentifier}.
+ *
+ * Stores values in tree and provides lookup of closest ancestor
+ *
+ *
+ * @param <V> Value type
+ */
+@Beta
+@NotThreadSafe
+public final class DOMDataTreePrefixTable<V> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DOMDataTreePrefixTable.class);
+ private final Map<LogicalDatastoreType, DOMDataTreePrefixTableEntry<V>> roots = new EnumMap<>(LogicalDatastoreType.class);
+
+ private DOMDataTreePrefixTable() {
+
+ }
+
+ public static <V> DOMDataTreePrefixTable<V> create() {
+ return new DOMDataTreePrefixTable<>();
+ }
+
+ /**
+ *
+ * Lookups entry by provided {@link DOMDataTreeIdentifier}, if entry is not present returns
+ * closest non-null entry towards root or null if no entry towards root exists.
+ *
+ * @param prefix Prefix for lookup
+ * @return closest non-null entry towards root or null if no entry towards root exists.
+ */
+ public @Nullable DOMDataTreePrefixTableEntry<V> lookup(@Nonnull final DOMDataTreeIdentifier prefix) {
+ final DOMDataTreePrefixTableEntry<V> t = roots.get(prefix.getDatastoreType());
+ if (t == null) {
+ return null;
+ }
+
+ return t.lookup(prefix.getRootIdentifier());
+ }
+
+ /**
+ * Stores value associated to the prefix
+ *
+ * @param prefix DOM prefix of value
+ * @param value Value to be stored
+ * @throws IllegalStateException If value is already stored for provided prefix
+ */
+ public void store(@Nonnull final DOMDataTreeIdentifier prefix, @Nonnull final V value) {
+ DOMDataTreePrefixTableEntry<V> t = roots.get(prefix.getDatastoreType());
+ if (t == null) {
+ t = new DOMDataTreePrefixTableEntry<V>();
+ roots.put(prefix.getDatastoreType(), t);
+ }
+
+ t.store(prefix.getRootIdentifier(), value);
+ }
+
+ /**
+ * Removes value associated to the prefix.
+ *
+ * Value is removed only and only if full prefix match for stored value. Removal of prefix does
+ * not remove child prefixes.
+ *
+ * @param prefix
+ */
+ public void remove(@Nonnull final DOMDataTreeIdentifier prefix) {
+ final DOMDataTreePrefixTableEntry<V> t = roots.get(prefix.getDatastoreType());
+ if (t == null) {
+ LOG.warn("Shard registration {} points to non-existent table", t);
+ return;
+ }
+
+ t.remove(prefix.getRootIdentifier());
+ }
+
+}
* 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.mdsal.dom.broker;
+package org.opendaylight.mdsal.dom.spi;
+import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import javax.annotation.concurrent.NotThreadSafe;
import org.opendaylight.yangtools.concepts.Identifiable;
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;
-final class ShardingTableEntry<V> implements Identifiable<PathArgument> {
- private static final Logger LOG = LoggerFactory.getLogger(ShardingTableEntry.class);
+@Beta
+@NotThreadSafe
+public final class DOMDataTreePrefixTableEntry<V> implements Identifiable<PathArgument> {
+ private static final Logger LOG = LoggerFactory.getLogger(DOMDataTreePrefixTableEntry.class);
// FIXME: We do probably want to adapt map
- private final Map<PathArgument, ShardingTableEntry<V>> children = new HashMap<>();
+ private final Map<PathArgument, DOMDataTreePrefixTableEntry<V>> children = new HashMap<>();
private final PathArgument identifier;
private V value;
- ShardingTableEntry() {
+ DOMDataTreePrefixTableEntry() {
identifier = null;
}
- ShardingTableEntry(final PathArgument identifier) {
+ DOMDataTreePrefixTableEntry(final PathArgument identifier) {
this.identifier = Preconditions.checkNotNull(identifier);
}
return value;
}
- ShardingTableEntry<V> lookup(final YangInstanceIdentifier id) {
+ DOMDataTreePrefixTableEntry<V> lookup(final YangInstanceIdentifier id) {
final Iterator<PathArgument> it = id.getPathArguments().iterator();
- ShardingTableEntry<V> entry = this;
+ DOMDataTreePrefixTableEntry<V> entry = this;
while (it.hasNext()) {
final PathArgument a = it.next();
- final ShardingTableEntry<V> child = entry.children.get(a);
+ final DOMDataTreePrefixTableEntry<V> child = entry.children.get(a);
if (child == null) {
LOG.debug("Lookup of {} stopped at {}", id, a);
break;
void store(final YangInstanceIdentifier id, final V reg) {
final Iterator<PathArgument> it = id.getPathArguments().iterator();
- ShardingTableEntry<V> entry = this;
+ DOMDataTreePrefixTableEntry<V> entry = this;
while (it.hasNext()) {
final PathArgument a = it.next();
- ShardingTableEntry<V> child = entry.children.get(a);
+ DOMDataTreePrefixTableEntry<V> child = entry.children.get(a);
if (child == null) {
- child = new ShardingTableEntry<>(a);
+ child = new DOMDataTreePrefixTableEntry<>(a);
entry.children.put(a, child);
}
// TODO: Is this correct? We want to enter child
private boolean remove(final Iterator<PathArgument> it) {
if (it.hasNext()) {
final PathArgument arg = it.next();
- final ShardingTableEntry<V> child = children.get(arg);
+ final DOMDataTreePrefixTableEntry<V> child = children.get(arg);
if (child != null) {
if (child.remove(it)) {
children.remove(arg);