Convert MappingUtilsImpl into a Component 46/104346/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 9 Feb 2023 15:43:52 +0000 (16:43 +0100)
committerGilles Thouenon <gilles.thouenon@orange.com>
Mon, 13 Feb 2023 09:48:23 +0000 (10:48 +0100)
This is as simple a component as they come: a single dependency and a
single service published. Split it out of the blueprint container.

Change-Id: Ib94603ca9e7f54639444cde9c1cba30967d3b23b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
common/pom.xml
common/src/main/java/org/opendaylight/transportpce/common/mapping/MappingUtilsImpl.java
common/src/main/resources/OSGI-INF/blueprint/common-blueprint.xml

index 7b9031a5826f40f9b1d796c27ce18802e9173393..5bb0e995d163d967e5401da5b498082f5f539e6e 100644 (file)
       <groupId>com.google.code.gson</groupId>
       <artifactId>gson</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.service.component.annotations</artifactId>
+    </dependency>
 
     <!-- Testing dependencies -->
     <dependency>
index c94e26caa412689544e7233a8568053890512f1f..63d904db44fd67197574e6322fed70876db04e92 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.transportpce.common.mapping;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.ImmutableMap;
 import java.util.ArrayList;
 import java.util.List;
@@ -33,16 +35,17 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOC
 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOtsiOtsigroup;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.SupportedIfCapability;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
-public class MappingUtilsImpl implements MappingUtils {
+@Component
+public final class MappingUtilsImpl implements MappingUtils {
 
     private static final Logger LOG = LoggerFactory.getLogger(MappingUtilsImpl.class);
 
-    private final DataBroker dataBroker;
-
     private static final ImmutableMap<String, SupportedIfCapability> CAP_TYPE_MAP =
         ImmutableMap.<String, SupportedIfCapability>builder()
             .put("If400GE{qname=(http://org/openroadm/port/types?revision=2020-03-27)if-400GE}", If400GE.VALUE)
@@ -67,10 +70,11 @@ public class MappingUtilsImpl implements MappingUtils {
                 If100GEODU4.VALUE)
             .build();
 
-    public MappingUtilsImpl(DataBroker dataBroker) {
-
-        this.dataBroker = dataBroker;
+    private final DataBroker dataBroker;
 
+    @Activate
+    public MappingUtilsImpl(@Reference DataBroker dataBroker) {
+        this.dataBroker = requireNonNull(dataBroker);
     }
 
     public String getOpenRoadmVersion(String nodeId) {
index 527ef648c09711b64f4b2325de19255786d2a017..62688f3443fc4b474bd4a0888cf47518e7e8cc71 100644 (file)
@@ -11,6 +11,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
 
     <reference id="mountPointService" interface="org.opendaylight.mdsal.binding.api.MountPointService" />
     <reference id="dataBroker" interface="org.opendaylight.mdsal.binding.api.DataBroker" />
+    <reference id="mappingUtils" interface="org.opendaylight.transportpce.common.mapping.MappingUtils" />
 
     <bean id="deviceTransactionManager" class="org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl"
           destroy-method="preDestroy" >
@@ -18,10 +19,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
         <argument value="15000" />
     </bean>
 
-    <bean id="mappingUtils" class="org.opendaylight.transportpce.common.mapping.MappingUtilsImpl" >
-        <argument ref="dataBroker" />
-    </bean>
-
     <bean id="openRoadmInterfaces121" class="org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121" >
         <argument ref="deviceTransactionManager" />
     </bean>
@@ -106,6 +103,4 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
 
     <service ref="crossConnectImpl" interface="org.opendaylight.transportpce.common.crossconnect.CrossConnect" />
 
-    <service ref="mappingUtils" interface="org.opendaylight.transportpce.common.mapping.MappingUtils" />
-
 </blueprint>