incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r619322 - /incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/EventUtil.java
Date Thu, 07 Feb 2008 09:34:16 GMT
Author: cziegeler
Date: Thu Feb  7 01:34:16 2008
New Revision: 619322

URL: http://svn.apache.org/viewvc?rev=619322&view=rev
Log:
SLING-177: Start adding support for rescheduling and retrying jobs.

Modified:
    incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/EventUtil.java

Modified: incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/EventUtil.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/EventUtil.java?rev=619322&r1=619321&r2=619322&view=diff
==============================================================================
--- incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/EventUtil.java
(original)
+++ incubator/sling/trunk/sling/event/src/main/java/org/apache/sling/event/EventUtil.java
Thu Feb  7 01:34:16 2008
@@ -40,12 +40,21 @@
     /** The job topic property. */
     public static final String PROPERTY_JOB_TOPIC = "event.job.topic";
 
-    /** The property for the unique event id. */
+    /** The property for the unique event id. Value is of type String. */
     public static final String PROPERTY_JOB_ID = "event.job.id";
 
     /** The property to set if a job can be run parallel to any other job. */
     public static final String PROPERTY_JOB_PARALLEL = "event.job.parallel";
 
+    /** The property to track the retry count for jobs. Value is of type Integer. */
+    public static final String PROPERTY_JOB_RETRY_COUNT = "event.job.retrycount";
+
+    /** The property to for setting the maximum number of retries. Value is of type Integer.
*/
+    public static final String PROPERTY_JOB_RETRIES = "event.job.retries";
+
+    /** The property to set a retry delay. Value is of type Long. */
+    public static final String PROPERTY_JOB_RETRY_DELAY = "event.job.retrydelay";
+
     /** The topic for jobs. */
     public static final String TOPIC_JOB = "org/apache/sling/event/job";
 
@@ -137,7 +146,30 @@
         if ( ctx == null ) {
             throw new NullPointerException("JobStatusNotifier context is not available in
event properties.");
         }
-        ctx.notifier.finishedJob(job, ctx.eventNodePath, ctx.lockToken, true);
+        boolean retry = true;
+        // check if we exceeded the number of retries
+        if ( job.getProperty(PROPERTY_JOB_RETRIES) != null ) {
+            int retries = (Integer) job.getProperty(PROPERTY_JOB_RETRIES);
+            int retryCount = 0;
+            if ( job.getProperty(PROPERTY_JOB_RETRY_COUNT) != null ) {
+                retryCount = (Integer)job.getProperty(PROPERTY_JOB_RETRY_COUNT);
+            }
+            retryCount++;
+            if ( retryCount >= retries ) {
+                retry = false;
+            }
+            // update event with retry count
+            final Dictionary<String, Object> newProperties;
+            // create a new dictionary
+            newProperties = new Hashtable<String, Object>();
+            final String[] names = job.getPropertyNames();
+            for(int i=0; i<names.length; i++ ) {
+                newProperties.put(names[i], job.getProperty(names[i]));
+            }
+            newProperties.put(PROPERTY_JOB_RETRY_COUNT, retryCount);
+            job = new Event(job.getTopic(), newProperties);
+        }
+        ctx.notifier.finishedJob(job, ctx.eventNodePath, ctx.lockToken, retry);
     }
 
     /**



Mime
View raw message