geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r153824 - in geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer: ExecutorFeedingTimerTask.java ThreadPooledTimer.java
Date Mon, 14 Feb 2005 18:27:01 GMT
Author: djencks
Date: Mon Feb 14 10:26:54 2005
New Revision: 153824

URL: http://svn.apache.org/viewcvs?view=rev&rev=153824
Log:
don't try to actually start a timer that has already been cancelled

Modified:
    geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/ExecutorFeedingTimerTask.java
    geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/ThreadPooledTimer.java

Modified: geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/ExecutorFeedingTimerTask.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/ExecutorFeedingTimerTask.java?view=diff&r1=153823&r2=153824
==============================================================================
--- geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/ExecutorFeedingTimerTask.java
(original)
+++ geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/ExecutorFeedingTimerTask.java
Mon Feb 14 10:26:54 2005
@@ -39,6 +39,7 @@
 
     private final WorkInfo workInfo;
     private final ThreadPooledTimer threadPooledTimer;
+    boolean cancelled = false;
 
     public ExecutorFeedingTimerTask(WorkInfo workInfo, ThreadPooledTimer threadPooledTimer)
{
         this.workInfo = workInfo;
@@ -59,14 +60,19 @@
             threadPooledTimer.registerSynchronization(new CancelSynchronization(this));
         } catch (RollbackException e) {
             log.info(e);
-            throw (IllegalStateException) new IllegalStateException("RollbackException when
trying to register cacel synchronization").initCause(e);
+            throw (IllegalStateException) new IllegalStateException("RollbackException when
trying to register Cancel Synchronization").initCause(e);
         } catch (SystemException e) {
             log.info(e);
-            throw (IllegalStateException) new IllegalStateException("SystemException when
trying to register cacel synchronization").initCause(e);
+            throw (IllegalStateException) new IllegalStateException("SystemException when
trying to register Cancel Synchronization").initCause(e);
         }
         // One cancels the task at this specific time. If the transaction is
         // rolled-back, one will recreate it.
+        cancelled = true;
         return super.cancel();
+    }
+
+    public boolean isCancelled() {
+        return cancelled;
     }
 
     private void doCancel() {

Modified: geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/ThreadPooledTimer.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/ThreadPooledTimer.java?view=diff&r1=153823&r2=153824
==============================================================================
--- geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/ThreadPooledTimer.java
(original)
+++ geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/ThreadPooledTimer.java
Mon Feb 14 10:26:54 2005
@@ -37,6 +37,8 @@
 import org.apache.geronimo.gbean.GBeanLifecycle;
 import org.apache.geronimo.transaction.context.TransactionContext;
 import org.apache.geronimo.transaction.context.TransactionContextManager;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  *
@@ -46,6 +48,8 @@
  * */
 public class ThreadPooledTimer implements PersistentTimer, GBeanLifecycle {
 
+    private static final Log log = LogFactory.getLog(ThreadPooledTimer.class);
+
     private final ExecutorTaskFactory executorTaskFactory;
     private final WorkerPersistence workerPersistence;
     private final Executor executor;
@@ -265,7 +269,16 @@
 
         public void afterCompletion(int status) {
             if (status == Status.STATUS_COMMITTED) {
-                getTimer().schedule(worker, time);
+                if (worker.isCancelled()) {
+                    log.trace("Worker is already cancelled, not scheduling");
+                    return;
+                }
+                try {
+                    getTimer().schedule(worker, time);
+                } catch (IllegalStateException e) {
+                    //TODO consider again if catching this exception is appropriate
+                    log.info("Couldn't schedule worker " + e.getMessage() + "at (now) " +
System.currentTimeMillis() + " for " + time.getTime());
+                }
             }
         }
     }
@@ -287,7 +300,15 @@
 
         public void afterCompletion(int status) {
             if (status == Status.STATUS_COMMITTED) {
-                getTimer().schedule(worker, time, period);
+                if (worker.isCancelled()) {
+                    log.trace("Worker is already cancelled, not scheduling/period");
+                    return;
+                }
+                try {
+                    getTimer().schedule(worker, time, period);
+                } catch (Exception e) {
+                    log.info("Couldn't schedule/period worker " + e.getMessage() + "at (now)
" + System.currentTimeMillis() + " for " + time.getTime());
+                }
             }
         }
     }
@@ -309,7 +330,15 @@
 
         public void afterCompletion(int status) {
             if (status == Status.STATUS_COMMITTED) {
-                getTimer().scheduleAtFixedRate(worker, time, period);
+                if (worker.isCancelled()) {
+                    log.trace("Worker is already cancelled, not scheduleAtFixedRate");
+                    return;
+                }
+                try {
+                    getTimer().scheduleAtFixedRate(worker, time, period);
+                } catch (Exception e) {
+                    log.info("Couldn't scheduleAtFixedRate worker " + e.getMessage() + "at
(now) " + System.currentTimeMillis() + " for " + time.getTime());
+                }
             }
         }
     }



Mime
View raw message