From: Robert Varga Date: Mon, 11 Jul 2022 21:25:38 +0000 (+0200) Subject: Use FrameworkUtil.asDictionary() X-Git-Tag: v6.0.1~2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=4fe7de82691dabf3e224987f2de5401e8c0e00ad Use FrameworkUtil.asDictionary() We do not need a Hashtable, use FrameworkUtil to give us what we need. Change-Id: I50099a7b8f036d7f7f8af467242005e74b48d89d Signed-off-by: Robert Varga --- diff --git a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintBundleTracker.java b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintBundleTracker.java index 26db1380cf..55994ca1f0 100644 --- a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintBundleTracker.java +++ b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintBundleTracker.java @@ -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 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 emptyDict() { - return new Hashtable<>(); - } - /** * Implemented from BundleActivator. */ diff --git a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/ComponentProcessor.java b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/ComponentProcessor.java index 2f0709f6af..b83cd829d0 100644 --- a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/ComponentProcessor.java +++ b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/ComponentProcessor.java @@ -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 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() { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OSGiDistributedDataStore.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OSGiDistributedDataStore.java index a0f6937344..0811137efa 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OSGiDistributedDataStore.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OSGiDistributedDataStore.java @@ -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 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); } }