Use FrameworkUtil.asDictionary() 08/101808/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 11 Jul 2022 21:25:38 +0000 (23:25 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 11 Jul 2022 21:28:40 +0000 (23:28 +0200)
We do not need a Hashtable, use FrameworkUtil to give us what we need.

Change-Id: I50099a7b8f036d7f7f8af467242005e74b48d89d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintBundleTracker.java
opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/ComponentProcessor.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OSGiDistributedDataStore.java

index 26db1380cf96514c68b049339f474e37ef50a827..55994ca1f093ddf4b86a02ccc8847166d679dc8d 100644 (file)
@@ -11,23 +11,22 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashSet;
-import java.util.Hashtable;
 import java.util.List;
+import java.util.Map;
 import org.apache.aries.blueprint.NamespaceHandler;
 import org.apache.aries.blueprint.services.BlueprintExtenderService;
 import org.apache.aries.quiesce.participant.QuiesceParticipant;
 import org.apache.aries.util.AriesFrameworkUtil;
 import org.eclipse.jdt.annotation.Nullable;
-import org.gaul.modernizer_maven_annotations.SuppressModernizer;
 import org.opendaylight.controller.blueprint.ext.OpendaylightNamespaceHandler;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
+import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.framework.SynchronousBundleListener;
@@ -158,20 +157,15 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus
     }
 
     private void registerNamespaceHandler(final BundleContext context) {
-        Dictionary<String, Object> props = emptyDict();
-        props.put("osgi.service.blueprint.namespace", OpendaylightNamespaceHandler.NAMESPACE_1_0_0);
-        namespaceReg = context.registerService(NamespaceHandler.class, new OpendaylightNamespaceHandler(), props);
+        namespaceReg = context.registerService(NamespaceHandler.class, new OpendaylightNamespaceHandler(),
+            FrameworkUtil.asDictionary(Map.of(
+                "osgi.service.blueprint.namespace", OpendaylightNamespaceHandler.NAMESPACE_1_0_0)));
     }
 
     private void registerBlueprintEventHandler(final BundleContext context) {
         eventHandlerReg = context.registerService(BlueprintListener.class, this, null);
     }
 
-    @SuppressModernizer
-    private static Dictionary<String, Object> emptyDict() {
-        return new Hashtable<>();
-    }
-
     /**
      * Implemented from BundleActivator.
      */
index 2f0709f6af8fae04096bbb963c2baf5134d89134..b83cd829d02364aeefc2db1020c0852a15d83a97 100644 (file)
@@ -10,8 +10,8 @@ package org.opendaylight.controller.blueprint.ext;
 import com.google.common.base.Strings;
 import java.util.ArrayList;
 import java.util.Dictionary;
-import java.util.Hashtable;
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
 import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.aries.blueprint.ComponentDefinitionRegistry;
@@ -24,6 +24,7 @@ import org.gaul.modernizer_maven_annotations.SuppressModernizer;
 import org.opendaylight.controller.blueprint.BlueprintContainerRestartService;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
+import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.blueprint.reflect.BeanProperty;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
@@ -55,7 +56,7 @@ public class ComponentProcessor implements ComponentDefinitionRegistryProcessor
     }
 
     public void setBlueprintContainerRestartService(final BlueprintContainerRestartService restartService) {
-        this.blueprintContainerRestartService = restartService;
+        blueprintContainerRestartService = restartService;
     }
 
     public void setRestartDependentsOnUpdates(final boolean restartDependentsOnUpdates) {
@@ -156,11 +157,11 @@ public class ComponentProcessor implements ComponentDefinitionRegistryProcessor
             }
         };
 
-        Dictionary<String, Object> props = new Hashtable<>();
-        props.put(Constants.SERVICE_PID, persistentId);
-        props.put(Constants.BUNDLE_SYMBOLICNAME, bundle.getSymbolicName());
-        props.put(Constants.BUNDLE_VERSION, bundle.getHeaders().get(Constants.BUNDLE_VERSION));
-        managedServiceRegs.add(bundle.getBundleContext().registerService(ManagedService.class, managedService, props));
+        managedServiceRegs.add(bundle.getBundleContext().registerService(ManagedService.class, managedService,
+            FrameworkUtil.asDictionary(Map.of(
+                Constants.SERVICE_PID, persistentId,
+                Constants.BUNDLE_SYMBOLICNAME, bundle.getSymbolicName(),
+                Constants.BUNDLE_VERSION, bundle.getHeaders().get(Constants.BUNDLE_VERSION)))));
     }
 
     private String logName() {
index a0f6937344ed4df0efecee05ca5c9a59cb3cbcd8..0811137efa99d7e859d963309ec192e33dbe2aa1 100644 (file)
@@ -12,17 +12,15 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.annotations.Beta;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
-import java.util.Dictionary;
-import java.util.Hashtable;
 import java.util.Map;
 import org.checkerframework.checker.lock.qual.GuardedBy;
-import org.gaul.modernizer_maven_annotations.SuppressModernizer;
 import org.opendaylight.controller.cluster.ActorSystemProvider;
 import org.opendaylight.controller.cluster.datastore.config.Configuration;
 import org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl;
 import org.opendaylight.controller.cluster.datastore.config.ModuleShardConfigProvider;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.osgi.framework.FrameworkUtil;
 import org.osgi.service.component.ComponentFactory;
 import org.osgi.service.component.ComponentInstance;
 import org.osgi.service.component.annotations.Activate;
@@ -87,17 +85,15 @@ public final class OSGiDistributedDataStore {
         }
 
         @Override
-        @SuppressModernizer
         public void onSuccess(final Object result) {
             LOG.debug("Distributed Datastore type {} reached initial settle", datastoreType);
 
             synchronized (this) {
                 if (!stopped) {
-                    final Dictionary<String, Object> dict = new Hashtable<>();
-                    dict.put(OSGiDOMStore.DATASTORE_TYPE_PROP, datastoreType);
-                    dict.put(OSGiDOMStore.DATASTORE_INST_PROP, datastore);
-                    dict.put("type", serviceType);
-                    component = datastoreFactory.newInstance(dict);
+                    component = datastoreFactory.newInstance(FrameworkUtil.asDictionary(Map.of(
+                        OSGiDOMStore.DATASTORE_TYPE_PROP, datastoreType,
+                        OSGiDOMStore.DATASTORE_INST_PROP, datastore,
+                        "type", serviceType)));
                     LOG.info("Distributed Datastore type {} started", datastoreType);
                 }
             }