Encapsulate HwvtepSouthboundUtil's executor 83/94583/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 9 Jan 2021 23:08:17 +0000 (00:08 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 10 Jan 2021 08:53:06 +0000 (09:53 +0100)
We do not want to leak this executor to prevent shenanigans. We really
just need a schedule() method.

Change-Id: Ida4004c82d1d99f51439ebbdf908f62d36bb6a25
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepOperGlobalListener.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundConstants.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundUtil.java

index 59356e4719eb327c984b33747f8ce1e55baade11..9bdb1371812c3c8409a54be4596e9f2e637b9d89 100644 (file)
@@ -104,7 +104,7 @@ public class HwvtepOperGlobalListener implements ClusteredDataTreeChangeListener
                 NODE_DELET_WAITING_JOBS.get(iid).add(job);
                 //Also delete the node so that reconciliation kicks in
                 deleteTheNodeOfOldConnection(iid, getNodeConnectionInfo(iid));
-                HwvtepSouthboundUtil.getScheduledExecutorService().schedule(() -> {
+                HwvtepSouthboundUtil.schedule(() -> {
                     runPendingJobs(iid);
                 }, HwvtepSouthboundConstants.HWVTEP_REGISTER_CALLBACKS_WAIT_TIMEOUT, TimeUnit.SECONDS);
             } else {
@@ -118,7 +118,7 @@ public class HwvtepOperGlobalListener implements ClusteredDataTreeChangeListener
     private synchronized void runPendingJobs(InstanceIdentifier<Node> iid) {
         List<Callable<Void>> jobs = NODE_DELET_WAITING_JOBS.remove(iid);
         if (jobs != null && !jobs.isEmpty()) {
-            jobs.forEach((job) -> {
+            jobs.forEach(job -> {
                 try {
                     LOG.error("Node disconnected job found {} running it now ", iid);
                     job.call();
@@ -131,7 +131,7 @@ public class HwvtepOperGlobalListener implements ClusteredDataTreeChangeListener
     }
 
     private static void connect(Collection<DataTreeModification<Node>> changes) {
-        changes.forEach((change) -> {
+        changes.forEach(change -> {
             InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
             DataObjectModification<Node> mod = change.getRootNode();
             Node node = getCreated(mod);
@@ -159,7 +159,7 @@ public class HwvtepOperGlobalListener implements ClusteredDataTreeChangeListener
     }
 
     private static void updated(Collection<DataTreeModification<Node>> changes) {
-        changes.forEach((change) -> {
+        changes.forEach(change -> {
             InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
             DataObjectModification<Node> mod = change.getRootNode();
             Node node = getUpdated(mod);
@@ -174,7 +174,7 @@ public class HwvtepOperGlobalListener implements ClusteredDataTreeChangeListener
     }
 
     private void disconnect(Collection<DataTreeModification<Node>> changes) {
-        changes.forEach((change) -> {
+        changes.forEach(change -> {
             InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
             DataObjectModification<Node> mod = change.getRootNode();
             Node node = getRemoved(mod);
@@ -194,7 +194,7 @@ public class HwvtepOperGlobalListener implements ClusteredDataTreeChangeListener
 
     public void scheduleOldConnectionNodeDelete(InstanceIdentifier<Node> iid) {
         ConnectionInfo oldConnectionInfo = getNodeConnectionInfo(iid);
-        HwvtepSouthboundUtil.getScheduledExecutorService().schedule(() -> {
+        HwvtepSouthboundUtil.schedule(() -> {
             deleteTheNodeOfOldConnection(iid, oldConnectionInfo);
         }, HwvtepSouthboundConstants.STALE_HWVTEP_CLEANUP_DELAY_SECS, TimeUnit.SECONDS);
     }
index c42be5bc953b2d465417da4d6b42663d1b7b3f47..597ca5da3811ab2411bd3225a77f481be989269b 100644 (file)
@@ -43,10 +43,8 @@ public interface HwvtepSouthboundConstants {
     int WAITING_QUEUE_CAPACITY = Integer.getInteger("hwvtep.wait.queue.capacity", 1000);
     long WAITING_JOB_EXPIRY_TIME_MILLIS = Integer.getInteger(
             "hwvtep.wait.job.expiry.time.millis", 90000);
-    Integer STALE_HWVTEP_CLEANUP_DELAY_SECS
-            = Integer.getInteger("stale.hwvtep.node.cleanup.delay.secs", 240);
-    Integer HWVTEP_REGISTER_CALLBACKS_WAIT_TIMEOUT
-            = Integer.getInteger("hwvtep.max.oper.wait.time.secs", 10);
+    int STALE_HWVTEP_CLEANUP_DELAY_SECS = Integer.getInteger("stale.hwvtep.node.cleanup.delay.secs", 240);
+    int HWVTEP_REGISTER_CALLBACKS_WAIT_TIMEOUT = Integer.getInteger("hwvtep.max.oper.wait.time.secs", 10);
     long IN_TRANSIT_STATE_EXPIRY_TIME_MILLIS = Integer.getInteger(
             "hwvtep.intransit.job.expiry.time.millis", 10000);
     long IN_TRANSIT_STATE_CHECK_PERIOD_MILLIS = Integer.getInteger(
index 1549109cbb1200e709cdedf27c63957fba3ceb98..fc0e3a2c1ee89935302ac845e4e511dcd3166ead 100644 (file)
@@ -17,6 +17,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.ReadTransaction;
 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
@@ -39,16 +40,17 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public final class HwvtepSouthboundUtil {
-
     private static final Logger LOG = LoggerFactory.getLogger(HwvtepSouthboundUtil.class);
+    private static final ScheduledExecutorService BACKGROUND_EXECUTOR =
+        Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder()
+            .setNameFormat("hwvteputil-executor-service-%d")
+            .build());
+
     private static final String SCHEMA_VERSION_MISMATCH =
             "{} column for {} table is not supported by this version of the {} schema: {}";
 
     private static InstanceIdentifierCodec instanceIdentifierCodec;
 
-    private static ScheduledExecutorService scheduledExecutorService = Executors
-            .newSingleThreadScheduledExecutor(new ThreadFactoryBuilder()
-                    .setNameFormat("hwvteputil-executor-service-%d").build());
 
     private HwvtepSouthboundUtil() {
         // Prevent instantiating a utility class
@@ -274,7 +276,7 @@ public final class HwvtepSouthboundUtil {
         return 0;
     }
 
-    public static ScheduledExecutorService getScheduledExecutorService() {
-        return scheduledExecutorService;
+    static void schedule(final Runnable command, final int delay, TimeUnit timeUnit) {
+        BACKGROUND_EXECUTOR.schedule(command, delay, timeUnit);
     }
 }