incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r981925 - in /sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets: ./ impl/ impl/servlets/ impl/storage/
Date Tue, 03 Aug 2010 15:22:52 GMT
Author: bdelacretaz
Date: Tue Aug  3 15:22:52 2010
New Revision: 981925

URL: http://svn.apache.org/viewvc?rev=981925&view=rev
Log:
SLING-550 - JobData and JobStatus provide creation time + stream path

Modified:
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/BackgroundServletConstants.java
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobConsole.java
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobData.java
    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/JobConsoleImpl.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/servlets/JobInfoServlet.java
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/storage/JobDataImpl.java
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/storage/JobStorageImpl.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/BackgroundServletConstants.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/BackgroundServletConstants.java?rev=981925&r1=981924&r2=981925&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/BackgroundServletConstants.java
(original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/BackgroundServletConstants.java
Tue Aug  3 15:22:52 2010
@@ -24,4 +24,7 @@ public class BackgroundServletConstants 
     
     /** Resource type for the stream node */
     public static final String STREAM_RESOURCE_TYPE = "sling/bg/stream";
+    
+    /** Property name used to store job nodes creation times */
+    public static final String CREATION_TIME_PROPERTY = "jcr:created";
 }

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobConsole.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobConsole.java?rev=981925&r1=981924&r2=981925&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobConsole.java
(original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobConsole.java
Tue Aug  3 15:22:52 2010
@@ -43,8 +43,9 @@ public interface JobConsole {
      */
     JobStatus getJobStatus(Session session, String path);
     
-    /** Return the full path, including extension, to use to display
-     *  the given job status' page.
-     */
+    /** Return the full path, including extension, to the job's status page. */
     String getJobStatusPagePath(HttpServletRequest request, JobStatus jobStatus, String extension);
+    
+    /** Return the full path, including extension, to the job's stream */
+    String getJobStreamPath(HttpServletRequest request, JobStatus jobStatus);
 }

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobData.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobData.java?rev=981925&r1=981924&r2=981925&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobData.java
(original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobData.java
Tue Aug  3 15:22:52 2010
@@ -20,6 +20,7 @@ package org.apache.sling.bgservlets;
 
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.Date;
 
 /** Wraps a JCR Node to store and retrieve information
  * 	about a background Job
@@ -47,4 +48,7 @@ public interface JobData {
 	
 	/** Get a named property, null if non-existent */
 	String getProperty(String name);
+	
+	/** Return this item's creation time */
+	Date getCreationTime();
 }

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=981925&r1=981924&r2=981925&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 Aug  3 15:22:52 2010
@@ -18,14 +18,22 @@
  */
 package org.apache.sling.bgservlets;
 
+import java.util.Date;
+
 /** Provides info about a job */
 public interface JobStatus {
     enum State {
         NEW, QUEUED, REJECTED, RUNNING, SUSPEND_REQUESTED, SUSPENDED, STOP_REQUESTED, STOPPED,
DONE
     }
+    
+    /** Suffix used to build the job's stream path */
+    String STREAM_PATH_SUFFIX = "/stream";
 
     /** Return the job's current state */
     State getState();
+    
+    /** Return the job's creation time */
+    Date getCreationTime();
 
     /**
      * Request a change in the job's state, which might not take effect
@@ -35,4 +43,7 @@ public interface JobStatus {
 
     /** Path of the Resource that describes this job */
     String getPath();
+    
+    /** Full Path of the job's stream, including extension */
+    String getStreamPath();
 }
\ No newline at end of file

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=981925&r1=981924&r2=981925&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 Aug  3 15:22:52 2010
@@ -19,6 +19,7 @@
 package org.apache.sling.bgservlets.impl;
 
 import java.io.IOException;
+import java.util.Date;
 
 import javax.jcr.Session;
 import javax.servlet.http.HttpServletRequest;
@@ -50,7 +51,9 @@ class BackgroundRequestExecutionJob impl
     private final ResourceResolver resourceResolver;
     private final SlingServlet slingServlet;
     private final String path;
-
+    private final String streamPath;
+    private final Date creationTime;
+    
     BackgroundRequestExecutionJob(SlingServlet slingServlet,
             ResourceResolverFactory rrf, JobStorage storage, SlingHttpServletRequest request,
             HttpServletResponse hsr, String[] parametersToRemove)
@@ -80,6 +83,8 @@ class BackgroundRequestExecutionJob impl
             d.setProperty(JobData.PROP_EXTENSION, ext);
         }
         path = d.getPath();
+        creationTime = d.getCreationTime();
+        streamPath = d.getPath() + STREAM_PATH_SUFFIX + (ext == null ? "" : "." + ext);
         stream = new SuspendableOutputStream(d.getOutputStream());
         response = new BackgroundHttpServletResponse(hsr, stream);
     }
@@ -116,4 +121,12 @@ class BackgroundRequestExecutionJob impl
     public void requestStateChange(State s) {
         stream.requestStateChange(s);
     }
