Fix odl-config-persister
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / broker / impl / ShardedDOMDataTree.java
index 11eae5d8334ef2e91d0be9baa0c5e25f79e8fc14..9e7596f5561821dc2078c1bd4b080640bf6edd79 100644 (file)
@@ -27,9 +27,16 @@ 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);
+    private final Map<LogicalDatastoreType, ShardingTableEntry> shardingTables = new EnumMap<>(
+            LogicalDatastoreType.class);
     @GuardedBy("this")
     private final Map<DOMDataTreeIdentifier, DOMDataTreeProducer> idToProducer = new TreeMap<>();
 
@@ -45,13 +52,10 @@ public final class ShardedDOMDataTree implements DOMDataTreeService, DOMDataTree
 
     @GuardedBy("this")
     private void storeShard(final DOMDataTreeIdentifier prefix, final ShardRegistration<?> reg) {
-        ShardingTableEntry t = shardingTables.get(prefix.getDatastoreType());
-        if (t == null) {
-            t = new ShardingTableEntry();
-            shardingTables.put(prefix.getDatastoreType(), t);
-        }
+        ShardingTableEntry shardingTableEntry = shardingTables
+                .computeIfAbsent(prefix.getDatastoreType(), k -> new ShardingTableEntry());
 
-        t.store(prefix.getRootIdentifier(), reg);
+        shardingTableEntry.store(prefix.getRootIdentifier(), reg);
     }
 
     void removeShard(final ShardRegistration<?> reg) {
@@ -82,7 +86,8 @@ public final class ShardedDOMDataTree implements DOMDataTreeService, DOMDataTree
     }
 
     @Override
-    public <T extends DOMDataTreeShard> ListenerRegistration<T> registerDataTreeShard(final DOMDataTreeIdentifier prefix, final T shard) throws DOMDataTreeShardingConflictException {
+    public <T extends DOMDataTreeShard> ListenerRegistration<T> registerDataTreeShard(
+            final DOMDataTreeIdentifier prefix, final T shard) throws DOMDataTreeShardingConflictException {
         final ShardRegistration<T> reg;
         final ShardRegistration<?> parentReg;
 
@@ -95,12 +100,13 @@ public final class ShardedDOMDataTree implements DOMDataTreeService, DOMDataTree
             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 {}", prefix, parentReg.getInstance()));
+                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<T>(this, prefix, shard);
+            reg = new ShardRegistration<>(this, prefix, shard);
 
             storeShard(prefix, reg);
 
@@ -117,7 +123,7 @@ public final class ShardedDOMDataTree implements DOMDataTreeService, DOMDataTree
 
     @GuardedBy("this")
     private DOMDataTreeProducer findProducer(final DOMDataTreeIdentifier subtree) {
-        for (Entry<DOMDataTreeIdentifier, DOMDataTreeProducer> e : idToProducer.entrySet()) {
+        for (final Entry<DOMDataTreeIdentifier, DOMDataTreeProducer> e : idToProducer.entrySet()) {
             if (e.getKey().contains(subtree)) {
                 return e.getValue();
             }
@@ -127,10 +133,10 @@ public final class ShardedDOMDataTree implements DOMDataTreeService, DOMDataTree
     }
 
     synchronized void destroyProducer(final ShardedDOMDataTreeProducer producer) {
-        for (DOMDataTreeIdentifier s : producer.getSubtrees()) {
-            DOMDataTreeProducer r = idToProducer.remove(s);
+        for (final DOMDataTreeIdentifier s : producer.getSubtrees()) {
+            final DOMDataTreeProducer r = idToProducer.remove(s);
             if (!producer.equals(r)) {
-                LOG.error("Removed producer %s on subtree %s while removing %s", r, s, producer);
+                LOG.error("Removed producer {} on subtree {} while removing {}", r, s, producer);
             }
         }
     }
@@ -151,7 +157,7 @@ public final class ShardedDOMDataTree implements DOMDataTreeService, DOMDataTree
         Preconditions.checkArgument(!subtrees.isEmpty(), "Subtrees may not be empty");
 
         final Map<DOMDataTreeIdentifier, DOMDataTreeShard> shardMap = new HashMap<>();
-        for (DOMDataTreeIdentifier s : subtrees) {
+        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);
@@ -162,11 +168,12 @@ public final class ShardedDOMDataTree implements DOMDataTreeService, DOMDataTree
         return createProducer(shardMap);
     }
 
-    synchronized DOMDataTreeProducer createProducer(final ShardedDOMDataTreeProducer parent, final Collection<DOMDataTreeIdentifier> subtrees) {
+    synchronized DOMDataTreeProducer createProducer(final ShardedDOMDataTreeProducer parent,
+                                                    final Collection<DOMDataTreeIdentifier> subtrees) {
         Preconditions.checkNotNull(parent);
 
         final Map<DOMDataTreeIdentifier, DOMDataTreeShard> shardMap = new HashMap<>();
-        for (DOMDataTreeIdentifier s : subtrees) {
+        for (final DOMDataTreeIdentifier s : subtrees) {
             shardMap.put(s, lookupShard(s).getRegistration().getInstance());
         }
 
@@ -174,8 +181,12 @@ public final class ShardedDOMDataTree implements DOMDataTreeService, DOMDataTree
     }
 
     @Override
-    public synchronized <T extends DOMDataTreeListener> ListenerRegistration<T> registerListener(final T listener, final Collection<DOMDataTreeIdentifier> subtrees, final boolean allowRxMerges, final Collection<DOMDataTreeProducer> producers) {
-        // TODO Auto-generated method stub
-        return null;
+    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.");
     }
 }