+++ /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.controller.md.sal.dom.api;
-
-import com.google.common.base.Preconditions;
-
-/**
- * Failure reported when a data tree is no longer accessible.
- *
- * @deprecated Use {@link org.opendaylight.mdsal.dom.api.DOMDataTreeInaccessibleException} instead.
- */
-@Deprecated
-public class DOMDataTreeInaccessibleException extends DOMDataTreeListeningException {
- private static final long serialVersionUID = 1L;
- private final DOMDataTreeIdentifier treeIdentifier;
-
- public DOMDataTreeInaccessibleException(final DOMDataTreeIdentifier treeIdentifier, final String message) {
- super(message);
- this.treeIdentifier = Preconditions.checkNotNull(treeIdentifier);
- }
-
- public DOMDataTreeInaccessibleException(final DOMDataTreeIdentifier treeIdentifier, final String message,
- final Throwable cause) {
- super(message);
- this.treeIdentifier = Preconditions.checkNotNull(treeIdentifier);
- }
-
- public final DOMDataTreeIdentifier getTreeIdentifier() {
- return treeIdentifier;
- }
-}
+++ /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.controller.md.sal.dom.api;
-
-import java.util.Collection;
-import java.util.EventListener;
-import java.util.Map;
-import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
-
-/**
- * Interface implemented by data consumers, e.g. processes wanting to act on data
- * after it has been introduced to the conceptual data tree.
- *
- * @deprecated Use {@link org.opendaylight.mdsal.dom.api.DOMDataTreeListener} instead.
- */
-@Deprecated
-public interface DOMDataTreeListener extends EventListener {
- /**
- * Invoked whenever one or more registered subtrees change. The logical changes are reported,
- * as well as the roll up of new state for all subscribed subtrees.
- *
- * @param changes The set of changes being reported. Each subscribed subtree may be present
- * at most once.
- * @param subtrees Per-subtree state as visible after the reported changes have been applied.
- * This includes all the subtrees this listener is subscribed to, even those
- * which have not changed.
- */
- void onDataTreeChanged(@Nonnull Collection<DataTreeCandidate> changes,
- @Nonnull Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>> subtrees);
-
- /**
- * Invoked when a subtree listening failure occurs. This can be triggered, for example, when
- * a connection to external subtree source is broken. The listener will not receive any other
- * callbacks, but its registration still needs to be closed to prevent resource leak.
- *
- * @param causes Collection of failure causes, may not be null or empty.
- */
- void onDataTreeFailed(@Nonnull Collection<DOMDataTreeListeningException> causes);
-}
+++ /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.controller.md.sal.dom.api;
-
-/**
- * Base exception for various causes why and {@link DOMDataTreeListener}
- * may be terminated by the {@link DOMDataTreeService} implementation.
- *
- * @deprecated Use {@link org.opendaylight.mdsal.dom.api.DOMDataTreeListeningException} instead.
- */
-@Deprecated
-public class DOMDataTreeListeningException extends Exception {
- private static final long serialVersionUID = 1L;
-
- public DOMDataTreeListeningException(final String message) {
- super(message);
- }
-
- public DOMDataTreeListeningException(final String message, final Throwable cause) {
- super(message, cause);
- }
-}
+++ /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.controller.md.sal.dom.api;
-
-import javax.annotation.Nonnull;
-
-/**
- * Exception thrown when a loop is detected in the way {@link DOMDataTreeListener}
- * and {@link DOMDataTreeProducer} instances would be connected.
- *
- * @deprecated Use {@link org.opendaylight.mdsal.dom.api.DOMDataTreeLoopException} instead.
- */
-@Deprecated
-public class DOMDataTreeLoopException extends Exception {
- private static final long serialVersionUID = 1L;
-
- public DOMDataTreeLoopException(final @Nonnull String message) {
- super(message);
- }
-
- public DOMDataTreeLoopException(final @Nonnull String message, final @Nonnull Throwable cause) {
- super(message, cause);
- }
-}
+++ /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.controller.md.sal.dom.api;
-
-import java.util.Collection;
-import javax.annotation.Nonnull;
-
-/**
- * A data producer context. It allows transactions to be submitted to the subtrees
- * specified at instantiation time. At any given time there may be a single transaction
- * open. It needs to be either submitted or cancelled before another one can be open.
- * Once a transaction is submitted, it will proceed to be committed asynchronously.
- *
- * <p>
- * Each instance has an upper bound on the number of transactions which can be in-flight,
- * once that capacity is exceeded, an attempt to create a new transaction will block
- * until some transactions complete.
- *
- * <p>
- * Each {@link DOMDataTreeProducer} can be in two logical states, bound and unbound,
- * which define the lifecycle rules for when is it legal to create and submit transactions
- * in relationship with {@link DOMDataTreeListener} callbacks.
- *
- * <p>
- * When a producer is first created, it is unbound. In this state the producer can be
- * accessed by any application thread to allocate or submit transactions, as long as
- * the 'single open transaction' rule is maintained. The producer and any transaction
- * object MUST NOT be accessed, directly or indirectly, from a {@link DOMDataTreeListener}
- * callback.
- *
- * <p>
- * When a producer is referenced in a call to {@link DOMDataTreeService#registerListener(DOMDataTreeListener,
- * java.util.Collection, boolean, java.util.Collection)},
- * an attempt will be made to bind the producer to the specified {@link DOMDataTreeListener}.
- * Such an attempt will fail the producer is already bound, or it has an open transaction.
- * Once bound, the producer can only be accessed from within the {@link DOMDataTreeListener}
- * callback on that particular instance. Any transaction which is not submitted by the
- * time the callback returns will be implicitly cancelled. A producer becomes unbound
- * when the listener it is bound to becomes unregistered.
- *
- * @deprecated Use {@link org.opendaylight.mdsal.dom.api.DOMDataTreeProducer} instead.
- */
-@Deprecated
-public interface DOMDataTreeProducer extends DOMDataTreeProducerFactory, AutoCloseable {
- /**
- * Allocate a new open transaction on this producer. Any and all transactions
- * previously allocated must have been either submitted or cancelled by the
- * time this method is invoked.
- *
- * @param isolated Indicates whether this transaction should be a barrier. A barrier
- * transaction is processed separately from any preceding transactions.
- * Non-barrier transactions may be merged and processed in a batch,
- * such that any observers see the modifications contained in them as
- * if the modifications were made in a single transaction.
- * @return A new {@link DOMDataWriteTransaction}
- * @throws IllegalStateException if a previous transaction was not closed.
- * @throws IllegalThreadStateException if the calling thread context does not
- * match the lifecycle rules enforced by the producer state (e.g. bound or unbound).
- * This exception is thrown on a best effort basis and programs should not rely
- * on it for correct operation.
- */
- @Nonnull DOMDataWriteTransaction createTransaction(boolean isolated);
-
- /**
- * {@inheritDoc}
- *
- * <p>
- * When invoked on a {@link DOMDataTreeProducer}, this method has additional restrictions.
- * There may not be an open transaction from this producer. The method needs to be
- * invoked in appropriate context, e.g. bound or unbound.
- *
- * <p>
- * Specified subtrees must be accessible by this producer. Accessible means they are a subset
- * of the subtrees specified when the producer is instantiated. The set is further reduced as
- * child producers are instantiated -- if you create a producer for /a and then a child for
- * /a/b, /a/b is not accessible from the first producer.
- *
- * <p>
- * Once this method returns successfully, this (parent) producer loses the ability to
- * access the specified paths until the resulting (child) producer is shut down.
- *
- * @throws IllegalStateException if there is an open transaction
- * @throws IllegalArgumentException if subtrees contains a subtree which is not
- * accessible by this producer
- * @throws IllegalThreadStateException if the calling thread context does not
- * match the lifecycle rules enforced by the producer state (e.g. bound or unbound).
- * This exception is thrown on a best effort basis and programs should not rely
- * on it for correct operation.
- */
- @Override
- @Nonnull DOMDataTreeProducer createProducer(@Nonnull Collection<DOMDataTreeIdentifier> subtrees);
-
- /**
- * {@inheritDoc}
- *
- * @throws DOMDataTreeProducerBusyException when there is an open transaction.
- */
- @Override
- void close() throws DOMDataTreeProducerException;
-}
+++ /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.controller.md.sal.dom.api;
-
-/**
- * Exception indicating that the {@link DOMDataTreeProducer} has an open user
- * transaction and cannot be closed.
- *
- * @deprecated Use {@link org.opendaylight.mdsal.dom.api.DOMDataTreeProducerBusyException} instead.
- */
-@Deprecated
-public class DOMDataTreeProducerBusyException extends DOMDataTreeProducerException {
- private static final long serialVersionUID = 1L;
-
- public DOMDataTreeProducerBusyException(final String message) {
- super(message);
- }
-
- public DOMDataTreeProducerBusyException(final String message, final Throwable cause) {
- super(message, cause);
- }
-}
+++ /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.controller.md.sal.dom.api;
-
-/**
- * Base exception for all exceptions related to {@link DOMDataTreeProducer}s.
- *
- * @deprecated Use {@link org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException} instead.
- */
-@Deprecated
-public class DOMDataTreeProducerException extends Exception {
- private static final long serialVersionUID = 1L;
-
- public DOMDataTreeProducerException(final String message) {
- super(message);
- }
-
- public DOMDataTreeProducerException(final String message, final Throwable cause) {
- super(message, cause);
- }
-}
+++ /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.controller.md.sal.dom.api;
-
-import java.util.Collection;
-import javax.annotation.Nonnull;
-
-/**
- * Base source of {@link DOMDataTreeProducer}s. This interface is usually not used directly,
- * but rather through one of its sub-interfaces.
- *
- * @deprecated Use {@link org.opendaylight.mdsal.dom.api.DOMDataTreeProducerFactory} instead.
- */
-@Deprecated
-public interface DOMDataTreeProducerFactory {
- /**
- * Create a producer, which is able to access to a set of trees.
- *
- * @param subtrees The collection of subtrees the resulting producer should have access to.
- * @return A {@link DOMDataTreeProducer} instance.
- * @throws IllegalArgumentException if subtrees is empty.
- */
- @Nonnull DOMDataTreeProducer createProducer(@Nonnull Collection<DOMDataTreeIdentifier> subtrees);
-}
+++ /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.controller.md.sal.dom.api;
-
-import java.util.Collection;
-import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-
-/**
- * A {@link DOMService} providing access to the conceptual data tree. Interactions
- * with the data tree are split into data producers and consumers (listeners). Each
- * of them operate on a set of subtrees, which need to be declared at instantiation time.
- *
- * <p>
- * Returned instances are not thread-safe and expected to be used by a single thread
- * at a time. Furthermore, producers may not be accessed from consumer callbacks
- * unless they were specified when the listener is registered.
- *
- * <p>
- * The service maintains a loop-free topology of producers and consumers. What this means
- * is that a consumer is not allowed to access a producer, which affects any of the
- * subtrees it is subscribed to. This restriction is in place to ensure the system does
- * not go into a feedback loop, where it is impossible to block either a producer or
- * a consumer without accumulating excess work in the backlog stemming from its previous
- * activity.
- *
- * @deprecated Use {@link org.opendaylight.mdsal.dom.api.DOMDataTreeService} instead.
- */
-@Deprecated
-public interface DOMDataTreeService extends DOMDataTreeProducerFactory, DOMService {
- /**
- * Register a {@link DOMDataTreeListener} instance. Once registered, the listener
- * will start receiving changes on the selected subtrees. If the listener cannot
- * keep up with the rate of changes, and allowRxMerges is set to true, this service
- * is free to merge the changes, so that a smaller number of them will be reported,
- * possibly hiding some data transitions (like flaps).
- *
- * <p>
- * If the listener wants to write into any producer, that producer has to be mentioned
- * in the call to this method. Those producers will be bound exclusively to the
- * registration, so that accessing them outside of this listener's callback will trigger
- * an error. Any producers mentioned must be idle, e.g. they may not have an open
- * transaction at the time this method is invoked.
- *
- * <p>
- * Each listener instance can be registered at most once. Implementations of this
- * interface have to guarantee that the listener's methods will not be invoked
- * concurrently from multiple threads.
- *
- * @param listener {@link DOMDataTreeListener} that is being registered
- * @param subtrees Conceptual subtree identifier of subtrees which should be monitored
- * for changes. May not be null or empty.
- * @param allowRxMerges True if the backend may perform ingress state compression.
- * @param producers {@link DOMDataTreeProducer} instances to bind to the listener.
- * @return A listener registration. Once closed, the listener will no longer be
- * invoked and the producers will be unbound.
- * @throws IllegalArgumentException if subtrees is empty or the listener is already bound
- * @throws DOMDataTreeLoopException if the registration of the listener to the specified
- * subtrees with specified producers would form a
- * feedback loop
- */
- @Nonnull <T extends DOMDataTreeListener> ListenerRegistration<T> registerListener(@Nonnull T listener,
- @Nonnull Collection<DOMDataTreeIdentifier> subtrees, boolean allowRxMerges,
- @Nonnull Collection<DOMDataTreeProducer> producers) throws DOMDataTreeLoopException;
-}
+++ /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.controller.md.sal.dom.api;
-
-import java.util.EventListener;
-import javax.annotation.Nonnull;
-
-/**
- * A single shard of the conceptual data tree. This interface defines the basic notifications
- * a shard can receive. Each shard implementation is expected to also implement some of the
- * datastore-level APIs. Which interfaces are required depends on the {@link DOMDataTreeShardingService}
- * implementation.
- *
- * @deprecated Use {@link org.opendaylight.mdsal.dom.api.DOMDataTreeShard} instead.
- */
-@Deprecated
-public interface DOMDataTreeShard extends EventListener {
- /**
- * Invoked whenever a child is getting attached as a more specific prefix under this shard.
- *
- * @param prefix Child's prefix
- * @param child Child shard
- */
- void onChildAttached(@Nonnull DOMDataTreeIdentifier prefix, @Nonnull DOMDataTreeShard child);
-
- /**
- * Invoked whenever a child is getting detached as a more specific prefix under this shard.
- *
- * @param prefix Child's prefix
- * @param child Child shard
- */
- void onChildDetached(@Nonnull DOMDataTreeIdentifier prefix, @Nonnull DOMDataTreeShard child);
-}
+++ /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.controller.md.sal.dom.api;
-
-import javax.annotation.Nonnull;
-
-/**
- * Exception thrown when an attempt to attach a conflicting shard to the global table.
- *
- * @deprecated Use {@link org.opendaylight.mdsal.dom.api.DOMDataTreeShardingConflictException} instead.
- */
-@Deprecated
-public class DOMDataTreeShardingConflictException extends Exception {
- private static final long serialVersionUID = 1L;
-
- public DOMDataTreeShardingConflictException(final @Nonnull String message) {
- super(message);
- }
-
- public DOMDataTreeShardingConflictException(final @Nonnull String message, final @Nonnull Throwable cause) {
- super(message, cause);
- }
-}
+++ /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.controller.md.sal.dom.api;
-
-import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-
-/**
- * A {@link DOMService} providing access to details on how the conceptual data tree
- * is distributed among providers (also known as shards). Each shard is tied to a
- * single {@link DOMDataTreeIdentifier}. Based on those data tree identifiers, the
- * shards are organized in a tree, where there is a logical parent/child relationship.
- *
- * <p>
- * It is not allowed to attach two shards to the same data tree identifier, which means
- * the mapping of each piece of information has an unambiguous home. When accessing
- * the information, the shard with the longest matching data tree identifier is used,
- * which is why this interface treats it is a prefix.
- *
- * <p>
- * Whenever a parent/child relationship is changed, the parent is notified, so it can
- * understand that a logical child has been attached.
- *
- * @deprecated Use {@link org.opendaylight.mdsal.dom.api.DOMDataTreeShardingService} instead.
- */
-@Deprecated
-public interface DOMDataTreeShardingService extends DOMService {
- /**
- * Register a shard as responsible for a particular subtree prefix.
- *
- * @param prefix Data tree identifier, may not be null.
- * @param shard Responsible shard instance
- * @return A registration. To remove the shard's binding, close the registration.
- * @throws DOMDataTreeShardingConflictException if the prefix is already bound
- */
- @Nonnull <T extends DOMDataTreeShard> ListenerRegistration<T> registerDataTreeShard(
- @Nonnull DOMDataTreeIdentifier prefix, @Nonnull T shard) throws DOMDataTreeShardingConflictException;
-}
+++ /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.controller.md.sal.dom.api;
-
-import static org.junit.Assert.assertNotNull;
-
-import com.google.common.util.concurrent.CheckedFuture;
-import java.net.URI;
-import java.util.Collections;
-import javax.annotation.Nonnull;
-import org.junit.Test;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-
-/**
- * Abstract test suite demonstrating various access patterns on how a {@link DOMDataTreeService}
- * can be used.
- */
-public abstract class AbstractDOMDataTreeServiceTestSuite {
- protected static final QNameModule TEST_MODULE = QNameModule.create(URI.create(
- "urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:store"));
-
- protected static final YangInstanceIdentifier UNORDERED_CONTAINER_IID = YangInstanceIdentifier.create(
- new NodeIdentifier(QName.create(TEST_MODULE, "lists")),
- new NodeIdentifier(QName.create(TEST_MODULE, "unordered-container")));
- protected static final DOMDataTreeIdentifier UNORDERED_CONTAINER_TREE =
- new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, UNORDERED_CONTAINER_IID);
-
- /**
- * Return a reference to the service used in this test. The instance
- * needs to be reused within the same test and must be isolated between
- * tests.
- *
- * @return {@link DOMDataTreeService} instance.
- */
- protected abstract @Nonnull DOMDataTreeService service();
-
- /**
- * A simple unbound producer. It write some basic things into the data store based on the
- * test model.
- */
- @Test
- public final void testBasicProducer() throws DOMDataTreeProducerException, TransactionCommitFailedException {
- // Create a producer. It is an AutoCloseable resource, hence the try-with pattern
- try (DOMDataTreeProducer prod = service().createProducer(Collections.singleton(UNORDERED_CONTAINER_TREE))) {
- assertNotNull(prod);
-
- final DOMDataWriteTransaction tx = prod.createTransaction(true);
- assertNotNull(tx);
-
- tx.put(LogicalDatastoreType.OPERATIONAL, UNORDERED_CONTAINER_IID,
- ImmutableContainerNodeBuilder.create().build());
-
- final CheckedFuture<Void, TransactionCommitFailedException> f = tx.submit();
- assertNotNull(f);
-
- f.checkedGet();
- }
- }
-
- // TODO: simple listener
-}
+++ /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.controller.md.sal.dom.broker.impl;
-
-import com.google.common.base.Preconditions;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeShard;
-import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
-
-/**
- * ShardRegistration.
- *
- * @deprecated To be removed with {@link ShardedDOMDataTree}.
- */
-@Deprecated
-final class ShardRegistration<T extends DOMDataTreeShard> extends AbstractListenerRegistration<T> {
- private final DOMDataTreeIdentifier prefix;
- private final ShardedDOMDataTree tree;
-
- protected ShardRegistration(final ShardedDOMDataTree tree, final DOMDataTreeIdentifier prefix, final T shard) {
- super(shard);
- this.tree = Preconditions.checkNotNull(tree);
- this.prefix = Preconditions.checkNotNull(prefix);
- }
-
- DOMDataTreeIdentifier getPrefix() {
- return prefix;
- }
-
- @Override
- protected void removeRegistration() {
- tree.removeShard(this);
- }
-}
+++ /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.controller.md.sal.dom.broker.impl;
-
-import com.google.common.base.Preconditions;
-import java.util.Collection;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.TreeMap;
-import javax.annotation.concurrent.GuardedBy;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeListener;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeProducer;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeService;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeShard;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeShardingConflictException;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeShardingService;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Shared DOM data tree.
- *
- * @deprecated Use {@link org.opendaylight.mdsal.dom.broker.ShardedDOMDataTree} instead.
- */
-@Deprecated
-public final class ShardedDOMDataTree implements DOMDataTreeService, DOMDataTreeShardingService {
- private static final Logger LOG = LoggerFactory.getLogger(ShardedDOMDataTree.class);
- private final Map<LogicalDatastoreType, ShardingTableEntry> shardingTables = new EnumMap<>(
- LogicalDatastoreType.class);
- @GuardedBy("this")
- private final Map<DOMDataTreeIdentifier, DOMDataTreeProducer> idToProducer = new TreeMap<>();
-
- @GuardedBy("this")
- private ShardingTableEntry lookupShard(final DOMDataTreeIdentifier prefix) {
- final ShardingTableEntry t = shardingTables.get(prefix.getDatastoreType());
- if (t == null) {
- return null;
- }
-
- return t.lookup(prefix.getRootIdentifier());
- }
-
- @GuardedBy("this")
- private void storeShard(final DOMDataTreeIdentifier prefix, final ShardRegistration<?> reg) {
- ShardingTableEntry shardingTableEntry = shardingTables
- .computeIfAbsent(prefix.getDatastoreType(), k -> new ShardingTableEntry());
-
- shardingTableEntry.store(prefix.getRootIdentifier(), reg);
- }
-
- void removeShard(final ShardRegistration<?> reg) {
- final DOMDataTreeIdentifier prefix = reg.getPrefix();
- final ShardRegistration<?> parentReg;
-
- synchronized (this) {
- final ShardingTableEntry t = shardingTables.get(prefix.getDatastoreType());
- if (t == null) {
- LOG.warn("Shard registration {} points to non-existent table", reg);
- return;
- }
-
- t.remove(prefix.getRootIdentifier());
- parentReg = lookupShard(prefix).getRegistration();
-
- /*
- * FIXME: adjust all producers. This is tricky, as we need different locking strategy,
- * simply because we risk AB/BA deadlock with a producer being split off from
- * a producer.
- *
- */
- }
-
- if (parentReg != null) {
- parentReg.getInstance().onChildDetached(prefix, reg.getInstance());
- }
- }
-
- @Override
- public <T extends DOMDataTreeShard> ListenerRegistration<T> registerDataTreeShard(
- final DOMDataTreeIdentifier prefix, final T shard) throws DOMDataTreeShardingConflictException {
- final ShardRegistration<T> reg;
- final ShardRegistration<?> parentReg;
-
- synchronized (this) {
- /*
- * Lookup the parent shard (e.g. the one which currently matches the prefix),
- * and if it exists, check if its registration prefix does not collide with
- * this registration.
- */
- final ShardingTableEntry parent = lookupShard(prefix);
- parentReg = parent.getRegistration();
- if (parentReg != null && prefix.equals(parentReg.getPrefix())) {
- throw new DOMDataTreeShardingConflictException(
- String.format("Prefix %s is already occupied by shard %s", prefix, parentReg.getInstance()));
- }
-
- // FIXME: wrap the shard in a proper adaptor based on implemented interface
-
- reg = new ShardRegistration<>(this, prefix, shard);
-
- storeShard(prefix, reg);
-
- // FIXME: update any producers/registrations
- }
-
- // Notify the parent shard
- if (parentReg != null) {
- parentReg.getInstance().onChildAttached(prefix, shard);
- }
-
- return reg;
- }
-
- @GuardedBy("this")
- private DOMDataTreeProducer findProducer(final DOMDataTreeIdentifier subtree) {
- for (final Entry<DOMDataTreeIdentifier, DOMDataTreeProducer> e : idToProducer.entrySet()) {
- if (e.getKey().contains(subtree)) {
- return e.getValue();
- }
- }
-
- return null;
- }
-
- synchronized void destroyProducer(final ShardedDOMDataTreeProducer producer) {
- for (final DOMDataTreeIdentifier s : producer.getSubtrees()) {
- final DOMDataTreeProducer r = idToProducer.remove(s);
- if (!producer.equals(r)) {
- LOG.error("Removed producer {} on subtree {} while removing {}", r, s, producer);
- }
- }
- }
-
- @GuardedBy("this")
- private DOMDataTreeProducer createProducer(final Map<DOMDataTreeIdentifier, DOMDataTreeShard> shardMap) {
- // Record the producer's attachment points
- final DOMDataTreeProducer ret = ShardedDOMDataTreeProducer.create(this, shardMap);
- for (DOMDataTreeIdentifier s : shardMap.keySet()) {
- idToProducer.put(s, ret);
- }
-
- return ret;
- }
-
- @Override
- public synchronized DOMDataTreeProducer createProducer(final Collection<DOMDataTreeIdentifier> subtrees) {
- Preconditions.checkArgument(!subtrees.isEmpty(), "Subtrees may not be empty");
-
- final Map<DOMDataTreeIdentifier, DOMDataTreeShard> shardMap = new HashMap<>();
- for (final DOMDataTreeIdentifier s : subtrees) {
- // Attempting to create a disconnected producer -- all subtrees have to be unclaimed
- final DOMDataTreeProducer producer = findProducer(s);
- Preconditions.checkArgument(producer == null, "Subtree %s is attached to producer %s", s, producer);
-
- shardMap.put(s, lookupShard(s).getRegistration().getInstance());
- }
-
- return createProducer(shardMap);
- }
-
- synchronized DOMDataTreeProducer createProducer(final ShardedDOMDataTreeProducer parent,
- final Collection<DOMDataTreeIdentifier> subtrees) {
- Preconditions.checkNotNull(parent);
-
- final Map<DOMDataTreeIdentifier, DOMDataTreeShard> shardMap = new HashMap<>();
- for (final DOMDataTreeIdentifier s : subtrees) {
- shardMap.put(s, lookupShard(s).getRegistration().getInstance());
- }
-
- return createProducer(shardMap);
- }
-
- @Override
- public synchronized <T extends DOMDataTreeListener> ListenerRegistration<T>
- registerListener(final T listener,
- final Collection<DOMDataTreeIdentifier> subtrees,
- final boolean allowRxMerges,
- final Collection<DOMDataTreeProducer> producers) {
- // FIXME Implement this.
- throw new UnsupportedOperationException("Not implemented yet.");
- }
-}
+++ /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.controller.md.sal.dom.broker.impl;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.BiMap;
-import com.google.common.collect.ImmutableBiMap;
-import com.google.common.collect.ImmutableBiMap.Builder;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Queue;
-import java.util.Set;
-import javax.annotation.concurrent.GuardedBy;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeProducer;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeProducerBusyException;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeProducerException;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeShard;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.controller.sal.core.spi.data.DOMStore;
-import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain;
-import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Sharded DOM Data Tree Producer.
- *
- * @deprecated To be removed with {@link ShardedDOMDataTree}.
- */
-@Deprecated
-@SuppressWarnings("checkstyle:IllegalCatch")
-final class ShardedDOMDataTreeProducer implements DOMDataTreeProducer {
- private static final Logger LOG = LoggerFactory.getLogger(ShardedDOMDataTreeProducer.class);
- private final BiMap<DOMDataTreeShard, DOMStoreTransactionChain> shardToChain;
- private final Map<DOMDataTreeIdentifier, DOMDataTreeShard> idToShard;
- private final ShardedDOMDataTree dataTree;
-
- @GuardedBy("this")
- private Map<DOMDataTreeIdentifier, DOMDataTreeProducer> children = Collections.emptyMap();
- @GuardedBy("this")
- private DOMDataWriteTransaction openTx;
- @GuardedBy("this")
- private boolean closed;
-
- ShardedDOMDataTreeProducer(final ShardedDOMDataTree dataTree,
- final Map<DOMDataTreeIdentifier, DOMDataTreeShard> shardMap,
- final Set<DOMDataTreeShard> shards) {
- this.dataTree = Preconditions.checkNotNull(dataTree);
-
- // Create shard -> chain map
- final Builder<DOMDataTreeShard, DOMStoreTransactionChain> cb = ImmutableBiMap.builder();
- final Queue<Exception> es = new LinkedList<>();
-
- for (final DOMDataTreeShard s : shards) {
- if (s instanceof DOMStore) {
- try {
- final DOMStoreTransactionChain c = ((DOMStore) s).createTransactionChain();
- LOG.trace("Using DOMStore chain {} to access shard {}", c, s);
- cb.put(s, c);
- } catch (final Exception e) {
- LOG.error("Failed to instantiate chain for shard {}", s, e);
- es.add(e);
- }
- } else {
- LOG.error("Unhandled shard instance type {}", s.getClass());
- }
- }
- this.shardToChain = cb.build();
-
- // An error was encountered, close chains and report the error
- if (shardToChain.size() != shards.size()) {
- for (final DOMStoreTransactionChain c : shardToChain.values()) {
- try {
- c.close();
- } catch (final Exception e) {
- LOG.warn("Exception raised while closing chain {}", c, e);
- }
- }
-
- final IllegalStateException e = new IllegalStateException("Failed to completely allocate contexts",
- es.poll());
- while (!es.isEmpty()) {
- e.addSuppressed(es.poll());
- }
-
- throw e;
- }
-
- idToShard = ImmutableMap.copyOf(shardMap);
- }
-
- @Override
- public synchronized DOMDataWriteTransaction createTransaction(final boolean isolated) {
- Preconditions.checkState(!closed, "Producer is already closed");
- Preconditions.checkState(openTx == null, "Transaction %s is still open", openTx);
-
- // Allocate backing transactions
- final Map<DOMDataTreeShard, DOMStoreWriteTransaction> shardToTx = new HashMap<>();
- for (final Entry<DOMDataTreeShard, DOMStoreTransactionChain> e : shardToChain.entrySet()) {
- shardToTx.put(e.getKey(), e.getValue().newWriteOnlyTransaction());
- }
-
- // Create the ID->transaction map
- final ImmutableMap.Builder<DOMDataTreeIdentifier, DOMStoreWriteTransaction> b = ImmutableMap.builder();
- for (final Entry<DOMDataTreeIdentifier, DOMDataTreeShard> e : idToShard.entrySet()) {
- b.put(e.getKey(), shardToTx.get(e.getValue()));
- }
-
- final ShardedDOMDataWriteTransaction ret = new ShardedDOMDataWriteTransaction(this, b.build());
- openTx = ret;
- return ret;
- }
-
- @GuardedBy("this")
- private boolean haveSubtree(final DOMDataTreeIdentifier subtree) {
- for (final DOMDataTreeIdentifier i : idToShard.keySet()) {
- if (i.contains(subtree)) {
- return true;
- }
- }
-
- return false;
- }
-
- @GuardedBy("this")
- private DOMDataTreeProducer lookupChild(final DOMDataTreeIdentifier identifier) {
- for (final Entry<DOMDataTreeIdentifier, DOMDataTreeProducer> e : children.entrySet()) {
- if (e.getKey().contains(identifier)) {
- return e.getValue();
- }
- }
-
- return null;
- }
-
- @Override
- public synchronized DOMDataTreeProducer createProducer(final Collection<DOMDataTreeIdentifier> subtrees) {
- Preconditions.checkState(!closed, "Producer is already closed");
- Preconditions.checkState(openTx == null, "Transaction %s is still open", openTx);
-
- for (final DOMDataTreeIdentifier s : subtrees) {
- // Check if the subtree was visible at any time
- if (!haveSubtree(s)) {
- throw new IllegalArgumentException(
- String.format("Subtree %s was never available in producer %s", s, this));
- }
-
- // Check if the subtree has not been delegated to a child
- final DOMDataTreeProducer child = lookupChild(s);
- Preconditions.checkArgument(child == null, "Subtree %s is delegated to child producer %s", s, child);
-
- // Check if part of the requested subtree is not delegated to a child.
- for (final DOMDataTreeIdentifier c : children.keySet()) {
- if (s.contains(c)) {
- throw new IllegalArgumentException(
- String.format("Subtree %s cannot be delegated as it is superset of already-delegated %s", s,
- c));
- }
- }
- }
-
- final DOMDataTreeProducer ret = dataTree.createProducer(this, subtrees);
- final ImmutableMap.Builder<DOMDataTreeIdentifier, DOMDataTreeProducer> cb = ImmutableMap.builder();
- cb.putAll(children);
- for (final DOMDataTreeIdentifier s : subtrees) {
- cb.put(s, ret);
- }
-
- children = cb.build();
- return ret;
- }
-
- @Override
- public synchronized void close() throws DOMDataTreeProducerException {
- if (!closed) {
- if (openTx != null) {
- throw new DOMDataTreeProducerBusyException(String.format("Transaction %s is still open", openTx));
- }
-
- closed = true;
- dataTree.destroyProducer(this);
- }
- }
-
- static DOMDataTreeProducer create(final ShardedDOMDataTree dataTree,
- final Map<DOMDataTreeIdentifier, DOMDataTreeShard> shardMap) {
- /*
- * FIXME: we do not allow multiple multiple shards in a producer because we do not implement the
- * synchronization primitives yet
- */
- final Set<DOMDataTreeShard> shards = ImmutableSet.copyOf(shardMap.values());
- if (shards.size() > 1) {
- throw new UnsupportedOperationException("Cross-shard producers are not supported yet");
- }
-
- return new ShardedDOMDataTreeProducer(dataTree, shardMap, shards);
- }
-
- Set<DOMDataTreeIdentifier> getSubtrees() {
- return idToShard.keySet();
- }
-
- synchronized void cancelTransaction(final ShardedDOMDataWriteTransaction transaction) {
- if (!openTx.equals(transaction)) {
- LOG.warn("Transaction {} is not open in producer {}", transaction, this);
- return;
- }
-
- LOG.debug("Transaction {} cancelled", transaction);
- openTx = null;
- }
-}
+++ /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.controller.md.sal.dom.broker.impl;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicLong;
-import javax.annotation.concurrent.GuardedBy;
-import javax.annotation.concurrent.NotThreadSafe;
-import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.controller.md.sal.common.impl.service.AbstractDataTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
-import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * ShardedDOMDataWriteTransaction.
- *
- * @deprecated To be removed with {@link ShardedDOMDataTree}.
- */
-@Deprecated
-@NotThreadSafe
-final class ShardedDOMDataWriteTransaction implements DOMDataWriteTransaction {
- private static final Logger LOG = LoggerFactory.getLogger(ShardedDOMDataWriteTransaction.class);
- private static final AtomicLong COUNTER = new AtomicLong();
- private final Map<DOMDataTreeIdentifier, DOMStoreWriteTransaction> idToTransaction;
- private final ShardedDOMDataTreeProducer producer;
- private final String identifier;
- @GuardedBy("this")
- private boolean closed = false;
-
- ShardedDOMDataWriteTransaction(final ShardedDOMDataTreeProducer producer,
- final Map<DOMDataTreeIdentifier, DOMStoreWriteTransaction> idToTransaction) {
- this.producer = Preconditions.checkNotNull(producer);
- this.idToTransaction = Preconditions.checkNotNull(idToTransaction);
- this.identifier = "SHARDED-DOM-" + COUNTER.getAndIncrement();
- }
-
- // FIXME: use atomic operations
- @GuardedBy("this")
- private DOMStoreWriteTransaction lookup(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
- final DOMDataTreeIdentifier id = new DOMDataTreeIdentifier(store, path);
-
- for (Entry<DOMDataTreeIdentifier, DOMStoreWriteTransaction> e : idToTransaction.entrySet()) {
- if (e.getKey().contains(id)) {
- return e.getValue();
- }
- }
-
- throw new IllegalArgumentException(String.format("Path %s is not acessible from transaction %s", id, this));
- }
-
- @Override
- public String getIdentifier() {
- return identifier;
- }
-
- @Override
- public synchronized boolean cancel() {
- if (closed) {
- return false;
- }
-
- LOG.debug("Cancelling transaction {}", identifier);
- for (DOMStoreWriteTransaction tx : ImmutableSet.copyOf(idToTransaction.values())) {
- tx.close();
- }
-
- closed = true;
- producer.cancelTransaction(this);
- return true;
- }
-
- @Override
- public synchronized CheckedFuture<Void, TransactionCommitFailedException> submit() {
- Preconditions.checkState(!closed, "Transaction %s is already closed", identifier);
-
- final Set<DOMStoreWriteTransaction> txns = ImmutableSet.copyOf(idToTransaction.values());
- final List<DOMStoreThreePhaseCommitCohort> cohorts = new ArrayList<>(txns.size());
- for (DOMStoreWriteTransaction tx : txns) {
- cohorts.add(tx.ready());
- }
-
- try {
- return Futures.immediateCheckedFuture(new CommitCoordinationTask(this, cohorts, null).call());
- } catch (TransactionCommitFailedException e) {
- return Futures.immediateFailedCheckedFuture(e);
- }
- }
-
- @Override
- @Deprecated
- public ListenableFuture<RpcResult<TransactionStatus>> commit() {
- return AbstractDataTransaction.convertToLegacyCommitFuture(submit());
- }
-
- @Override
- public synchronized void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
- lookup(store, path).delete(path);
- }
-
- @Override
- public synchronized void put(final LogicalDatastoreType store, final YangInstanceIdentifier path,
- final NormalizedNode<?, ?> data) {
- lookup(store, path).write(path, data);
- }
-
- @Override
- public synchronized void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
- final NormalizedNode<?, ?> data) {
- lookup(store, path).merge(path, data);
- }
-}
+++ /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.controller.md.sal.dom.broker.impl;
-
-import com.google.common.base.Preconditions;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Map;
-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;
-
-/**
- * Sharding Table Entry.
- *
- * @deprecated To be removed with {@link ShardedDOMDataTree}.
- */
-@Deprecated
-final class ShardingTableEntry implements Identifiable<PathArgument> {
- private static final Logger LOG = LoggerFactory.getLogger(ShardingTableEntry.class);
- private final Map<PathArgument, ShardingTableEntry> children = Collections.emptyMap();
- private final PathArgument identifier;
- private ShardRegistration<?> registration;
-
- ShardingTableEntry() {
- identifier = null;
- }
-
- ShardingTableEntry(final PathArgument identifier) {
- this.identifier = Preconditions.checkNotNull(identifier);
- }
-
- @Override
- public PathArgument getIdentifier() {
- return identifier;
- }
-
- public ShardRegistration<?> getRegistration() {
- return registration;
- }
-
- ShardingTableEntry lookup(final YangInstanceIdentifier id) {
- final Iterator<PathArgument> it = id.getPathArguments().iterator();
- ShardingTableEntry entry = this;
-
- while (it.hasNext()) {
- final PathArgument a = it.next();
- final ShardingTableEntry child = entry.children.get(a);
- if (child == null) {
- LOG.debug("Lookup of {} stopped at {}", id, a);
- break;
- }
-
- entry = child;
- }
-
- return entry;
- }
-
- void store(final YangInstanceIdentifier id, final ShardRegistration<?> reg) {
- final Iterator<PathArgument> it = id.getPathArguments().iterator();
- ShardingTableEntry entry = this;
-
- while (it.hasNext()) {
- final PathArgument a = it.next();
- ShardingTableEntry child = entry.children.computeIfAbsent(a, ShardingTableEntry::new);
- }
-
- Preconditions.checkState(entry.registration == null);
- entry.registration = reg;
- }
-
- private boolean remove(final Iterator<PathArgument> it) {
- if (it.hasNext()) {
- final PathArgument arg = it.next();
- final ShardingTableEntry child = children.get(arg);
- if (child != null) {
- if (child.remove(it)) {
- children.remove(arg);
- }
- } else {
- LOG.warn("Cannot remove non-existent child {}", arg);
- }
- }
-
- return registration == null && children.isEmpty();
- }
-
- void remove(final YangInstanceIdentifier id) {
- this.remove(id.getPathArguments().iterator());
- }
-}