+
+    public String getStreamPath() {
+        return streamPath;
+    }
+
+    public Date getCreationTime() {
+        return creationTime;
+    }
 }

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/JobConsoleImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/JobConsoleImpl.java?rev=981925&r1=981924&r2=981925&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/JobConsoleImpl.java
(original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/JobConsoleImpl.java
Tue Aug  3 15:22:52 2010
@@ -120,4 +120,8 @@ public class JobConsoleImpl implements J
         }
         return request.getContextPath() + jobStatus.getPath() + extension;
     }
+    
+    public String getJobStreamPath(HttpServletRequest request, JobStatus jobStatus) {
+        return request.getContextPath() + jobStatus.getStreamPath();
+    }
 }

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=981925&r1=981924&r2=981925&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 Aug  3 15:22:52 2010
@@ -21,6 +21,7 @@ package org.apache.sling.bgservlets.impl
 import java.io.FilterOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Date;
 
 import org.apache.sling.bgservlets.JobStatus;
 
@@ -153,11 +154,28 @@ public class SuspendableOutputStream ext
 
     /**
      * Not implemented
-     *
      * @throws UnsupportedOperationException
      */
     public String getPath() {
         throw new UnsupportedOperationException(
                 "getPath() is not applicable to this class");
     }
+    
+    /**
+     * Not implemented
+     * @throws UnsupportedOperationException
+     */
+    public String getStreamPath() {
+        throw new UnsupportedOperationException(
+                "getStreamPath() is not applicable to this class");
+    }
+
+    /**
+     * Not implemented
+     * @throws UnsupportedOperationException
+     */
+    public Date getCreationTime() {
+        throw new UnsupportedOperationException(
+        "getCreationTime() is not applicable to this class");
+    }
 }

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/servlets/JobInfoServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/servlets/JobInfoServlet.java?rev=981925&r1=981924&r2=981925&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/servlets/JobInfoServlet.java
(original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/servlets/JobInfoServlet.java
Tue Aug  3 15:22:52 2010
@@ -24,6 +24,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import javax.jcr.Node;
+import javax.jcr.RepositoryException;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletResponse;
 
@@ -36,8 +37,9 @@ import org.apache.sling.api.SlingHttpSer
 import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
 import org.apache.sling.bgservlets.BackgroundServletConstants;
+import org.apache.sling.bgservlets.JobConsole;
 import org.apache.sling.bgservlets.JobData;
-import org.apache.sling.bgservlets.JobStorage;
+import org.apache.sling.bgservlets.JobStatus;
 import org.apache.sling.commons.json.JSONException;
 import org.apache.sling.commons.json.io.JSONWriter;
 
@@ -65,7 +67,7 @@ public class JobInfoServlet extends Slin
     }
 
     @Reference
