incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r686165 - /incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
Date Fri, 15 Aug 2008 07:33:02 GMT
Author: cziegeler
Date: Fri Aug 15 00:33:01 2008
New Revision: 686165

URL: http://svn.apache.org/viewvc?rev=686165&view=rev
Log:
SLING-614 : Persist retry count in repository 

Modified:
    incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java

Modified: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java?rev=686165&r1=686164&r2=686165&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
(original)
+++ incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
Fri Aug 15 00:33:01 2008
@@ -632,6 +632,26 @@
         if ( jobId != null ) {
             eventNode.setProperty(EventHelper.NODE_PROPERTY_JOBID, jobId);
         }
+        final long retryCount = OsgiUtil.toLong(event.getProperty(EventUtil.PROPERTY_JOB_RETRY_COUNT),
0);
+        final long retries = OsgiUtil.toLong(event.getProperty(EventUtil.PROPERTY_JOB_RETRIES),
this.maxJobRetries);
+        eventNode.setProperty(EventUtil.PROPERTY_JOB_RETRY_COUNT, retryCount);
+        eventNode.setProperty(EventUtil.PROPERTY_JOB_RETRIES, retries);
+    }
+
+    /**
+     * @see org.apache.sling.event.impl.AbstractRepositoryEventHandler#addEventProperties(javax.jcr.Node,
java.util.Dictionary)
+     */
+    protected void addEventProperties(Node eventNode,
+                                      Dictionary<String, Object> properties)
+    throws RepositoryException {
+        super.addEventProperties(eventNode, properties);
+        // convert to integers (jcr only supports long)
+        if ( properties.get(EventUtil.PROPERTY_JOB_RETRIES) != null ) {
+            properties.put(EventUtil.PROPERTY_JOB_RETRIES, Integer.valueOf(properties.get(EventUtil.PROPERTY_JOB_RETRIES).toString()));
+        }
+        if ( properties.get(EventUtil.PROPERTY_JOB_RETRY_COUNT) != null ) {
+            properties.put(EventUtil.PROPERTY_JOB_RETRY_COUNT, Integer.valueOf(properties.get(EventUtil.PROPERTY_JOB_RETRY_COUNT).toString()));
+        }
     }
 
     /**
@@ -756,19 +776,22 @@
                 retryCount = (Integer)job.getProperty(EventUtil.PROPERTY_JOB_RETRY_COUNT);
             }
             retryCount++;
-            if ( retryCount > retries ) {
+            if ( retries != -1 && retryCount > retries ) {
                 reschedule = 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]));
+            if ( !reschedule ) {
+                // update event with retry count and retries
+                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(EventUtil.PROPERTY_JOB_RETRY_COUNT, retryCount);
+                newProperties.put(EventUtil.PROPERTY_JOB_RETRIES, retries);
+                job = new Event(job.getTopic(), newProperties);
             }
-            newProperties.put(EventUtil.PROPERTY_JOB_RETRY_COUNT, retryCount);
-            job = new Event(job.getTopic(), newProperties);
         }
         final boolean parallelProcessing = job.getProperty(EventUtil.PROPERTY_JOB_PARALLEL)
!= null;
         // we have to use the same session for unlocking that we used for locking!
@@ -825,6 +848,15 @@
                     }
                 }
                 if ( reschedule ) {
+                    // update retry count and retries in the repository
+                    try {
+                        eventNode.setProperty(EventUtil.PROPERTY_JOB_RETRIES, (Integer)job.getProperty(EventUtil.PROPERTY_JOB_RETRIES));
+                        eventNode.setProperty(EventUtil.PROPERTY_JOB_RETRY_COUNT, (Integer)job.getProperty(EventUtil.PROPERTY_JOB_RETRY_COUNT));
+                        eventNode.save();
+                    } catch (RepositoryException re) {
+                        // if an exception occurs, we just log
+                        this.logger.error("Exception during job updating job rescheduling
information.", re);
+                    }
                     final EventInfo info = new EventInfo();
                     try {
                         info.event = job;



Mime
View raw message