Do not allow global timer to be stopped
[controller.git] / opendaylight / config / netty-timer-config / src / main / java / org / opendaylight / controller / config / yang / netty / timer / HashedWheelTimerCloseable.java
index 8786f3af0a177a0068196f31bc352248f7e51da5..7bc13521642cb8475e505dcefe1a339ffd69463e 100644 (file)
@@ -14,7 +14,7 @@ import io.netty.util.TimerTask;
 import java.util.Set;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.Nullable;
 
 public final class HashedWheelTimerCloseable implements AutoCloseable, Timer {
 
@@ -25,7 +25,7 @@ public final class HashedWheelTimerCloseable implements AutoCloseable, Timer {
     }
 
     @Override
-    public void close() throws Exception {
+    public void close() {
         stop();
     }
 
@@ -39,27 +39,32 @@ public final class HashedWheelTimerCloseable implements AutoCloseable, Timer {
         return this.timer.stop();
     }
 
-    public static HashedWheelTimerCloseable newInstance(@Nullable final ThreadFactory threadFactory,
-            @Nullable final Long duration, @Nullable final Integer ticksPerWheel) {
+    public static HashedWheelTimerCloseable newInstance(final @Nullable Long duration,
+            final @Nullable Integer ticksPerWheel) {
+        return newInstance(null, duration, ticksPerWheel);
+    }
+
+    public static HashedWheelTimerCloseable newInstance(final @Nullable ThreadFactory threadFactory,
+            final @Nullable Long duration, final @Nullable Integer ticksPerWheel) {
         TimeUnit unit = TimeUnit.MILLISECONDS;
-        if(!nullOrNonPositive(duration) && threadFactory == null && nullOrNonPositive(ticksPerWheel)) {
+        if (!nullOrNonPositive(duration) && threadFactory == null && nullOrNonPositive(ticksPerWheel)) {
             return new HashedWheelTimerCloseable(new HashedWheelTimer(duration, unit));
         }
 
-        if(!nullOrNonPositive(duration) && threadFactory == null && !nullOrNonPositive(ticksPerWheel)) {
+        if (!nullOrNonPositive(duration) && threadFactory == null && !nullOrNonPositive(ticksPerWheel)) {
             return new HashedWheelTimerCloseable(new HashedWheelTimer(duration, unit, ticksPerWheel));
         }
 
-        if(nullOrNonPositive(duration) && threadFactory != null && nullOrNonPositive(ticksPerWheel)) {
+        if (nullOrNonPositive(duration) && threadFactory != null && nullOrNonPositive(ticksPerWheel)) {
             return new HashedWheelTimerCloseable(new HashedWheelTimer(threadFactory));
         }
 
-        if(!nullOrNonPositive(duration) && threadFactory != null && nullOrNonPositive(ticksPerWheel)) {
+        if (!nullOrNonPositive(duration) && threadFactory != null && nullOrNonPositive(ticksPerWheel)) {
             return new HashedWheelTimerCloseable(
                     new HashedWheelTimer(threadFactory, duration, unit));
         }
 
-        if(!nullOrNonPositive(duration) && threadFactory != null && !nullOrNonPositive(ticksPerWheel)) {
+        if (!nullOrNonPositive(duration) && threadFactory != null && !nullOrNonPositive(ticksPerWheel)) {
             return new HashedWheelTimerCloseable(
                     new HashedWheelTimer(threadFactory, duration, unit, ticksPerWheel));
         }
@@ -67,7 +72,7 @@ public final class HashedWheelTimerCloseable implements AutoCloseable, Timer {
         return new HashedWheelTimerCloseable(new HashedWheelTimer());
     }
 
-    private static boolean nullOrNonPositive(final Number n) {
-        return n == null || n.longValue() <= 0;
+    private static boolean nullOrNonPositive(final Number num) {
+        return num == null || num.longValue() <= 0;
     }
 }