-    private JobStorage jobStorage;
+    private JobConsole jobConsole;
 
     static interface Renderer {
         void render(PrintWriter pw, String streamPath, String streamResource) throws IOException;
@@ -110,25 +112,24 @@ public class JobInfoServlet extends Slin
     protected void doGet(SlingHttpServletRequest request,
             SlingHttpServletResponse response) throws ServletException,
             IOException {
-        final JobData j = jobStorage.getJobData(request.getResource().adaptTo(Node.class));
-        String jobExt = j.getProperty(JobData.PROP_EXTENSION);
-        if(jobExt == null || jobExt.length() == 0) {
-            jobExt = "";
-        } else {
-            jobExt = "." + jobExt;
-        }
-        final String streamResource = request.getResource().getPath() + "/stream" + jobExt;
-        final String streamPath = request.getContextPath() + streamResource;
-        final String ext = request.getRequestPathInfo().getExtension();
-        Renderer r = renderers.get(ext);
-        if(r == null) {
-            r = renderers.get(DEFAULT_EXT);
-        }
-        if(r == null) {
-            response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No JobRenderer available
for extension '" + ext + "'");
+        try {
+            final Node n = request.getResource().adaptTo(Node.class);
+            final JobStatus j = jobConsole.getJobStatus(n.getSession(), n.getPath());
+            final String streamPath =  j.getStreamPath();
+            final String fullStreamPath = request.getContextPath() + streamPath; 
+            final String ext = request.getRequestPathInfo().getExtension();
+            Renderer r = renderers.get(ext);
+            if(r == null) {
+                r = renderers.get(DEFAULT_EXT);
+            }
+            if(r == null) {
+                response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No JobRenderer available
for extension '" + ext + "'");
+            }
+            response.setContentType(request.getResponseContentType());
+            response.setCharacterEncoding(DEFAULT_ENCODING);
+            r.render(response.getWriter(), fullStreamPath, streamPath);
+        } catch(RepositoryException re) {
+            throw new ServletException("RepositoryException in doGet", re);
         }
-        response.setContentType(request.getResponseContentType());
-        response.setCharacterEncoding(DEFAULT_ENCODING);
-        r.render(response.getWriter(), streamPath, streamResource);
     }
 }

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/storage/JobDataImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/storage/JobDataImpl.java?rev=981925&r1=981924&r2=981925&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/storage/JobDataImpl.java
(original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/storage/JobDataImpl.java
Tue Aug  3 15:22:52 2010
@@ -20,6 +20,8 @@ package org.apache.sling.bgservlets.impl
 
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.Calendar;
+import java.util.Date;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
@@ -27,6 +29,7 @@ import javax.jcr.RepositoryException;
 import org.apache.sling.api.SlingConstants;
 import org.apache.sling.bgservlets.BackgroundServletConstants;
 import org.apache.sling.bgservlets.JobData;
+import org.apache.sling.bgservlets.JobStatus;
 import org.apache.sling.bgservlets.impl.nodestream.NodeInputStream;
 import org.apache.sling.bgservlets.impl.nodestream.NodeOutputStream;
 
@@ -34,8 +37,9 @@ class JobDataImpl implements JobData {
 
 	private final Node node;
 	private final String path;
+	private final Calendar creationTime;
 	
-	public static final String STREAM_PATH = "stream";
+	public static final String STREAM_PATH = JobStatus.STREAM_PATH_SUFFIX.substring(1);
 	
     public static final String RT_PROP = SlingConstants.NAMESPACE_PREFIX + ":" + SlingConstants.PROPERTY_RESOURCE_TYPE;
     
@@ -43,6 +47,13 @@ class JobDataImpl implements JobData {
 	JobDataImpl(Node n) throws RepositoryException {
 		node = n;
 		path = node.getPath();
+		if(node.hasProperty(BackgroundServletConstants.CREATION_TIME_PROPERTY)) {
+		    creationTime = node.getProperty(BackgroundServletConstants.CREATION_TIME_PROPERTY).getDate();
+		} else {
+		    // Set fake date if not found
+		    creationTime = Calendar.getInstance();
+		    creationTime.set(1900, 1, 1);
+		}
 	}
 	
 	public InputStream getInputStream() {
@@ -96,4 +107,8 @@ class JobDataImpl implements JobData {
             throw new JobStorageException("RepositoryException in setProperty", re);
         }
     }
+
+    public Date getCreationTime() {
+        return creationTime.getTime();
+    }
 }

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/storage/JobStorageImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/storage/JobStorageImpl.java?rev=981925&r1=981924&r2=981925&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/storage/JobStorageImpl.java
(original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/storage/JobStorageImpl.java
Tue Aug  3 15:22:52 2010
@@ -29,6 +29,7 @@ import javax.jcr.Session;
 
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.bgservlets.BackgroundServletConstants;
 import org.apache.sling.bgservlets.JobData;
 import org.apache.sling.bgservlets.JobStorage;
 import org.apache.sling.bgservlets.impl.DeepNodeCreator;
@@ -74,7 +75,7 @@ public class JobStorageImpl implements J
         }
 	    final Node result = new DeepNodeCreator().deepCreateNode(path, s, JOB_NODETYPE);
 	    result.addMixin(JobData.JOB_DATA_MIXIN);
-	    result.setProperty("jcr:created", Calendar.getInstance());
+	    result.setProperty(BackgroundServletConstants.CREATION_TIME_PROPERTY, Calendar.getInstance());
 	    result.save();
 	    log.debug("Job node {} created", result.getPath());
 	    return result;

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=981925&r1=981924&r2=981925&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 Aug  3 15:22:52 2010
@@ -18,6 +18,8 @@
  */
 package org.apache.sling.bgservlets.impl.storage;
 
+import java.util.Date;
+
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 
@@ -25,6 +27,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.bgservlets.ExecutionEngine;
+import org.apache.sling.bgservlets.JobData;
 import org.apache.sling.bgservlets.JobStatus;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -44,15 +47,32 @@ public class NodeJobStatusFactoryImpl im
     
     private class NodeJobStatus implements JobStatus {
         private final String path;
+        private final String streamPath;
+        private final Date creationTime;
         
         public NodeJobStatus(Node n) throws RepositoryException {
             path = n.getPath();
+            if(n.hasProperty(JobData.PROP_EXTENSION)) {
+                streamPath = path + JobStatus.STREAM_PATH_SUFFIX + "." 
+                    + n.getProperty(JobData.PROP_EXTENSION).getString();
+            } else {
+                streamPath = path + JobStatus.STREAM_PATH_SUFFIX;
+            }
+            creationTime = new JobDataImpl(n).getCreationTime();
         }
     
         public String getPath() {
             return path;
         }
     
+        public String getStreamPath() {
+            return streamPath;
+        }
+        
+        public Date getCreationTime() {
+            return creationTime;
+        }
+
         public State getState() {
             final JobStatus j = getActiveJob();
             if(j == null) {



Mime
View raw message