Author: cziegeler
Date: Fri Sep 27 16:02:44 2013
New Revision: 1526967

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

Modified:
    
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/jobs/consumer/JobExecutionContext.java

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=1526967&r1=1526966&r2=1526967&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
 Fri Sep 27 16:02:44 2013
@@ -542,23 +542,20 @@ public abstract class AbstractJobQueue
                                         result = consumer.process(job, new 
JobExecutionContext() {
 
                                             @Override
-                                            public void update(final long eta) 
{
-                                                
handler.updateProperty(job.update(eta));
-                                            }
-
-                                            @Override
-                                            public void startProgress(final 
long eta) {
+                                            public void initProgress(final int 
steps,
+                                                    final long eta) {
+                                                
handler.updateProperty(job.startProgress(steps));
                                                 
handler.updateProperty(job.startProgress(eta));
                                             }
 
                                             @Override
-                                            public void startProgress(final 
int steps) {
-                                                
handler.updateProperty(job.startProgress(steps));
+                                            public void 
incrementProgressCount(final int steps) {
+                                                
handler.updateProperty(job.setProgress(steps));
                                             }
 
                                             @Override
-                                            public void setProgress(final int 
step) {
-                                                
handler.updateProperty(job.setProgress(step));
+                                            public void updateProgress(final 
long eta) {
+                                                
handler.updateProperty(job.update(eta));
                                             }
 
                                             @Override

Modified: 
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/consumer/JobExecutionContext.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/consumer/JobExecutionContext.java?rev=1526967&r1=1526966&r2=1526967&view=diff
==============================================================================
--- 
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/consumer/JobExecutionContext.java
 (original)
+++ 
sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/consumer/JobExecutionContext.java
 Fri Sep 27 16:02:44 2013
@@ -37,45 +37,51 @@ public interface JobExecutionContext {
     /**
      * If a job is stoppable, it should periodically check this method
      * and stop processing if the method return <code>true</code>.
+     * If a job is stopped and the job executor detects this, its up
+     * to the implementation to decide the result of such a state.
+     * There might be use cases where the job returns {@link 
JobStatus#SUCCEEDED}
+     * although it didn't process everything, or {@link JobStatus#FAILED}
+     * to retry later on or {@link JobStatus#CANCELLED}.
      * @return Whether this job has been stopped from the outside.
      */
     boolean isStopped();
 
     /**
-     * Indicate that the job executor is able to report the progress
-     * by providing a step count.
+     * Indicate that the job executor is able to report the progress.
+     * The progress can either be reported by a step count,
+     * assuming that all steps take roughly the same amount of time.
+     * Or the progress can be reported by an ETA containing the number
+     * of seconds the job needs to finish.
      * This method should only be called once, consecutive calls
-     * or a call to {@link #startProgress(long)} have no effect.
+     * have no effect.
+     * By using a step count of 100, the progress can be displayed
+     * in percentage.
      * @param steps Number of total steps or -1 if the number of
      *              steps is unknown.
-     */
-    void startProgress(final int steps);
-
-    /**
-     * Indicate that the job executor is able to report the progress
-     * by providing an ETA.
-     * This method should only be called once, consecutive calls
-     * or a call to {@link #startProgress(int)} have no effect.
      * @param eta Number of seconds the process should take or
      *        -1 of it's not known now.
      */
-    void startProgress(final long eta);
+    void initProgress(final int steps, final long eta);
 
     /**
-     * Update the progress to the current finished step.
-     * This method has only effect if {@link #startProgress(int)}
-     * has been called first.
-     * @param step The current step.
+     * Update the progress by additionally marking the provided
+     * number of steps as finished. If the total number of finished
+     * steps is equal or higher to the initial number of steps
+     * reported in {@link #initProgress(int, long)}, then the
+     * job progress is assumed to be 100%.
+     * This method has only effect if {@link #initProgress(int, long)}
+     * has been called first with a positive number for steps
+     * @param step The number of finished steps since the last call.
      */
-    void setProgress(final int step);
+    void incrementProgressCount(final int steps);
 
     /**
      * Update the progress to the new ETA.
-     * This method has only effect if {@link #startProgress(long)}
+     * This method has only effect if {@link #initProgress(int, long)}
      * has been called first.
      * @param eta The new ETA
      */
-    void update(final long eta);
+    void updateProgress(final long eta);
 
     /**
      * Log a message.


Reply via email to