sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1524136 - in /sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl: jobs/ jobs/queues/ support/
Date Tue, 17 Sep 2013 17:27:34 GMT
Author: cziegeler
Date: Tue Sep 17 17:27:34 2013
New Revision: 1524136

URL: http://svn.apache.org/r1524136
Log:
SLING-3028 :  Support for progress tracking of jobs 

Modified:
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobImpl.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/AbstractJobQueue.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/AbstractParallelJobQueue.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/OrderedJobQueue.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobImpl.java?rev=1524136&r1=1524135&r2=1524136&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobImpl.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobImpl.java
Tue Sep 17 17:27:34 2013
@@ -42,6 +42,9 @@ public class JobImpl implements Job {
     /** Internal job property if this is an bridged event (event admin). */
     public static final String PROPERTY_BRIDGED_EVENT = "slingevent:eventadmin";
 
+    /** Internal job property containing optional delay override. */
+    public static final String PROPERTY_DELAY_OVERRIDE = ":slingevent:delayOverride";
+
     private final ValueMap properties;
 
     private final String topic;
@@ -230,6 +233,13 @@ public class JobImpl implements Job {
         }
     }
 
+    /**
+     * Prepare a new job execution
+     */
+    public void prepare() {
+        this.properties.remove(JobImpl.PROPERTY_DELAY_OVERRIDE);
+    }
+
     @Override
     public String toString() {
         return "JobImpl [properties=" + properties + ", topic=" + topic

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/AbstractJobQueue.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/AbstractJobQueue.java?rev=1524136&r1=1524135&r2=1524136&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/AbstractJobQueue.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/AbstractJobQueue.java
Tue Sep 17 17:27:34 2013
@@ -532,34 +532,35 @@ public abstract class AbstractJobQueue
 
                                 try {
                                     synchronized ( job ) {
+                                        job.prepare();
                                         result = consumer.process(job, new JobExecutionContext()
{
 
                                             @Override
-                                            public void update(long eta) {
+                                            public void update(final long eta) {
                                                 // TODO Auto-generated method stub
 
                                             }
 
                                             @Override
-                                            public void startProgress(long eta) {
+                                            public void startProgress(final long eta) {
                                                 // TODO Auto-generated method stub
 
                                             }
 
                                             @Override
-                                            public void startProgress(int steps) {
+                                            public void startProgress(final int steps) {
                                                 // TODO Auto-generated method stub
 
                                             }
 
                                             @Override
-                                            public void setProgress(int step) {
+                                            public void setProgress(final int step) {
                                                 // TODO Auto-generated method stub
 
                                             }
 
                                             @Override
-                                            public void log(String message, Object... args)
{
+                                            public void log(final String message, Object...
args) {
                                                 // TODO Auto-generated method stub
 
                                             }
@@ -590,6 +591,9 @@ public abstract class AbstractJobQueue
                                     currentThread.setPriority(oldPriority);
                                     currentThread.setName(oldName);
                                     if ( result != null ) {
+                                        if ( result.getRetryDelayInMs() != null ) {
+                                            job.setProperty(JobImpl.PROPERTY_DELAY_OVERRIDE,
result.getRetryDelayInMs());
+                                        }
                                         finishedJob(job.getId(), result, false);
                                     }
                                 }
@@ -783,6 +787,16 @@ public abstract class AbstractJobQueue
         return null;
     }
 
+    protected long getRetryDelay(final JobHandler handler) {
+        long delay = this.configuration.getRetryDelayInMs();
+        if ( handler.getJob().getProperty(JobImpl.PROPERTY_DELAY_OVERRIDE) != null ) {
+            delay = handler.getJob().getProperty(JobImpl.PROPERTY_DELAY_OVERRIDE, Long.class);
+        } else  if ( handler.getJob().getProperty(Job.PROPERTY_JOB_RETRY_DELAY) != null )
{
+            delay = handler.getJob().getProperty(Job.PROPERTY_JOB_RETRY_DELAY, Long.class);
+        }
+        return delay;
+    }
+
     /**
      * Reschedule a job.
      */

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/AbstractParallelJobQueue.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/AbstractParallelJobQueue.java?rev=1524136&r1=1524135&r2=1524136&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/AbstractParallelJobQueue.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/AbstractParallelJobQueue.java
Tue Sep 17 17:27:34 2013
@@ -24,7 +24,6 @@ import org.apache.sling.commons.schedule
 import org.apache.sling.event.impl.jobs.JobConsumerManager;
 import org.apache.sling.event.impl.jobs.JobHandler;
 import org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration;
-import org.apache.sling.event.jobs.Job;
 import org.osgi.service.event.EventAdmin;
 
 /**
@@ -123,10 +122,7 @@ public abstract class AbstractParallelJo
     protected JobHandler reschedule(final JobHandler info) {
         // we just sleep for the delay time - if none, we continue and retry
         // this job again
-        long delay = this.configuration.getRetryDelayInMs();
-        if ( info.getJob().getProperty(Job.PROPERTY_JOB_RETRY_DELAY) != null ) {
-            delay = info.getJob().getProperty(Job.PROPERTY_JOB_RETRY_DELAY, Long.class);
-        }
+        final long delay = this.getRetryDelay(info);
         if ( delay > 0 ) {
             final Date fireDate = new Date();
             fireDate.setTime(System.currentTimeMillis() + delay);

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/OrderedJobQueue.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/OrderedJobQueue.java?rev=1524136&r1=1524135&r2=1524136&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/OrderedJobQueue.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/queues/OrderedJobQueue.java
Tue Sep 17 17:27:34 2013
@@ -29,7 +29,6 @@ import java.util.TreeSet;
 import org.apache.sling.event.impl.jobs.JobConsumerManager;
 import org.apache.sling.event.impl.jobs.JobHandler;
 import org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration;
-import org.apache.sling.event.jobs.Job;
 import org.osgi.service.event.EventAdmin;
 
 /**
@@ -169,10 +168,7 @@ public final class OrderedJobQueue exten
     protected JobHandler reschedule(final JobHandler handler) {
         // we just sleep for the delay time - if none, we continue and retry
         // this job again
-        long delay = this.configuration.getRetryDelayInMs();
-        if ( handler.getJob().getProperty(Job.PROPERTY_JOB_RETRY_DELAY) != null ) {
-            delay = handler.getJob().getProperty(Job.PROPERTY_JOB_RETRY_DELAY, Long.class);
-        }
+        final long delay = this.getRetryDelay(handler);
         if ( delay > 0 ) {
             synchronized ( this.sleepLock ) {
                 this.sleepLock.sleepingSince = System.currentTimeMillis();

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java?rev=1524136&r1=1524135&r2=1524136&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java
Tue Sep 17 17:27:34 2013
@@ -34,8 +34,10 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.event.EventUtil;
+import org.apache.sling.event.impl.jobs.JobImpl;
 import org.apache.sling.event.impl.jobs.deprecated.JobStatusNotifier;
 import org.apache.sling.event.jobs.JobUtil;
+import org.apache.sling.event.jobs.consumer.JobConsumer;
 import org.osgi.service.event.EventConstants;
 
 public abstract class ResourceHelper {
@@ -61,7 +63,9 @@ public abstract class ResourceHelper {
         JobUtil.PROPERTY_JOB_RUN_LOCAL,
         JobUtil.PROPERTY_JOB_QUEUE_ORDERED,
         JobUtil.PROPERTY_NOTIFICATION_JOB,
-        JobStatusNotifier.CONTEXT_PROPERTY_NAME
+        JobStatusNotifier.CONTEXT_PROPERTY_NAME,
+        JobImpl.PROPERTY_DELAY_OVERRIDE,
+        JobConsumer.PROPERTY_JOB_ASYNC_HANDLER
     };
 
     /**



Mime
View raw message