2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.md.sal.dom.broker.impl;
10 import com.google.common.base.Preconditions;
11 import java.util.Collections;
12 import java.util.Iterator;
14 import org.opendaylight.yangtools.concepts.Identifiable;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * @deprecated To be removed with {@link ShardedDOMDataTree}.
24 final class ShardingTableEntry implements Identifiable<PathArgument> {
25 private static final Logger LOG = LoggerFactory.getLogger(ShardingTableEntry.class);
26 private final Map<PathArgument, ShardingTableEntry> children = Collections.emptyMap();
27 private final PathArgument identifier;
28 private ShardRegistration<?> registration;
30 ShardingTableEntry() {
34 ShardingTableEntry(final PathArgument identifier) {
35 this.identifier = Preconditions.checkNotNull(identifier);
39 public PathArgument getIdentifier() {
43 public ShardRegistration<?> getRegistration() {
47 ShardingTableEntry lookup(final YangInstanceIdentifier id) {
48 final Iterator<PathArgument> it = id.getPathArguments().iterator();
49 ShardingTableEntry entry = this;
51 while (it.hasNext()) {
52 final PathArgument a = it.next();
53 final ShardingTableEntry child = entry.children.get(a);
55 LOG.debug("Lookup of {} stopped at {}", id, a);
65 void store(final YangInstanceIdentifier id, final ShardRegistration<?> reg) {
66 final Iterator<PathArgument> it = id.getPathArguments().iterator();
67 ShardingTableEntry entry = this;
69 while (it.hasNext()) {
70 final PathArgument a = it.next();
71 ShardingTableEntry child = entry.children.computeIfAbsent(a, ShardingTableEntry::new);
74 Preconditions.checkState(entry.registration == null);
75 entry.registration = reg;
78 private boolean remove(final Iterator<PathArgument> it) {
80 final PathArgument arg = it.next();
81 final ShardingTableEntry child = children.get(arg);
83 if (child.remove(it)) {
87 LOG.warn("Cannot remove non-existent child {}", arg);
91 return registration == null && children.isEmpty();
94 void remove(final YangInstanceIdentifier id) {
95 this.remove(id.getPathArguments().iterator());