Convert DeviceTransactionManagerImpl into a cmpnt 47/104347/4
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 9 Feb 2023 16:02:59 +0000 (17:02 +0100)
committerGilles Thouenon <gilles.thouenon@orange.com>
Tue, 14 Feb 2023 15:13:12 +0000 (15:13 +0000)
This is a simplistic component, split it off from blueprint. While we
are at it, mark hard-coded constants for future tuning.

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

index eaa7773d99c065dc5c7c3edc28d502f8c781243f..1e92c51c67cd3f05f27f311ebd53478c5c486fba 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.transportpce.common.device;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -33,32 +35,43 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 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.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
-public class DeviceTransactionManagerImpl implements DeviceTransactionManager {
+@Component
+public final class DeviceTransactionManagerImpl implements DeviceTransactionManager {
 
     // TODO cache device data brokers
     // TODO remove disconnected devices from maps
 
     private static final Logger LOG = LoggerFactory.getLogger(DeviceTransactionManagerImpl.class);
+    // TODO add an @ObjectClassDefinition to make these configurable at runtime
     private static final int NUMBER_OF_THREADS = 4;
     private static final long GET_DATA_SUBMIT_TIMEOUT = 3000;
     private static final TimeUnit GET_DATA_SUBMIT_TIME_UNIT = TimeUnit.MILLISECONDS;
+    // TODO set reasonable value here for maxDurationToSubmitTransaction
+    private static final long MAX_DURATION_TO_SUBMIT = 15000;
     private static final TimeUnit MAX_DURATION_TO_SUBMIT_TIMEUNIT = TimeUnit.MILLISECONDS;
 
     private final MountPointService mountPointService;
     private final ScheduledExecutorService checkingExecutor;
     private final ListeningExecutorService listeningExecutor;
-    private final ConcurrentMap<String, CountDownLatch> deviceLocks;
-    // TODO set reasonable value in blueprint for maxDurationToSubmitTransaction
+    private final ConcurrentMap<String, CountDownLatch> deviceLocks = new ConcurrentHashMap<>();
     private final long maxDurationToSubmitTransaction;
 
-    public DeviceTransactionManagerImpl(MountPointService mountPointService, long maxDurationToSubmitTransaction) {
-        this.mountPointService = mountPointService;
+    @Activate
+    public DeviceTransactionManagerImpl(@Reference MountPointService mountPointService) {
+        this(mountPointService, MAX_DURATION_TO_SUBMIT);
+    }
+
+    public DeviceTransactionManagerImpl(MountPointService mountPointService,
+            long maxDurationToSubmitTransaction) {
+        this.mountPointService = requireNonNull(mountPointService);
         this.maxDurationToSubmitTransaction = maxDurationToSubmitTransaction;
-        this.deviceLocks = new ConcurrentHashMap<>();
         this.checkingExecutor = Executors.newScheduledThreadPool(NUMBER_OF_THREADS);
         this.listeningExecutor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUMBER_OF_THREADS));
     }
@@ -175,6 +188,7 @@ public class DeviceTransactionManagerImpl implements DeviceTransactionManager {
         return getDeviceDataBroker(deviceId).isPresent();
     }
 
+    @Deactivate
     public void preDestroy() {
         checkingExecutor.shutdown();
         listeningExecutor.shutdown();
index 62688f3443fc4b474bd4a0888cf47518e7e8cc71..29657ee8e9d92f6c01681a31f9803fbb9e5c3c97 100644 (file)
@@ -9,16 +9,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
 -->
 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
 
-    <reference id="mountPointService" interface="org.opendaylight.mdsal.binding.api.MountPointService" />
     <reference id="dataBroker" interface="org.opendaylight.mdsal.binding.api.DataBroker" />
+    <reference id="deviceTransactionManager" interface="org.opendaylight.transportpce.common.device.DeviceTransactionManager" />
     <reference id="mappingUtils" interface="org.opendaylight.transportpce.common.mapping.MappingUtils" />
 
-    <bean id="deviceTransactionManager" class="org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl"
-          destroy-method="preDestroy" >
-        <argument ref="mountPointService" />
-        <argument value="15000" />
-    </bean>
-
     <bean id="openRoadmInterfaces121" class="org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121" >
         <argument ref="deviceTransactionManager" />
     </bean>
@@ -93,8 +87,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
         <argument ref="crossConnect710" />
     </bean>
 
-    <service ref="deviceTransactionManager" interface="org.opendaylight.transportpce.common.device.DeviceTransactionManager" />
-
     <service ref="networkTransactionImpl" interface="org.opendaylight.transportpce.common.network.NetworkTransactionService" />
 
     <service ref="openRoadmInterfaces" interface="org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces" />