Use a dedicated timer in programming-impl 12/110412/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 1 Mar 2024 13:22:37 +0000 (14:22 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 1 Mar 2024 13:23:34 +0000 (14:23 +0100)
The global timer is going away. Use a dedicated timer instead.

Change-Id: I78a21dee2905f66ce04af9751a154b7cb7780fb9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/DefaultInstructionSchedulerFactory.java

index 3ff42b5bddf157d583f2353074a817d3e3df2a2c..e510444adf91f5cf86a0fc62731f6c36faa7f53f 100644 (file)
@@ -9,9 +9,12 @@ package org.opendaylight.bgpcep.programming.impl;
 
 import static java.util.Objects.requireNonNull;
 
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import io.netty.util.HashedWheelTimer;
 import io.netty.util.Timer;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -32,24 +35,26 @@ import org.slf4j.LoggerFactory;
 @Singleton
 public final class DefaultInstructionSchedulerFactory implements InstructionSchedulerFactory, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(DefaultInstructionSchedulerFactory.class);
+    private static final ThreadFactory THREAD_FACTORY = new ThreadFactoryBuilder()
+        .setNameFormat("programming-timer-%d")
+        .setDaemon(true)
+        .build();
 
+    private final ExecutorService exec = Executors.newSingleThreadExecutor();
+    private final Timer timer = new HashedWheelTimer(THREAD_FACTORY);
     private final DataBroker dataProvider;
     private final NotificationPublishService notifs;
-    private final Timer timer;
     private final RpcProviderService rpcProviderRegistry;
     private final ClusterSingletonServiceProvider cssp;
-    private final ExecutorService exec = Executors.newSingleThreadExecutor();
 
     @Inject
     @Activate
     public DefaultInstructionSchedulerFactory(@Reference final DataBroker dataProvider,
             @Reference final RpcProviderService rpcProviderRegistry,
             @Reference final NotificationPublishService notifs,
-            @Reference(target = "(type=global-timer)") final Timer timer,
             @Reference final ClusterSingletonServiceProvider cssp) {
         this.dataProvider = requireNonNull(dataProvider);
         this.notifs = requireNonNull(notifs);
-        this.timer = requireNonNull(timer);
         this.rpcProviderRegistry = requireNonNull(rpcProviderRegistry);
         this.cssp = requireNonNull(cssp);
     }
@@ -67,5 +72,6 @@ public final class DefaultInstructionSchedulerFactory implements InstructionSche
     public void close() {
         // FIXME: This can have weird effects: should we keep track of all schedulers and refcount?
         exec.shutdown();
+        timer.stop();
     }
 }