Use ClassToInstanceMap for extensions 35/73935/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 11 Jul 2018 13:01:25 +0000 (15:01 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 11 Jul 2018 13:01:25 +0000 (15:01 +0200)
Using a plain map was an API design mistake, make sure implementations
are serving a ClassToInstanceMap before embarking on migration.

Change-Id: I2609d08d9df9f0da8d4f23fdeb5007979db80d72
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/AbstractDOMBroker.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/compat/LegacyDOMDataBrokerAdapter.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTree.java

index 799e94a..c2c604e 100644 (file)
@@ -10,8 +10,9 @@ package org.opendaylight.controller.cluster.databroker;
 
 import static com.google.common.base.Preconditions.checkState;
 
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableMap.Builder;
+import com.google.common.collect.ClassToInstanceMap;
+import com.google.common.collect.ImmutableClassToInstanceMap;
+import com.google.common.collect.ImmutableClassToInstanceMap.Builder;
 import java.util.EnumMap;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicLong;
@@ -39,13 +40,14 @@ public abstract class AbstractDOMBroker extends AbstractDOMTransactionFactory<DO
 
     private final AtomicLong txNum = new AtomicLong();
     private final AtomicLong chainNum = new AtomicLong();
-    private final Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> extensions;
+    private final ClassToInstanceMap<DOMDataBrokerExtension> extensions;
+
     private volatile AutoCloseable closeable;
 
     protected AbstractDOMBroker(final Map<LogicalDatastoreType, DOMStore> datastores) {
         super(datastores);
 
-        Builder<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> extBuilder = ImmutableMap.builder();
+        Builder<DOMDataBrokerExtension> extBuilder = ImmutableClassToInstanceMap.builder();
         if (isSupported(datastores, DOMStoreTreeChangePublisher.class)) {
             extBuilder.put(DOMDataTreeChangeService.class, new DOMDataTreeChangeService() {
                 @Override
index 2455466..4555b87 100644 (file)
@@ -9,9 +9,10 @@ package org.opendaylight.controller.cluster.databroker.compat;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
+import com.google.common.collect.ClassToInstanceMap;
 import com.google.common.collect.ForwardingObject;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableMap.Builder;
+import com.google.common.collect.ImmutableClassToInstanceMap;
+import com.google.common.collect.ImmutableClassToInstanceMap.Builder;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.FutureCallback;
@@ -78,7 +79,7 @@ public class LegacyDOMDataBrokerAdapter extends ForwardingObject implements DOMD
     };
 
     private final AbstractDOMBroker delegate;
-    private final Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> extensions;
+    private final ClassToInstanceMap<DOMDataBrokerExtension> extensions;
 
     public LegacyDOMDataBrokerAdapter(AbstractDOMBroker delegate) {
         this.delegate = delegate;
@@ -87,7 +88,7 @@ public class LegacyDOMDataBrokerAdapter extends ForwardingObject implements DOMD
             org.opendaylight.mdsal.dom.api.DOMDataBrokerExtension> delegateExtensions =
                 delegate.getSupportedExtensions();
 
-        Builder<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> extBuilder = ImmutableMap.builder();
+        Builder<DOMDataBrokerExtension> extBuilder = ImmutableClassToInstanceMap.builder();
         final org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService delegateTreeChangeService =
                 (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService) delegateExtensions.get(
                         org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService.class);
index 53d0270..e61fc52 100644 (file)
@@ -22,7 +22,7 @@ import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Throwables;
 import com.google.common.collect.ForwardingObject;
-import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableClassToInstanceMap;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -289,7 +289,7 @@ public class DistributedShardedDOMDataTree implements DOMDataTreeService, DOMDat
 
     @Override
     public Map<Class<? extends DOMDataTreeServiceExtension>, DOMDataTreeServiceExtension> getSupportedExtensions() {
-        return ImmutableMap.of();
+        return ImmutableClassToInstanceMap.of();
     }
 
     @Nonnull

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.