From d60888a10b4c49cca3e3cc277ced79d05d0b3460 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 1 Mar 2024 14:22:37 +0100 Subject: [PATCH] Use a dedicated timer in programming-impl The global timer is going away. Use a dedicated timer instead. Change-Id: I78a21dee2905f66ce04af9751a154b7cb7780fb9 Signed-off-by: Robert Varga --- .../impl/DefaultInstructionSchedulerFactory.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/DefaultInstructionSchedulerFactory.java b/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/DefaultInstructionSchedulerFactory.java index 3ff42b5bdd..e510444adf 100644 --- a/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/DefaultInstructionSchedulerFactory.java +++ b/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/DefaultInstructionSchedulerFactory.java @@ -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(); } } -- 2.36.6