incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1053386 - in /sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets: JobStatus.java impl/BackgroundRequestExecutionJob.java impl/SuspendableOutputStream.java impl/storage/NodeJobStatusFactoryImpl.java
Date Tue, 28 Dec 2010 16:34:29 GMT
Author: bdelacretaz
Date: Tue Dec 28 16:34:28 2010
New Revision: 1053386

URL: http://svn.apache.org/viewvc?rev=1053386&view=rev
Log:
SLING-1904 - indicate allowed state transitions

Modified:
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobStatus.java
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundRequestExecutionJob.java
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/SuspendableOutputStream.java
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/storage/NodeJobStatusFactoryImpl.java

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobStatus.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobStatus.java?rev=1053386&r1=1053385&r2=1053386&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobStatus.java
(original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobStatus.java
Tue Dec 28 16:34:28 2010
@@ -40,6 +40,14 @@ public interface JobStatus {
      * immediately, or even be ignored.
      */
     void requestStateChange(State s);
+    
+    /** Indicate which state changes a human user can currently request,
+     *  based on our state. For a human user, the only states that make sense
+     *  to be requested are RUNNING, SUSPENDED and STOPPED, or a subset
+     *  of those based on current state.
+     *  @return empty array if no state change allowed 
+     */
+    State [] getAllowedHumanStateChanges();
 
     /** Path of the Resource that describes this job */
     String getPath();

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundRequestExecutionJob.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundRequestExecutionJob.java?rev=1053386&r1=1053385&r2=1053386&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundRequestExecutionJob.java
(original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundRequestExecutionJob.java
Tue Dec 28 16:34:28 2010
@@ -35,6 +35,7 @@ import org.apache.sling.bgservlets.JobPr
 import org.apache.sling.bgservlets.JobStatus;
 import org.apache.sling.bgservlets.JobStorage;
 import org.apache.sling.bgservlets.RuntimeState;
+import org.apache.sling.bgservlets.JobStatus.State;
 import org.apache.sling.engine.SlingRequestProcessor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -112,18 +113,26 @@ class BackgroundRequestExecutionJob impl
         }
     }
 
+    /** @inheritDoc */
     public String getPath() {
         return path;
     }
 
+    /** @inheritDoc */
     public State getState() {
         return stream.getState();
     }
 
+    /** @inheritDoc */
     public void requestStateChange(State s) {
         stream.requestStateChange(s);
     }
 
+    /** @inheritDoc */
+    public State[] getAllowedHumanStateChanges() {
+        return stream.getAllowedHumanStateChanges();
+    }
+
     public String getStreamPath() {
         return streamPath;
     }
@@ -132,14 +141,17 @@ class BackgroundRequestExecutionJob impl
         return creationTime;
     }
 
+    /** @inheritDoc */
     public JobProgressInfo getProgressInfo() {
         return this;
     }
 
+    /** @inheritDoc */
     public String getProgressMessage() {
         return progressMessage;
     }
 
+    /** @inheritDoc */
     public Date getEstimatedCompletionTime() {
         return estimatedCompletionTime;
     }

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/SuspendableOutputStream.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/SuspendableOutputStream.java?rev=1053386&r1=1053385&r2=1053386&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/SuspendableOutputStream.java
(original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/SuspendableOutputStream.java
Tue Dec 28 16:34:28 2010
@@ -154,6 +154,21 @@ public class SuspendableOutputStream ext
                     + " -> " + s);
         }
     }
+    
+    /** @inheritDoc */
+    public State [] getAllowedHumanStateChanges() {
+        return getAllowedStates(state);
+    }
+    
+    static State [] getAllowedStates(State s) {
+        State [] result = new State[] {};
+        if(s == State.RUNNING) {
+            result = new State[] { State.SUSPENDED, State.STOPPED }; 
+        } else if(s == State.SUSPEND_REQUESTED || s == State.SUSPENDED) {
+            result = new State[] { State.RUNNING, State.STOPPED }; 
+        }
+        return result;
+    }
 
     /**
      * Not implemented

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/storage/NodeJobStatusFactoryImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/storage/NodeJobStatusFactoryImpl.java?rev=1053386&r1=1053385&r2=1053386&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/storage/NodeJobStatusFactoryImpl.java
(original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/storage/NodeJobStatusFactoryImpl.java
Tue Dec 28 16:34:28 2010
@@ -30,6 +30,7 @@ import org.apache.sling.bgservlets.Execu
 import org.apache.sling.bgservlets.JobData;
 import org.apache.sling.bgservlets.JobProgressInfo;
 import org.apache.sling.bgservlets.JobStatus;
+import org.apache.sling.bgservlets.JobStatus.State;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -92,6 +93,15 @@ public class NodeJobStatusFactoryImpl im
             }
         }
         
+        /** @inheritDoc */
+        public State [] getAllowedHumanStateChanges() {
+            final JobStatus j = getActiveJob();
+            if(j == null) {
+                return new State[] {};
+            }
+            return j.getAllowedHumanStateChanges();
+        }
+        
         private JobStatus getActiveJob() {
             if(executionEngine != null) {
                 return executionEngine.getJobStatus(path);



Mime
View raw message