Use constructor injection for OSGiGlobalTimer 45/109445/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 28 Dec 2023 20:32:15 +0000 (21:32 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 28 Dec 2023 20:32:15 +0000 (21:32 +0100)
Upgraded SpotBugs is warning about field initialization, side-step it by
using constructor injection.

Change-Id: I1697459db8d72c956649f3c61f3d090322c3e9fb
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/config/netty-timer-config/src/main/java/org/opendaylight/controller/config/yang/netty/timer/OSGiGlobalTimer.java

index 96130007923f6bf843a22999fe331eefbff36a14..87e941d7c8cb5e234a1e4cdb0a719e0f1476a41c 100644 (file)
@@ -36,18 +36,8 @@ public final class OSGiGlobalTimer implements Timer {
 
     private Timer delegate;
 
-    @Override
-    public Timeout newTimeout(final TimerTask task, final long delay, final TimeUnit unit) {
-        return delegate.newTimeout(task, delay, unit);
-    }
-
-    @Override
-    public Set<Timeout> stop() {
-        return delegate.stop();
-    }
-
     @Activate
-    void activate(final Config config) {
+    public OSGiGlobalTimer(final Config config) {
         delegate = HashedWheelTimerCloseable.newInstance(config.tickDuration(), config.ticksPerWheel());
         LOG.info("Global Netty timer started");
     }
@@ -55,6 +45,17 @@ public final class OSGiGlobalTimer implements Timer {
     @Deactivate
     void deactivate() {
         delegate.stop();
+        delegate = null;
         LOG.info("Global Netty timer stopped");
     }
+
+    @Override
+    public Timeout newTimeout(final TimerTask task, final long delay, final TimeUnit unit) {
+        return delegate.newTimeout(task, delay, unit);
+    }
+
+    @Override
+    public Set<Timeout> stop() {
+        return delegate.stop();
+    }
 }