killbill-aplcache

Remove janitor from initialization after it has already been

9/18/2014 10:14:42 PM

Details

diff --git a/payment/src/main/java/org/killbill/billing/payment/core/Janitor.java b/payment/src/main/java/org/killbill/billing/payment/core/Janitor.java
index 4a1e516..fed5f7c 100644
--- a/payment/src/main/java/org/killbill/billing/payment/core/Janitor.java
+++ b/payment/src/main/java/org/killbill/billing/payment/core/Janitor.java
@@ -104,10 +104,15 @@ public class Janitor {
         this.pluginControlledPaymentAutomatonRunner = pluginControlledPaymentAutomatonRunner;
         this.retrySMHelper = retrySMHelper;
         this.controllerDispatcher = controllerDispatcher;
+        this.isStopped = false;
     }
 
     public void start() {
-        isStopped = false;
+        if (isStopped) {
+            log.warn("Janitor is not a restartable service, and was already started, aborting");
+            return;
+        }
+
         // Start task for removing old pending payments.
         final TimeUnit pendingRateUnit = paymentConfig.getJanitorRunningRate().getUnit();
         final long pendingPeriod = paymentConfig.getJanitorRunningRate().getPeriod();
@@ -120,7 +125,10 @@ public class Janitor {
     }
 
     public void stop() {
-        isStopped = true;
+        if (isStopped) {
+            log.warn("Janitor is already in a stopped state");
+            return;
+        }
         try {
             /* Previously submitted tasks will be executed with shutdown(); when task executes as a result of shutdown being called
              * or because it was already in its execution loop, it will check for the volatile boolean isStopped flag and
@@ -135,6 +143,8 @@ public class Janitor {
         } catch (InterruptedException e) {
             Thread.currentThread().interrupt();
             log.warn("Janitor stop sequence got interrupted");
+        } finally {
+            isStopped = true;
         }
     }