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 * Sharding Table Entry.
23 * @deprecated To be removed with {@link ShardedDOMDataTree}.
26 final class ShardingTableEntry implements Identifiable<PathArgument> {
27 private static final Logger LOG = LoggerFactory.getLogger(ShardingTableEntry.class);
28 private final Map<PathArgument, ShardingTableEntry> children = Collections.emptyMap();
29 private final PathArgument identifier;
30 private ShardRegistration<?> registration;
32 ShardingTableEntry() {
36 ShardingTableEntry(final PathArgument identifier) {
37 this.identifier = Preconditions.checkNotNull(identifier);
41 public PathArgument getIdentifier() {
45 public ShardRegistration<?> getRegistration() {
49 ShardingTableEntry lookup(final YangInstanceIdentifier id) {
50 final Iterator<PathArgument> it = id.getPathArguments().iterator();
51 ShardingTableEntry entry = this;
53 while (it.hasNext()) {
54 final PathArgument a = it.next();
55 final ShardingTableEntry child = entry.children.get(a);
57 LOG.debug("Lookup of {} stopped at {}", id, a);
67 void store(final YangInstanceIdentifier id, final ShardRegistration<?> reg) {
68 final Iterator<PathArgument> it = id.getPathArguments().iterator();
69 ShardingTableEntry entry = this;
71 while (it.hasNext()) {
72 final PathArgument a = it.next();
73 ShardingTableEntry child = entry.children.computeIfAbsent(a, ShardingTableEntry::new);
76 Preconditions.checkState(entry.registration == null);
77 entry.registration = reg;
80 private boolean remove(final Iterator<PathArgument> it) {
82 final PathArgument arg = it.next();
83 final ShardingTableEntry child = children.get(arg);
85 if (child.remove(it)) {
89 LOG.warn("Cannot remove non-existent child {}", arg);
93 return registration == null && children.isEmpty();
96 void remove(final YangInstanceIdentifier id) {
97 this.remove(id.getPathArguments().iterator());