incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r965490 - in /sling/trunk/contrib/extensions/bgservlets/src: main/java/org/apache/sling/bgservlets/ main/java/org/apache/sling/bgservlets/impl/ main/java/org/apache/sling/bgservlets/impl/webconsole/ test/java/org/apache/sling/bgservlets/impl/
Date Mon, 19 Jul 2010 14:08:39 GMT
Author: bdelacretaz
Date: Mon Jul 19 14:08:38 2010
New Revision: 965490

URL: http://svn.apache.org/viewvc?rev=965490&view=rev
Log:
SLING-550 - reformat using spaces instead of tabs. Finally found the right switch in Eclipse: it's in java/formatter, setting all editors to use spaces is not enough.

Modified:
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/ExecutionEngine.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/Predicate.java
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/Activator.java
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundHttpServletRequest.java
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundHttpServletResponse.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/BackgroundServletStarterFilter.java
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundTestServlet.java
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/ExecutionEngineImpl.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/webconsole/ExecutionEngineConsolePlugin.java
    sling/trunk/contrib/extensions/bgservlets/src/test/java/org/apache/sling/bgservlets/impl/SuspendableOutputStreamTest.java

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/ExecutionEngine.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/ExecutionEngine.java?rev=965490&r1=965489&r2=965490&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/ExecutionEngine.java (original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/ExecutionEngine.java Mon Jul 19 14:08:38 2010
@@ -20,19 +20,23 @@ package org.apache.sling.bgservlets;
 
 import java.util.Iterator;
 
-/** Service that executes Runnables, will later allow
- * 	them to be suspended, resumed, stopped and restarted.
+/**
+ * Service that executes Runnables, will later allow them to be suspended,
+ * resumed, stopped and restarted.
  */
 public interface ExecutionEngine {
-	
-	/** Add a job to the execution queue */
-	void queueForExecution(Runnable job);
-	
-	/** Get JobStatus by path */
-	JobStatus getJobStatus(String path);
-	
-	/** Enumerate JobStatus that match supplied predicate 
-	 * 	@param p if null, returns all known JobStatus.
-	 */
-	Iterator<JobStatus> getMatchingJobStatus(Predicate<JobStatus> p);
+
+    /** Add a job to the execution queue */
+    void queueForExecution(Runnable job);
+
+    /** Get JobStatus by path */
+    JobStatus getJobStatus(String path);
+
+    /**
+     * Enumerate JobStatus that match supplied predicate
+     * 
+     * @param p
+     *            if null, returns all known JobStatus.
+     */
+    Iterator<JobStatus> getMatchingJobStatus(Predicate<JobStatus> p);
 }
\ No newline at end of file

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=965490&r1=965489&r2=965490&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 Mon Jul 19 14:08:38 2010
@@ -20,26 +20,19 @@ package org.apache.sling.bgservlets;
 
 /** Provides info about a job */
 public interface JobStatus {
-	enum State {
-		NEW,
-		QUEUED,
-		REJECTED,
-		RUNNING, 
-		SUSPEND_REQUESTED, 
-		SUSPENDED, 
-		STOP_REQUESTED, 
-		STOPPED, 
-		DONE
-	}
+    enum State {
+        NEW, QUEUED, REJECTED, RUNNING, SUSPEND_REQUESTED, SUSPENDED, STOP_REQUESTED, STOPPED, DONE
+    }
 
-	/** Return the job's current state */
-	State getState();
-	
-	/** Request a change in the job's state, which might not take
-	 * 	effect immediately, or even be ignored.
-	 */
-	void requestStateChange(State s);
-	
-	/** Path of the Resource that describes this job */
-	String getPath();
+    /** Return the job's current state */
+    State getState();
+
+    /**
+     * Request a change in the job's state, which might not take effect
+     * immediately, or even be ignored.
+     */
+    void requestStateChange(State s);
+
+    /** Path of the Resource that describes this job */
+    String getPath();
 }
\ No newline at end of file

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/Predicate.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/Predicate.java?rev=965490&r1=965489&r2=965490&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/Predicate.java (original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/Predicate.java Mon Jul 19 14:08:38 2010
@@ -20,5 +20,5 @@ package org.apache.sling.bgservlets;
 
 /** Simple typed predicate */
 public interface Predicate<T> {
-	boolean isTrue(T subject);
+    boolean isTrue(T subject);
 }

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/Activator.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/Activator.java?rev=965490&r1=965489&r2=965490&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/Activator.java (original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/Activator.java Mon Jul 19 14:08:38 2010
@@ -26,8 +26,8 @@ import org.slf4j.LoggerFactory;
 
 /** Bundle activator */
 public class Activator implements BundleActivator {
-	private final Logger log = LoggerFactory.getLogger(getClass());
-	
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
     /**
      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
      */
@@ -35,7 +35,7 @@ public class Activator implements Bundle
         try {
             ExecutionEngineConsolePlugin.initPlugin(context);
         } catch (Throwable ignore) {
-        	// Happens for example if the webconsole is not installed
+            // Happens for example if the webconsole is not installed
             log.debug("Exception in start()", ignore);
         }
     }

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundHttpServletRequest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundHttpServletRequest.java?rev=965490&r1=965489&r2=965490&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundHttpServletRequest.java (original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundHttpServletRequest.java Mon Jul 19 14:08:38 2010
@@ -36,316 +36,321 @@ import javax.servlet.http.HttpSession;
 
 public class BackgroundHttpServletRequest implements HttpServletRequest {
 
-	private final String contextPath;
-	private final String method;
-	private final String pathInfo;
-	private final String servletPath;
-	private final String queryString;
-	private final String requestURI;
-	private final StringBuffer requestURL;
-	private final String characterEncoding; 
-	private final int contentLength;
-	private final String contentType;
-	private final Locale locale;
-	private final String protocol;
-	private final String remoteAddr;
-	private final String remoteHost;
-	private final int remotePort;
-	private final int serverPort;
-	private final String scheme;
-	private final String remoteUser;
-	private final String serverName;
-	
-	private final Map<String, Object> attributes;
-	private final Map<String, ?> parameters;
-	
-	static class IteratorEnumeration<T> implements Enumeration<T> {
-		private final Iterator<T> it;
-		IteratorEnumeration(Iterator<T> it) {
-			this.it = it;
-		}
-		public boolean hasMoreElements() {
-			return it.hasNext();
-		}
-		public T nextElement() {
-			return it.next();
-		}
-	}
-	
-	/** We throw this for any method for which we do not have data that's
-	 * 	safe to use outside of the container's request/response cycle.
-	 * 	Start by throwing this everywhere and implement methods as needed,
-	 * 	if their data is safe to use.
-	 */
-	@SuppressWarnings("serial")
-	class UnsupportedBackgroundOperationException extends UnsupportedOperationException {
-		UnsupportedBackgroundOperationException() {
-			super("This operation is not supported for background requests");
-		}
-	}
-	
-	@SuppressWarnings("unchecked")
-	BackgroundHttpServletRequest(HttpServletRequest r,String [] parametersToRemove) {
-		
-		// Store objects which are safe to use outside
-		// of the container's request/response cycle - the
-		// goal is to release r once this request starts
-		// executing in the background
-		contextPath = r.getContextPath();
-		method = r.getMethod();
-		pathInfo = r.getPathInfo();
-		servletPath = r.getServletPath();
-		queryString = r.getQueryString();
-		requestURI = r.getRequestURI();
-		requestURL = r.getRequestURL();
-		characterEncoding = r.getCharacterEncoding();
-		contentLength = r.getContentLength();
-		contentType = r.getContentType();
-		locale = r.getLocale();
-		protocol = r.getProtocol();
-		remoteAddr = r.getRemoteAddr();
-		remoteHost = r.getRemoteHost();
-		remotePort = r.getRemotePort();
-		serverPort = r.getServerPort();
-		scheme = r.getScheme();
-		remoteUser = r.getRemoteUser();
-		serverName = r.getServerName();
-
-		attributes = new HashMap<String, Object>();
-		/* Don't copy attributes, we consider this to be a "fresh" request
-		final Enumeration<?> e = r.getAttributeNames();
-		while(e.hasMoreElements()) {
-			final String key = (String)e.nextElement();
-			attributes.put(key, r.getAttribute(key));
-		}
-		*/
-		
-		parameters = new HashMap<String, String>();
-		parameters.putAll(r.getParameterMap());
-		for(String key : parametersToRemove) {
-			parameters.remove(key);
-		}
-	}
-	
-	public String getAuthType() {
-		return null;
-	}
-
-	public String getContextPath() {
-		return contextPath;
-	}
-
-	public Cookie[] getCookies() {
-		return null;
-	}
-
-	public long getDateHeader(String arg0) {
-		return 0;
-	}
-
-	public String getHeader(String arg0) {
-		return null;
-	}
-
-	public Enumeration<?> getHeaderNames() {
-		return null;
-	}
-
-	public Enumeration<?> getHeaders(String name) {
-		return null;
-	}
-
-	public int getIntHeader(String name) {
-		return 0;
-	}
-
-	public String getMethod() {
-		return method;
-	}
-
-	public String getPathInfo() {
-		return pathInfo;
-	}
-
-	public String getPathTranslated() {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public String getQueryString() {
-		return queryString;
-	}
-
-	public String getRemoteUser() {
-		return remoteUser;
-	}
-
-	public String getRequestedSessionId() {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public String getRequestURI() {
-		return requestURI;
-	}
-
-	public StringBuffer getRequestURL() {
-		return requestURL;
-	}
-
-	public String getServletPath() {
-		return servletPath;
-	}
-
-	public HttpSession getSession() {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public HttpSession getSession(boolean arg0) {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public Principal getUserPrincipal() {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public boolean isRequestedSessionIdFromCookie() {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public boolean isRequestedSessionIdFromUrl() {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public boolean isRequestedSessionIdFromURL() {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public boolean isRequestedSessionIdValid() {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public boolean isUserInRole(String arg0) {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public Object getAttribute(String name) {
-		return attributes.get(name);
-	}
-
-	public Enumeration<?> getAttributeNames() {
-		return new IteratorEnumeration<String>(attributes.keySet().iterator());
-	}
-
-	public String getCharacterEncoding() {
-		return characterEncoding;
-	}
-
-	public int getContentLength() {
-		return contentLength;
-	}
-
-	public String getContentType() {
-		return contentType;
-	}
-
-	public ServletInputStream getInputStream() throws IOException {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public String getLocalAddr() {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public Locale getLocale() {
-		return locale;
-	}
-
-	public Enumeration<?> getLocales() {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public String getLocalName() {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public int getLocalPort() {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public String getParameter(String name) {
-		final Object obj = parameters.get(name);
-		if(obj instanceof String[]) {
-			return ((String[])obj)[0];
-		}
-		return (String)obj;
-	}
-
-	public Map<?,?> getParameterMap() {
-		return parameters;
-	}
-
-	public Enumeration<?> getParameterNames() {
-		return new IteratorEnumeration<String>(parameters.keySet().iterator());
-	}
-
-	public String[] getParameterValues(String key) {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public String getProtocol() {
-		return protocol;
-	}
-
-	public BufferedReader getReader() throws IOException {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public String getRealPath(String arg0) {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public String getRemoteAddr() {
-		return remoteAddr;
-	}
-
-	public String getRemoteHost() {
-		return remoteHost;
-	}
-
-	public int getRemotePort() {
-		return remotePort;
-	}
-
-	public RequestDispatcher getRequestDispatcher(String arg0) {
-		throw new UnsupportedBackgroundOperationException();
-	}
-
-	public String getScheme() {
-		return scheme;
-	}
-
-	public String getServerName() {
-		return serverName;
-	}
-
-	public int getServerPort() {
-		return serverPort;
-	}
-
-	public boolean isSecure() {
-		return false;
-	}
-
-	public void removeAttribute(String name) {
-		attributes.remove(name);
-	}
-
-	public void setAttribute(String key, Object value) {
-		attributes.put(key, value);
-	}
-
-	public void setCharacterEncoding(String arg0)
-			throws UnsupportedEncodingException {
-		throw new UnsupportedBackgroundOperationException();
-		
-	}
+    private final String contextPath;
+    private final String method;
+    private final String pathInfo;
+    private final String servletPath;
+    private final String queryString;
+    private final String requestURI;
+    private final StringBuffer requestURL;
+    private final String characterEncoding;
+    private final int contentLength;
+    private final String contentType;
+    private final Locale locale;
+    private final String protocol;
+    private final String remoteAddr;
+    private final String remoteHost;
+    private final int remotePort;
+    private final int serverPort;
+    private final String scheme;
+    private final String remoteUser;
+    private final String serverName;
+
+    private final Map<String, Object> attributes;
+    private final Map<String, ?> parameters;
+
+    static class IteratorEnumeration<T> implements Enumeration<T> {
+        private final Iterator<T> it;
+
+        IteratorEnumeration(Iterator<T> it) {
+            this.it = it;
+        }
+
+        public boolean hasMoreElements() {
+            return it.hasNext();
+        }
+
+        public T nextElement() {
+            return it.next();
+        }
+    }
+
+    /**
+     * We throw this for any method for which we do not have data that's safe to
+     * use outside of the container's request/response cycle. Start by throwing
+     * this everywhere and implement methods as needed, if their data is safe to
+     * use.
+     */
+    @SuppressWarnings("serial")
+    class UnsupportedBackgroundOperationException extends
+            UnsupportedOperationException {
+        UnsupportedBackgroundOperationException() {
+            super("This operation is not supported for background requests");
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    BackgroundHttpServletRequest(HttpServletRequest r,
+            String[] parametersToRemove) {
+
+        // Store objects which are safe to use outside
+        // of the container's request/response cycle - the
+        // goal is to release r once this request starts
+        // executing in the background
+        contextPath = r.getContextPath();
+        method = r.getMethod();
+        pathInfo = r.getPathInfo();
+        servletPath = r.getServletPath();
+        queryString = r.getQueryString();
+        requestURI = r.getRequestURI();
+        requestURL = r.getRequestURL();
+        characterEncoding = r.getCharacterEncoding();
+        contentLength = r.getContentLength();
+        contentType = r.getContentType();
+        locale = r.getLocale();
+        protocol = r.getProtocol();
+        remoteAddr = r.getRemoteAddr();
+        remoteHost = r.getRemoteHost();
+        remotePort = r.getRemotePort();
+        serverPort = r.getServerPort();
+        scheme = r.getScheme();
+        remoteUser = r.getRemoteUser();
+        serverName = r.getServerName();
+
+        attributes = new HashMap<String, Object>();
+        /*
+         * Don't copy attributes, we consider this to be a "fresh" request final
+         * Enumeration<?> e = r.getAttributeNames(); while(e.hasMoreElements())
+         * { final String key = (String)e.nextElement(); attributes.put(key,
+         * r.getAttribute(key)); }
+         */
+
+        parameters = new HashMap<String, String>();
+        parameters.putAll(r.getParameterMap());
+        for (String key : parametersToRemove) {
+            parameters.remove(key);
+        }
+    }
+
+    public String getAuthType() {
+        return null;
+    }
+
+    public String getContextPath() {
+        return contextPath;
+    }
+
+    public Cookie[] getCookies() {
+        return null;
+    }
+
+    public long getDateHeader(String arg0) {
+        return 0;
+    }
+
+    public String getHeader(String arg0) {
+        return null;
+    }
+
+    public Enumeration<?> getHeaderNames() {
+        return null;
+    }
+
+    public Enumeration<?> getHeaders(String name) {
+        return null;
+    }
+
+    public int getIntHeader(String name) {
+        return 0;
+    }
+
+    public String getMethod() {
+        return method;
+    }
+
+    public String getPathInfo() {
+        return pathInfo;
+    }
+
+    public String getPathTranslated() {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public String getQueryString() {
+        return queryString;
+    }
+
+    public String getRemoteUser() {
+        return remoteUser;
+    }
+
+    public String getRequestedSessionId() {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public String getRequestURI() {
+        return requestURI;
+    }
+
+    public StringBuffer getRequestURL() {
+        return requestURL;
+    }
+
+    public String getServletPath() {
+        return servletPath;
+    }
+
+    public HttpSession getSession() {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public HttpSession getSession(boolean arg0) {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public Principal getUserPrincipal() {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public boolean isRequestedSessionIdFromCookie() {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public boolean isRequestedSessionIdFromUrl() {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public boolean isRequestedSessionIdFromURL() {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public boolean isRequestedSessionIdValid() {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public boolean isUserInRole(String arg0) {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public Object getAttribute(String name) {
+        return attributes.get(name);
+    }
+
+    public Enumeration<?> getAttributeNames() {
+        return new IteratorEnumeration<String>(attributes.keySet().iterator());
+    }
+
+    public String getCharacterEncoding() {
+        return characterEncoding;
+    }
+
+    public int getContentLength() {
+        return contentLength;
+    }
+
+    public String getContentType() {
+        return contentType;
+    }
+
+    public ServletInputStream getInputStream() throws IOException {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public String getLocalAddr() {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public Locale getLocale() {
+        return locale;
+    }
+
+    public Enumeration<?> getLocales() {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public String getLocalName() {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public int getLocalPort() {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public String getParameter(String name) {
+        final Object obj = parameters.get(name);
+        if (obj instanceof String[]) {
+            return ((String[]) obj)[0];
+        }
+        return (String) obj;
+    }
+
+    public Map<?, ?> getParameterMap() {
+        return parameters;
+    }
+
+    public Enumeration<?> getParameterNames() {
+        return new IteratorEnumeration<String>(parameters.keySet().iterator());
+    }
+
+    public String[] getParameterValues(String key) {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public String getProtocol() {
+        return protocol;
+    }
+
+    public BufferedReader getReader() throws IOException {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public String getRealPath(String arg0) {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public String getRemoteAddr() {
+        return remoteAddr;
+    }
+
+    public String getRemoteHost() {
+        return remoteHost;
+    }
+
+    public int getRemotePort() {
+        return remotePort;
+    }
+
+    public RequestDispatcher getRequestDispatcher(String arg0) {
+        throw new UnsupportedBackgroundOperationException();
+    }
+
+    public String getScheme() {
+        return scheme;
+    }
+
+    public String getServerName() {
+        return serverName;
+    }
+
+    public int getServerPort() {
+        return serverPort;
+    }
+
+    public boolean isSecure() {
+        return false;
+    }
+
+    public void removeAttribute(String name) {
+        attributes.remove(name);
+    }
+
+    public void setAttribute(String key, Object value) {
+        attributes.put(key, value);
+    }
+
+    public void setCharacterEncoding(String arg0)
+            throws UnsupportedEncodingException {
+        throw new UnsupportedBackgroundOperationException();
+
+    }
 }

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundHttpServletResponse.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundHttpServletResponse.java?rev=965490&r1=965489&r2=965490&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundHttpServletResponse.java (original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundHttpServletResponse.java Mon Jul 19 14:08:38 2010
@@ -33,165 +33,166 @@ import org.apache.sling.api.SlingHttpSer
 /** Minimal HttpServletResponse for background processing */
 class BackgroundHttpServletResponse implements SlingHttpServletResponse {
 
-	private final ServletOutputStream stream;
-	private final PrintWriter writer;
-	private final SlingHttpServletResponse wrappedResponse;
-	
-	static class ServletOutputStreamWrapper extends ServletOutputStream {
-
-		private final OutputStream os;
-		
-		ServletOutputStreamWrapper(OutputStream os) {
-			this.os = os;
-		}
-		
-		@Override
-		public void write(int b) throws IOException {
-			os.write(b);
-		}
-
-		@Override
-		public void close() throws IOException {
-			os.close();
-		}
-
-		@Override
-		public void flush() throws IOException {
-			os.flush();
-		}
-		
-	}
-	
-	BackgroundHttpServletResponse(HttpServletResponse hsr, OutputStream os) throws IOException {
-		stream = new ServletOutputStreamWrapper(os);
-		writer = new PrintWriter(new OutputStreamWriter(stream));
-		wrappedResponse = (hsr instanceof SlingHttpServletResponse ? (SlingHttpServletResponse)hsr : null);
-	}
-	
-	void cleanup() throws IOException {
-		stream.flush();
-		stream.close();
-	}
-
-
-	public ServletOutputStream getOutputStream() throws IOException {
-		return stream;
-	}
-
-	public PrintWriter getWriter() throws IOException {
-		return writer;
-	}
-
-	public void addCookie(Cookie arg0) {
-	}
-
-	public void addDateHeader(String arg0, long arg1) {
-	}
-
-	public void addHeader(String arg0, String arg1) {
-	}
-
-	public void addIntHeader(String arg0, int arg1) {
-	}
-
-	public boolean containsHeader(String arg0) {
-		return false;
-	}
-
-	public String encodeRedirectUrl(String arg0) {
-		return null;
-	}
-
-	public String encodeRedirectURL(String arg0) {
-		return null;
-	}
-
-	public String encodeUrl(String arg0) {
-		return null;
-	}
-
-	public String encodeURL(String arg0) {
-		return null;
-	}
-
-	public void sendError(int arg0, String arg1) throws IOException {
-		// TODO
-	}
-
-	public void sendError(int arg0) throws IOException {
-		// TODO
-	}
-
-	public void sendRedirect(String arg0) throws IOException {
-		// TODO
-	}
-
-	public void setDateHeader(String arg0, long arg1) {
-	}
-
-	public void setHeader(String arg0, String arg1) {
-	}
-
-	public void setIntHeader(String arg0, int arg1) {
-	}
-
-	public void setStatus(int arg0, String arg1) {
-		// TODO
-	}
-
-	public void setStatus(int arg0) {
-		// TODO
-	}
-
-	public void flushBuffer() throws IOException {
-		stream.flush();
-	}
-
-	public int getBufferSize() {
-		return 0;
-	}
-
-	public String getCharacterEncoding() {
-		return null;
-	}
-
-	public String getContentType() {
-		return null;
-	}
-
-	public Locale getLocale() {
-		return null;
-	}
-
-	public boolean isCommitted() {
-		return false;
-	}
-
-	public void reset() {
-	}
-
-	public void resetBuffer() {
-	}
-
-	public void setBufferSize(int arg0) {
-	}
-
-	public void setCharacterEncoding(String arg0) {
-	}
-
-	public void setContentLength(int arg0) {
-	}
-
-	public void setContentType(String arg0) {
-	}
-
-	public void setLocale(Locale arg0) {
-	}
-
-	public <AdapterType> AdapterType adaptTo(Class<AdapterType> t) {
-		if(wrappedResponse != null) {
-			return wrappedResponse.adaptTo(t);
-		}
-		return null;
-	}
+    private final ServletOutputStream stream;
+    private final PrintWriter writer;
+    private final SlingHttpServletResponse wrappedResponse;
+
+    static class ServletOutputStreamWrapper extends ServletOutputStream {
+
+        private final OutputStream os;
+
+        ServletOutputStreamWrapper(OutputStream os) {
+            this.os = os;
+        }
+
+        @Override
+        public void write(int b) throws IOException {
+            os.write(b);
+        }
+
+        @Override
+        public void close() throws IOException {
+            os.close();
+        }
+
+        @Override
+        public void flush() throws IOException {
+            os.flush();
+        }
+
+    }
+
+    BackgroundHttpServletResponse(HttpServletResponse hsr, OutputStream os)
+            throws IOException {
+        stream = new ServletOutputStreamWrapper(os);
+        writer = new PrintWriter(new OutputStreamWriter(stream));
+        wrappedResponse = (hsr instanceof SlingHttpServletResponse ? (SlingHttpServletResponse) hsr
+                : null);
+    }
+
+    void cleanup() throws IOException {
+        stream.flush();
+        stream.close();
+    }
+
+    public ServletOutputStream getOutputStream() throws IOException {
+        return stream;
+    }
+
+    public PrintWriter getWriter() throws IOException {
+        return writer;
+    }
+
+    public void addCookie(Cookie arg0) {
+    }
+
+    public void addDateHeader(String arg0, long arg1) {
+    }
+
+    public void addHeader(String arg0, String arg1) {
+    }
+
+    public void addIntHeader(String arg0, int arg1) {
+    }
+
+    public boolean containsHeader(String arg0) {
+        return false;
+    }
+
+    public String encodeRedirectUrl(String arg0) {
+        return null;
+    }
+
+    public String encodeRedirectURL(String arg0) {
+        return null;
+    }
+
+    public String encodeUrl(String arg0) {
+        return null;
+    }
+
+    public String encodeURL(String arg0) {
+        return null;
+    }
+
+    public void sendError(int arg0, String arg1) throws IOException {
+        // TODO
+    }
+
+    public void sendError(int arg0) throws IOException {
+        // TODO
+    }
+
+    public void sendRedirect(String arg0) throws IOException {
+        // TODO
+    }
+
+    public void setDateHeader(String arg0, long arg1) {
+    }
+
+    public void setHeader(String arg0, String arg1) {
+    }
+
+    public void setIntHeader(String arg0, int arg1) {
+    }
+
+    public void setStatus(int arg0, String arg1) {
+        // TODO
+    }
+
+    public void setStatus(int arg0) {
+        // TODO
+    }
+
+    public void flushBuffer() throws IOException {
+        stream.flush();
+    }
+
+    public int getBufferSize() {
+        return 0;
+    }
+
+    public String getCharacterEncoding() {
+        return null;
+    }
+
+    public String getContentType() {
+        return null;
+    }
+
+    public Locale getLocale() {
+        return null;
+    }
+
+    public boolean isCommitted() {
+        return false;
+    }
+
+    public void reset() {
+    }
+
+    public void resetBuffer() {
+    }
+
+    public void setBufferSize(int arg0) {
+    }
+
+    public void setCharacterEncoding(String arg0) {
+    }
+
+    public void setContentLength(int arg0) {
+    }
+
+    public void setContentType(String arg0) {
+    }
+
+    public void setLocale(Locale arg0) {
+    }
+
+    public <AdapterType> AdapterType adaptTo(Class<AdapterType> t) {
+        if (wrappedResponse != null) {
+            return wrappedResponse.adaptTo(t);
+        }
+        return null;
+    }
 }
\ 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=965490&r1=965489&r2=965490&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 Mon Jul 19 14:08:38 2010
@@ -34,70 +34,80 @@ import org.apache.sling.engine.SlingServ
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/** Runnable that executes a FilterChain, using 
- * 	a ServletResponseWrapper to capture the output.
+/**
+ * Runnable that executes a FilterChain, using a ServletResponseWrapper to
+ * capture the output.
  */
 class BackgroundRequestExecutionJob implements Runnable, JobStatus {
-	private final Logger log = LoggerFactory.getLogger(getClass());
-	private final HttpServletRequest request;
-	private final BackgroundHttpServletResponse response;
-	private final SuspendableOutputStream stream;
-	private final ResourceResolver resourceResolver;
-	private final SlingServlet slingServlet;
-	private final String path;
-	
-	BackgroundRequestExecutionJob(SlingServlet slingServlet, ResourceResolverFactory rrf, HttpServletRequest request, 
-			HttpServletResponse hsr, String [] parametersToRemove) throws IOException, LoginException {
-		this.request = new BackgroundHttpServletRequest(request, parametersToRemove);
-		this.slingServlet = slingServlet;
-		
-		// TODO we might 
-		// In a normal request the ResourceResolver is added to the request attributes
-		// by the authentication service, need to do the same here as we can't reuse the
-		// original one which is closed once main request is done
-		final AuthenticationInfo aa = (AuthenticationInfo)request.getAttribute(AuthenticationInfo.class.getName());
-		if(aa == null) {
-			throw new IllegalArgumentException("Missing AuthenticationInfo attribute");
-		}
-		resourceResolver = rrf.getResourceResolver(aa);
-		
-		// TODO write output to the Sling repository. For now: just a temp file
-		final File output = File.createTempFile(getClass().getSimpleName(), ".data");
-		output.deleteOnExit();
-		path = output.getAbsolutePath();
-		stream = new SuspendableOutputStream(new FileOutputStream(output));
-		response  = new BackgroundHttpServletResponse(hsr, stream);
-	}
-	
-	public String toString() {
-		return getClass().getSimpleName() + ", state=" + getState() + ", path=" + path;
-	}
-	
-	public void run() {
-		try {
-			slingServlet.processRequest(request, response, resourceResolver);
-		} catch(Exception e) {
-			// TODO report errors in the background job's output
-			log.error("Exception in background request processing", e);
-		} finally {
-			try {
-				response.cleanup();
-			} catch(IOException ioe) {
-				// TODO report errors in the background job's output
-				log.error("ServletResponseWrapper cleanup failed", ioe);
-			}
-		}
-	}
-
-	public String getPath() {
-		return path;
-	}
-
-	public State getState() {
-		return stream.getState();
-	}
-
-	public void requestStateChange(State s) {
-		stream.requestStateChange(s);
-	}
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    private final HttpServletRequest request;
+    private final BackgroundHttpServletResponse response;
+    private final SuspendableOutputStream stream;
+    private final ResourceResolver resourceResolver;
+    private final SlingServlet slingServlet;
+    private final String path;
+
+    BackgroundRequestExecutionJob(SlingServlet slingServlet,
+            ResourceResolverFactory rrf, HttpServletRequest request,
+            HttpServletResponse hsr, String[] parametersToRemove)
+            throws IOException, LoginException {
+        this.request = new BackgroundHttpServletRequest(request,
+                parametersToRemove);
+        this.slingServlet = slingServlet;
+
+        // TODO we might
+        // In a normal request the ResourceResolver is added to the request
+        // attributes
+        // by the authentication service, need to do the same here as we can't
+        // reuse the
+        // original one which is closed once main request is done
+        final AuthenticationInfo aa = (AuthenticationInfo) request
+                .getAttribute(AuthenticationInfo.class.getName());
+        if (aa == null) {
+            throw new IllegalArgumentException(
+                    "Missing AuthenticationInfo attribute");
+        }
+        resourceResolver = rrf.getResourceResolver(aa);
+
+        // TODO write output to the Sling repository. For now: just a temp file
+        final File output = File.createTempFile(getClass().getSimpleName(),
+                ".data");
+        output.deleteOnExit();
+        path = output.getAbsolutePath();
+        stream = new SuspendableOutputStream(new FileOutputStream(output));
+        response = new BackgroundHttpServletResponse(hsr, stream);
+    }
+
+    public String toString() {
+        return getClass().getSimpleName() + ", state=" + getState() + ", path="
+                + path;
+    }
+
+    public void run() {
+        try {
+            slingServlet.processRequest(request, response, resourceResolver);
+        } catch (Exception e) {
+            // TODO report errors in the background job's output
+            log.error("Exception in background request processing", e);
+        } finally {
+            try {
+                response.cleanup();
+            } catch (IOException ioe) {
+                // TODO report errors in the background job's output
+                log.error("ServletResponseWrapper cleanup failed", ioe);
+            }
+        }
+    }
+
+    public String getPath() {
+        return path;
+    }
+
+    public State getState() {
+        return stream.getState();
+    }
+
+    public void requestStateChange(State s) {
+        stream.requestStateChange(s);
+    }
 }

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundServletStarterFilter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundServletStarterFilter.java?rev=965490&r1=965489&r2=965490&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundServletStarterFilter.java (original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundServletStarterFilter.java Mon Jul 19 14:08:38 2010
@@ -41,73 +41,82 @@ import org.apache.sling.engine.SlingServ
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/** Filter that runs the current request in the background
- * 	if specific request parameters are set.
- *  TODO: define the position of this filter in the chain,
- *  and how do we enforce it?
+/**
+ * Filter that runs the current request in the background if specific request
+ * parameters are set. TODO: define the position of this filter in the chain,
+ * and how do we enforce it?
  */
 @Component
 @Service
-@Properties({
-	@Property(name="filter.scope", value="request"),
-	@Property(name="filter.order", intValue=java.lang.Integer.MIN_VALUE)
-})
-public class BackgroundServletStarterFilter implements Filter{
-
-	private final Logger log = LoggerFactory.getLogger(getClass());
-	
-	@Reference
-	private ExecutionEngine executionEngine;
-	
-	@Reference
-	private SlingServlet slingServlet;
-	
-	@Reference
-	private ResourceResolverFactory resourceResolverFactory;
-	
-	/** 
-	 * Request runs in the background if this request parameter is present 
-	 * TODO should be configurable, and maybe use other decision methods */
-	public static final String BG_PARAM = "sling:bg";
-	private static final String [] PARAM_TO_REMOVE = { BG_PARAM };
-	
-	public void doFilter(final ServletRequest sreq, final ServletResponse sresp, 
-			final FilterChain chain) throws IOException, ServletException {
-		if(!(sreq instanceof HttpServletRequest)) {
-			throw new ServletException("request is not an HttpServletRequest: " + sresp.getClass().getName());
-		}
-		if(!(sresp instanceof HttpServletResponse)) {
-			throw new ServletException("response is not an HttpServletResponse: " + sresp.getClass().getName());
-		}
-		final HttpServletRequest request = (HttpServletRequest)sreq;
-		final SlingHttpServletRequest slingRequest = 
-			(request instanceof SlingHttpServletRequest ? (SlingHttpServletRequest)request : null); 
-		final HttpServletResponse response = (HttpServletResponse)sresp; 
-		final String bgParam = sreq.getParameter(BG_PARAM); 
-		if(Boolean.valueOf(bgParam)) {
-			try {
-				final BackgroundRequestExecutionJob job = new BackgroundRequestExecutionJob(
-						slingServlet, resourceResolverFactory, request, response, PARAM_TO_REMOVE);
-				log.debug("{} parameter true, running request in the background ({})", BG_PARAM, job);
-				if(slingRequest != null) {
-					slingRequest.getRequestProgressTracker().log(
-							BG_PARAM + " parameter true, running request in background (" + job + ")");
-				}
-				executionEngine.queueForExecution(job);
-				
-				// TODO not really an error, should send a nicer message
-				response.sendError(HttpServletResponse.SC_ACCEPTED, "Running request in the background using " + job);
-			} catch (org.apache.sling.api.resource.LoginException e) {
-				throw new ServletException("LoginException in doFilter", e);
-			}
-		} else {
-			chain.doFilter(sreq, sresp);
-		}
-	}
+@Properties( {
+        @Property(name = "filter.scope", value = "request"),
+        @Property(name = "filter.order", intValue = java.lang.Integer.MIN_VALUE) })
+public class BackgroundServletStarterFilter implements Filter {
 
-	public void destroy() {
-	}
+    private final Logger log = LoggerFactory.getLogger(getClass());
 
-	public void init(FilterConfig cfg) throws ServletException {
-	}
+    @Reference
+    private ExecutionEngine executionEngine;
+
+    @Reference
+    private SlingServlet slingServlet;
+
+    @Reference
+    private ResourceResolverFactory resourceResolverFactory;
+
+    /**
+     * Request runs in the background if this request parameter is present TODO
+     * should be configurable, and maybe use other decision methods
+     */
+    public static final String BG_PARAM = "sling:bg";
+    private static final String[] PARAM_TO_REMOVE = { BG_PARAM };
+
+    public void doFilter(final ServletRequest sreq,
+            final ServletResponse sresp, final FilterChain chain)
+            throws IOException, ServletException {
+        if (!(sreq instanceof HttpServletRequest)) {
+            throw new ServletException("request is not an HttpServletRequest: "
+                    + sresp.getClass().getName());
+        }
+        if (!(sresp instanceof HttpServletResponse)) {
+            throw new ServletException(
+                    "response is not an HttpServletResponse: "
+                            + sresp.getClass().getName());
+        }
+        final HttpServletRequest request = (HttpServletRequest) sreq;
+        final SlingHttpServletRequest slingRequest = (request instanceof SlingHttpServletRequest ? (SlingHttpServletRequest) request
+                : null);
+        final HttpServletResponse response = (HttpServletResponse) sresp;
+        final String bgParam = sreq.getParameter(BG_PARAM);
+        if (Boolean.valueOf(bgParam)) {
+            try {
+                final BackgroundRequestExecutionJob job = new BackgroundRequestExecutionJob(
+                        slingServlet, resourceResolverFactory, request,
+                        response, PARAM_TO_REMOVE);
+                log.debug("{} parameter true, running request in the background ({})",
+                        BG_PARAM, job);
+                if (slingRequest != null) {
+                    slingRequest.getRequestProgressTracker().log(
+                            BG_PARAM
+                            + " parameter true, running request in background ("
+                            + job + ")");
+                }
+                executionEngine.queueForExecution(job);
+
+                // TODO not really an error, should send a nicer message
+                response.sendError(HttpServletResponse.SC_ACCEPTED,
+                        "Running request in the background using " + job);
+            } catch (org.apache.sling.api.resource.LoginException e) {
+                throw new ServletException("LoginException in doFilter", e);
+            }
+        } else {
+            chain.doFilter(sreq, sresp);
+        }
+    }
+
+    public void destroy() {
+    }
+
+    public void init(FilterConfig cfg) throws ServletException {
+    }
 }
\ No newline at end of file

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundTestServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundTestServlet.java?rev=965490&r1=965489&r2=965490&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundTestServlet.java (original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/BackgroundTestServlet.java Mon Jul 19 14:08:38 2010
@@ -32,55 +32,56 @@ import org.apache.sling.api.servlets.Sli
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/** Servlet used for interactive testing of the background
- * 	servlets engine.
- * 	TODO remove once we have better tests.
+/**
+ * Servlet used for interactive testing of the background servlets engine. TODO
+ * remove once we have better tests.
  */
 @Component
 @Service
 @SuppressWarnings("serial")
-@Property(name="sling.servlet.paths", value="/system/bgservlets/test")
+@Property(name = "sling.servlet.paths", value = "/system/bgservlets/test")
 public class BackgroundTestServlet extends SlingSafeMethodsServlet {
 
-	private final Logger log = LoggerFactory.getLogger(getClass());
-	
-	@Override
-	protected void doGet(SlingHttpServletRequest request,
-			SlingHttpServletResponse response) throws ServletException,
-			IOException {
-		response.setContentType("text/plain");
-		final PrintWriter w = response.getWriter();
-		
-		final int cycles = getIntParam(request, "cycles", 10);
-		final int interval = getIntParam(request, "interval", 1);
-		final int flushEvery = getIntParam(request, "flushEvery", 2);
-		
-		try {
-			for(int i=1; i <= cycles; i++) {
-				if(i % flushEvery == 0) {
-					w.println("Flushing output");
-					w.flush();
-				}
-				w.printf("Cycle %d of %d\n", i, cycles);
-				try {
-					Thread.sleep(interval * 1000);
-				} catch(InterruptedException iex) {
-					throw new ServletException("InterruptedException", iex);
-				}
-			}
-			w.println("All done.");
-			w.flush();
-		} catch(Throwable t) {
-			log.info("Exception in doGet", t);
-		}
-	}
-	
-	private int getIntParam(SlingHttpServletRequest request, String name, int defaultValue) {
-		int result = defaultValue;
-		final String str = request.getParameter(name);
-		if(str != null) {
-			result = Integer.parseInt(str);
-		}
-		return result;
-	}
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Override
+    protected void doGet(SlingHttpServletRequest request,
+            SlingHttpServletResponse response) throws ServletException,
+            IOException {
+        response.setContentType("text/plain");
+        final PrintWriter w = response.getWriter();
+
+        final int cycles = getIntParam(request, "cycles", 10);
+        final int interval = getIntParam(request, "interval", 1);
+        final int flushEvery = getIntParam(request, "flushEvery", 2);
+
+        try {
+            for (int i = 1; i <= cycles; i++) {
+                if (i % flushEvery == 0) {
+                    w.println("Flushing output");
+                    w.flush();
+                }
+                w.printf("Cycle %d of %d\n", i, cycles);
+                try {
+                    Thread.sleep(interval * 1000);
+                } catch (InterruptedException iex) {
+                    throw new ServletException("InterruptedException", iex);
+                }
+            }
+            w.println("All done.");
+            w.flush();
+        } catch (Throwable t) {
+            log.info("Exception in doGet", t);
+        }
+    }
+
+    private int getIntParam(SlingHttpServletRequest request, String name,
+            int defaultValue) {
+        int result = defaultValue;
+        final String str = request.getParameter(name);
+        if (str != null) {
+            result = Integer.parseInt(str);
+        }
+        return result;
+    }
 }

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/ExecutionEngineImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/ExecutionEngineImpl.java?rev=965490&r1=965489&r2=965490&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/ExecutionEngineImpl.java (original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/ExecutionEngineImpl.java Mon Jul 19 14:08:38 2010
@@ -38,102 +38,107 @@ import org.osgi.service.component.Compon
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/** Simple ExecutionEngine
- * 	TODO should use Sling's thread pool, and check synergies
- * 	with scheduler services */
+/**
+ * Simple ExecutionEngine TODO should use Sling's thread pool, and check
+ * synergies with scheduler services
+ */
 @Component
 @Service
 public class ExecutionEngineImpl implements ExecutionEngine {
 
-	private final Logger log = LoggerFactory.getLogger(getClass());
-	private Executor executor;
-	private final Map<String, JobStatus> jobs = new HashMap<String, JobStatus>();
-	
-	private class RunnableWrapper implements Runnable {
-		private final Runnable inputJob;
-		private final JobStatus jobStatus;
-		
-		RunnableWrapper(Runnable inputJob) {
-			this.inputJob = inputJob;
-			jobStatus = (inputJob instanceof JobStatus ? (JobStatus)inputJob : null);
-		}
-		public void run() {
-			if(jobStatus != null) {
-				jobStatus.requestStateChange(JobStatus.State.RUNNING);
-			}
-			log.info("Starting job {}", inputJob);
-			try {
-				// TODO save Exceptions in job?
-				inputJob.run();
-			} finally {
-				if(jobStatus != null) {
-					jobStatus.requestStateChange(JobStatus.State.DONE);
-				}
-			}
-			log.info("Done running job {}", inputJob);
-		}
-		
-		JobStatus getJobStatus() {
-			return jobStatus;
-		}
-	};
-	
-	@SuppressWarnings("serial")
-	public static class QueueFullException extends SlingException {
-		QueueFullException(Runnable r) {
-			super("Execution queue is full, cannot execute " + r);
-		}
-	}
-	
-	public void activate(ComponentContext context) {
-		// TODO configurable!
-		final int corePoolSize = 2;
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    private Executor executor;
+    private final Map<String, JobStatus> jobs = new HashMap<String, JobStatus>();
+
+    private class RunnableWrapper implements Runnable {
+        private final Runnable inputJob;
+        private final JobStatus jobStatus;
+
+        RunnableWrapper(Runnable inputJob) {
+            this.inputJob = inputJob;
+            jobStatus = (inputJob instanceof JobStatus ? (JobStatus) inputJob
+                    : null);
+        }
+
+        public void run() {
+            if (jobStatus != null) {
+                jobStatus.requestStateChange(JobStatus.State.RUNNING);
+            }
+            log.info("Starting job {}", inputJob);
+            try {
+                // TODO save Exceptions in job?
+                inputJob.run();
+            } finally {
+                if (jobStatus != null) {
+                    jobStatus.requestStateChange(JobStatus.State.DONE);
+                }
+            }
+            log.info("Done running job {}", inputJob);
+        }
+
+        JobStatus getJobStatus() {
+            return jobStatus;
+        }
+    };
+
+    @SuppressWarnings("serial")
+    public static class QueueFullException extends SlingException {
+        QueueFullException(Runnable r) {
+            super("Execution queue is full, cannot execute " + r);
+        }
+    }
+
+    public void activate(ComponentContext context) {
+        // TODO configurable!
+        final int corePoolSize = 2;
         int maximumPoolSize = 2;
         long keepAliveTime = 30;
         TimeUnit unit = TimeUnit.SECONDS;
-        BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>(4); 
+        BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>(4);
         RejectedExecutionHandler handler = new RejectedExecutionHandler() {
-			public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
-				onJobRejected(r);
-			}
-		};
-        executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler);
-	}
-	
-	public void deactivate(ComponentContext context) {
-		// TODO how to shutdown executor?
-		executor = null;
-		
-		// TODO cleanup jobs??
-	}
-	
-	private void onJobRejected(Runnable r) {
-		final RunnableWrapper w = (RunnableWrapper)r;
-		if(w.getJobStatus() != null) {
-			w.getJobStatus().requestStateChange(JobStatus.State.REJECTED);
-		}
-		log.info("Rejected job {}", r);
-		throw new QueueFullException(r);
-	}
-	
-	public void queueForExecution(final Runnable inputJob) {
-		// Wrap job in our own Runnable to change its state as we execute it
-		final RunnableWrapper w = new RunnableWrapper(inputJob);
-		if(w.getJobStatus() != null) {
-			w.getJobStatus().requestStateChange(JobStatus.State.QUEUED);
-			// TODO when to cleanup?
-			jobs.put(w.getJobStatus().getPath(), w.getJobStatus());
-		}
-		executor.execute(w);
-	}
-	
-	public JobStatus getJobStatus(String path) {
-		return jobs.get(path);
-	}
-
-	public Iterator<JobStatus> getMatchingJobStatus(Predicate<JobStatus> p) {
-		// TODO take predicate into account
-		// TODO sort by submission/execution time?
-		return jobs.values().iterator();
-	}
+            public void rejectedExecution(Runnable r,
+                    ThreadPoolExecutor executor) {
+                onJobRejected(r);
+            }
+        };
+        executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize,
+                keepAliveTime, unit, workQueue, handler);
+    }
+
+    public void deactivate(ComponentContext context) {
+        // TODO how to shutdown executor?
+        executor = null;
+
+        // TODO cleanup jobs??
+    }
+
+    private void onJobRejected(Runnable r) {
+        final RunnableWrapper w = (RunnableWrapper) r;
+        if (w.getJobStatus() != null) {
+            w.getJobStatus().requestStateChange(JobStatus.State.REJECTED);
+        }
+        log.info("Rejected job {}", r);
+        throw new QueueFullException(r);
+    }
+
+    public void queueForExecution(final Runnable inputJob) {
+        // Wrap job in our own Runnable to change its state as we execute it
+        final RunnableWrapper w = new RunnableWrapper(inputJob);
+        if (w.getJobStatus() != null) {
+            w.getJobStatus().requestStateChange(JobStatus.State.QUEUED);
+            // TODO when to cleanup?
+            jobs.put(w.getJobStatus().getPath(), w.getJobStatus());
+        }
+        executor.execute(w);
+    }
+
+    public JobStatus getJobStatus(String path) {
+        return jobs.get(path);
+    }
+
+    public Iterator<JobStatus> getMatchingJobStatus(Predicate<JobStatus> p) {
+        // TODO take predicate into account
+        // TODO sort by submission/execution time?
+        return jobs.values().iterator();
+    }
 }
\ No newline at end of file

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=965490&r1=965489&r2=965490&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 Mon Jul 19 14:08:38 2010
@@ -24,129 +24,140 @@ import java.io.OutputStream;
 
 import org.apache.sling.bgservlets.JobStatus;
 
-/** Wraps an OutputStream with controls for suspending it or
- * 	throwing an IOException next time it is written to.
- * 	Used to suspend background servlets (by blocking the 
- * 	stream) or stop them (by throwing an exception).
+/**
+ * Wraps an OutputStream with controls for suspending it or throwing an
+ * IOException next time it is written to. Used to suspend background servlets
+ * (by blocking the stream) or stop them (by throwing an exception).
  */
-public class SuspendableOutputStream extends FilterOutputStream implements JobStatus {
-	private State state = State.NEW;
-	private boolean closed = false;
-	
-	@SuppressWarnings("serial")
-	public static class StreamStoppedException extends RuntimeException {
-		StreamStoppedException() {
-			super("Stopped by " + SuspendableOutputStream.class.getSimpleName());
-		}
-	}
-	
-	public SuspendableOutputStream(OutputStream os) {
-		super(os);
-	}
-
-	@Override
-	public void write(byte[] b, int off, int len) throws IOException {
-		checkWritePermission();
-		super.write(b, off, len);
-	}
-
-	@Override
-	public void write(byte[] b) throws IOException {
-		checkWritePermission();
-		super.write(b);
-	}
-
-	@Override
-	public void write(int b) throws IOException {
-		checkWritePermission();
-		super.write(b);
-	}
-	
-	@Override
-	public void close() throws IOException {
-		super.close();
-		state = State.DONE;
-		closed = true;
-	}
-	
-	private void checkWritePermission() throws IOException {
-		if(closed) {
-			throw new IOException("Attempt to write to closed stream");
-		}
-		
-		if(state == State.STOP_REQUESTED || state == State.STOPPED) {
-			state = State.STOPPED;
-			// stopped: throw exception to stop stream user
-			flush();
-			throw new StreamStoppedException();
-			
-		} else if(state == State.SUSPEND_REQUESTED || state == State.SUSPENDED) {
-			synchronized (this) {
-				if(state == State.SUSPEND_REQUESTED || state == State.SUSPENDED)
-					state = State.SUSPENDED;
-					try {
-						// suspended: block until resumed
-						while(state == State.SUSPENDED) {
-							wait();
-						}
-					} catch (InterruptedException e) {
-						throw new IOException("InterruptedException in checkWritePermission()", e);
-					}
-			}
-		}
-	}
-
-
-	public State getState() {
-		return state;
-	}
-
-	/** Only SUSPENDED, STOP, and RUNNING make sense here */ 
-	public synchronized void requestStateChange(State s) {
-		boolean illegal = false;
-		
-		if(state == State.DONE) {
-			// ignore changes
-		} else if(s == State.SUSPENDED) {
-			if(state == State.NEW || state == State.QUEUED || state == State.RUNNING) {
-				state = State.SUSPEND_REQUESTED;
-				notify();
-			} else if(state == State.SUSPEND_REQUESTED || state == State.SUSPENDED) {
-				// ignore change
-			} else {
-				illegal = true;
-			}
-			
-		} else if(s == State.STOPPED) {
-			if(state == State.NEW || state == State.QUEUED || state == State.RUNNING 
-					|| state == State.SUSPEND_REQUESTED || state == State.SUSPENDED) {
-				state = State.STOP_REQUESTED;
-				notify();
-			} else if (state == State.STOP_REQUESTED || state == State.STOPPED) {
-				// ignore change
-			} else {
-				illegal = true;
-			}
-			
-		} else if(s == State.RUNNING) {
-			if(state == State.SUSPEND_REQUESTED || state == State.SUSPENDED) {
-				state = State.RUNNING;
-				notify();
-			}
-			
-		} else {
-			state = s;
-			notify();
-		}
-		
-		if(illegal) {
-			throw new IllegalStateException("Illegal state change:" + state + " -> " + s);
-		}
-	}
-
-	/** Not implemented
-	 * 	@throws UnsupportedOperationException */
-	public String getPath() {
-		throw new UnsupportedOperationException("getPath() is not applicable to this class");
-	}
+public class SuspendableOutputStream extends FilterOutputStream implements
+        JobStatus {
+    private State state = State.NEW;
+    private boolean closed = false;
+
+    @SuppressWarnings("serial")
+    public static class StreamStoppedException extends RuntimeException {
+        StreamStoppedException() {
+            super("Stopped by " + SuspendableOutputStream.class.getSimpleName());
+        }
+    }
+
+    public SuspendableOutputStream(OutputStream os) {
+        super(os);
+    }
+
+    @Override
+    public void write(byte[] b, int off, int len) throws IOException {
+        checkWritePermission();
+        super.write(b, off, len);
+    }
+
+    @Override
+    public void write(byte[] b) throws IOException {
+        checkWritePermission();
+        super.write(b);
+    }
+
+    @Override
+    public void write(int b) throws IOException {
+        checkWritePermission();
+        super.write(b);
+    }
+
+    @Override
+    public void close() throws IOException {
+        super.close();
+        state = State.DONE;
+        closed = true;
+    }
+
+    private void checkWritePermission() throws IOException {
+        if (closed) {
+            throw new IOException("Attempt to write to closed stream");
+        }
+
+        if (state == State.STOP_REQUESTED || state == State.STOPPED) {
+            state = State.STOPPED;
+            // stopped: throw exception to stop stream user
+            flush();
+            throw new StreamStoppedException();
+
+        } else if (state == State.SUSPEND_REQUESTED || state == State.SUSPENDED) {
+            synchronized (this) {
+                if (state == State.SUSPEND_REQUESTED
+                        || state == State.SUSPENDED)
+                    state = State.SUSPENDED;
+                try {
+                    // suspended: block until resumed
+                    while (state == State.SUSPENDED) {
+                        wait();
+                    }
+                } catch (InterruptedException e) {
+                    throw new IOException(
+                            "InterruptedException in checkWritePermission()", e);
+                }
+            }
+        }
+    }
+
+    public State getState() {
+        return state;
+    }
+
+    /** Only SUSPENDED, STOP, and RUNNING make sense here */
+    public synchronized void requestStateChange(State s) {
+        boolean illegal = false;
+
+        if (state == State.DONE) {
+            // ignore changes
+        } else if (s == State.SUSPENDED) {
+            if (state == State.NEW || state == State.QUEUED
+                    || state == State.RUNNING) {
+                state = State.SUSPEND_REQUESTED;
+                notify();
+            } else if (state == State.SUSPEND_REQUESTED
+                    || state == State.SUSPENDED) {
+                // ignore change
+            } else {
+                illegal = true;
+            }
+
+        } else if (s == State.STOPPED) {
+            if (state == State.NEW || state == State.QUEUED
+                    || state == State.RUNNING
+                    || state == State.SUSPEND_REQUESTED
+                    || state == State.SUSPENDED) {
+                state = State.STOP_REQUESTED;
+                notify();
+            } else if (state == State.STOP_REQUESTED || state == State.STOPPED) {
+                // ignore change
+            } else {
+                illegal = true;
+            }
+
+        } else if (s == State.RUNNING) {
+            if (state == State.SUSPEND_REQUESTED || state == State.SUSPENDED) {
+                state = State.RUNNING;
+                notify();
+            }
+
+        } else {
+            state = s;
+            notify();
+        }
+
+        if (illegal) {
+            throw new IllegalStateException("Illegal state change:" + state
+                    + " -> " + s);
+        }
+    }
+
+    /**
+     * Not implemented
+     * 
+     * @throws UnsupportedOperationException
+     */
+    public String getPath() {
+        throw new UnsupportedOperationException(
+                "getPath() is not applicable to this class");
+    }
 }

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/webconsole/ExecutionEngineConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/webconsole/ExecutionEngineConsolePlugin.java?rev=965490&r1=965489&r2=965490&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/webconsole/ExecutionEngineConsolePlugin.java (original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/webconsole/ExecutionEngineConsolePlugin.java Mon Jul 19 14:08:38 2010
@@ -41,17 +41,18 @@ import org.slf4j.LoggerFactory;
 
 /** Felix OSGi console plugin for the ExecutionEngine */
 public class ExecutionEngineConsolePlugin {
-	private static final Logger log = LoggerFactory.getLogger(ExecutionEngineConsolePlugin.class);
-	private static Plugin plugin;
+    private static final Logger log = LoggerFactory
+            .getLogger(ExecutionEngineConsolePlugin.class);
+    private static Plugin plugin;
     public static final String LABEL = "bgservlets";
     public static final String TITLE = "Background Servlets & Jobs";
-	
+
     public static void initPlugin(BundleContext context) {
         if (plugin == null) {
             Plugin tmp = new Plugin();
             tmp.activate(context);
             plugin = tmp;
-    		log.info("{} activated", plugin);
+            log.info("{} activated", plugin);
         }
     }
 
@@ -59,7 +60,7 @@ public class ExecutionEngineConsolePlugi
         if (plugin != null) {
             try {
                 plugin.deactivate();
-        		log.info("{} deactivated", plugin);
+                log.info("{} deactivated", plugin);
             } finally {
                 plugin = null;
             }
@@ -67,36 +68,42 @@ public class ExecutionEngineConsolePlugi
     }
 
     @SuppressWarnings("serial")
-	public static final class Plugin extends AbstractWebConsolePlugin {
+    public static final class Plugin extends AbstractWebConsolePlugin {
         private ServiceRegistration serviceRegistration;
         private ServiceTracker executionEngineTracker;
-        
-    	public void activate(BundleContext ctx) {
+
+        public void activate(BundleContext ctx) {
             super.activate(ctx);
-            
-            executionEngineTracker = new ServiceTracker(ctx, ExecutionEngine.class.getName(), null);
+
+            executionEngineTracker = new ServiceTracker(ctx,
+                    ExecutionEngine.class.getName(), null);
             executionEngineTracker.open();
-            
+
             Dictionary<String, Object> props = new Hashtable<String, Object>();
-            props.put(Constants.SERVICE_DESCRIPTION,
-                "Web Console Plugin to display Background servlets and ExecutionEngine status");
-            props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+            props
+                    .put(Constants.SERVICE_DESCRIPTION,
+                            "Web Console Plugin to display Background servlets and ExecutionEngine status");
+            props.put(Constants.SERVICE_VENDOR,
+                    "The Apache Software Foundation");
             props.put(Constants.SERVICE_PID, getClass().getName());
             props.put(WebConsoleConstants.PLUGIN_LABEL, LABEL);
 
-            serviceRegistration = ctx.registerService(WebConsoleConstants.SERVICE_NAME, this, props);
-    	}
-    	public void deactivate() {
+            serviceRegistration = ctx.registerService(
+                    WebConsoleConstants.SERVICE_NAME, this, props);
+        }
+
+        public void deactivate() {
             if (serviceRegistration != null) {
                 serviceRegistration.unregister();
                 serviceRegistration = null;
             }
-    		if(executionEngineTracker != null) {
-    			executionEngineTracker.close();
-    			executionEngineTracker = null;
-    		}
+            if (executionEngineTracker != null) {
+                executionEngineTracker.close();
+                executionEngineTracker = null;
+            }
             super.deactivate();
-    	}
+        }
+
         @Override
         public String getLabel() {
             return LABEL;
@@ -106,37 +113,39 @@ public class ExecutionEngineConsolePlugi
         public String getTitle() {
             return TITLE;
         }
-        
+
         @Override
-        protected void renderContent(HttpServletRequest req, HttpServletResponse res)
-          throws ServletException, IOException {
-        	final PrintWriter pw = res.getWriter();
-        	final ExecutionEngine ee = (ExecutionEngine)executionEngineTracker.getService();
-        	if(ee == null) {
-        		pw.println("No ExecutionEngine service found");
-        		return;
-        	}
-        	
-        	// TODO should use POST
-    		final String jobPath = req.getParameter("jobPath");
-    		if(jobPath != null) {
-        		final JobStatus job = ee.getJobStatus(jobPath);
-        		if(job != null) {
-            		final String action = req.getParameter("action");
-            		if("suspend".equals(action)) {
-            			job.requestStateChange(JobStatus.State.SUSPENDED);
-            		} else if("stop".equals(action)) {
-            			job.requestStateChange(JobStatus.State.STOPPED);
-            		} else if("resume".equals(action)) {
-            			job.requestStateChange(JobStatus.State.RUNNING);
-            		}
-        		}
-    		}
-    		
-    		pw.println("TODO: provide a way to cleanup old jobs<br/>");
-    		pw.println("TODO: optionally list active jobs only<br/>");
-  
-            pw.println("<table class='content' cellpadding='0' cellspacing='0' width='100%'>");
+        protected void renderContent(HttpServletRequest req,
+                HttpServletResponse res) throws ServletException, IOException {
+            final PrintWriter pw = res.getWriter();
+            final ExecutionEngine ee = (ExecutionEngine) executionEngineTracker
+                    .getService();
+            if (ee == null) {
+                pw.println("No ExecutionEngine service found");
+                return;
+            }
+
+            // TODO should use POST
+            final String jobPath = req.getParameter("jobPath");
+            if (jobPath != null) {
+                final JobStatus job = ee.getJobStatus(jobPath);
+                if (job != null) {
+                    final String action = req.getParameter("action");
+                    if ("suspend".equals(action)) {
+                        job.requestStateChange(JobStatus.State.SUSPENDED);
+                    } else if ("stop".equals(action)) {
+                        job.requestStateChange(JobStatus.State.STOPPED);
+                    } else if ("resume".equals(action)) {
+                        job.requestStateChange(JobStatus.State.RUNNING);
+                    }
+                }
+            }
+
+            pw.println("TODO: provide a way to cleanup old jobs<br/>");
+            pw.println("TODO: optionally list active jobs only<br/>");
+
+            pw
+                    .println("<table class='content' cellpadding='0' cellspacing='0' width='100%'>");
             pw.println("<thead>");
             pw.println("<tr class='content'>");
             pw.println("<th class='content container'>Controls</th>");
@@ -146,35 +155,37 @@ public class ExecutionEngineConsolePlugi
             pw.println("</thead>");
             pw.println("<tbody>");
 
-        	final Iterator<JobStatus> it = ee.getMatchingJobStatus(null);
-        	int count = 0;
-        	while(it.hasNext()) {
-        		renderJobStatus(pw, it.next());
-        		count++;
-        	}
+            final Iterator<JobStatus> it = ee.getMatchingJobStatus(null);
+            int count = 0;
+            while (it.hasNext()) {
+                renderJobStatus(pw, it.next());
+                count++;
+            }
             pw.println("</tbody>");
-        	pw.println("</table>");
-        	pw.println("Total <b>" + count + "</b> jobs.<br />");
+            pw.println("</table>");
+            pw.println("Total <b>" + count + "</b> jobs.<br />");
         }
-        
+
         private void renderJobStatus(PrintWriter pw, JobStatus job) {
-        	// TODO should use POST
+            // TODO should use POST
             pw.println("<tr class='content'>");
-        	pw.println("<td><form action='./" + LABEL + "' method='GET'>");
-        	final String [] actions = { "suspend", "resume", "stop" };
-        	for(String action : actions) {
-        		pw.println("<input type='submit' name='action' value='" + action + "'/>&nbsp;");
-        	}
-        	pw.println("<input type='hidden' name='jobPath' value='" + job.getPath() + "'/>&nbsp;");
-        	pw.println("</form></td>");
-        	pw.println("<td>");
-        	pw.println(job.getState());
-        	pw.println("</td>");
-        	pw.println("<td>");
-        	pw.println(job.getPath());
-        	pw.println("</td>");
-        	pw.println("</tr>");
+            pw.println("<td><form action='./" + LABEL + "' method='GET'>");
+            final String[] actions = { "suspend", "resume", "stop" };
+            for (String action : actions) {
+                pw.println("<input type='submit' name='action' value='"
+                        + action + "'/>&nbsp;");
+            }
+            pw.println("<input type='hidden' name='jobPath' value='"
+                    + job.getPath() + "'/>&nbsp;");
+            pw.println("</form></td>");
+            pw.println("<td>");
+            pw.println(job.getState());
+            pw.println("</td>");
+            pw.println("<td>");
+            pw.println(job.getPath());
+            pw.println("</td>");
+            pw.println("</tr>");
         }
-    
+
     }
 }
\ No newline at end of file

Modified: sling/trunk/contrib/extensions/bgservlets/src/test/java/org/apache/sling/bgservlets/impl/SuspendableOutputStreamTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/test/java/org/apache/sling/bgservlets/impl/SuspendableOutputStreamTest.java?rev=965490&r1=965489&r2=965490&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/test/java/org/apache/sling/bgservlets/impl/SuspendableOutputStreamTest.java (original)
+++ sling/trunk/contrib/extensions/bgservlets/src/test/java/org/apache/sling/bgservlets/impl/SuspendableOutputStreamTest.java Mon Jul 19 14:08:38 2010
@@ -19,9 +19,9 @@
 package org.apache.sling.bgservlets.impl;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.fail;
 
 import java.io.ByteArrayOutputStream;
@@ -32,129 +32,146 @@ import org.apache.sling.bgservlets.JobSt
 import org.junit.Test;
 
 public class SuspendableOutputStreamTest {
-	public final static String TEST = "0123456789abcdefghijklmnopqrstuvwxyz";
-	
-	static class WriterThread extends Thread {
-		private final OutputStream os;
-		private final byte [] toWrite = "TEST".getBytes();
-		private Exception runException;
-		final static int WRITE_DELAY = 50;
-		
-		WriterThread(OutputStream os) {
-			this.os = os;
-		}
-		
-		@Override
-		public void run() {
-			try {
-				while(true) {
-					os.write(toWrite);
-					Thread.sleep(WRITE_DELAY);
-				}
-			} catch(Exception e) {
-				runException = e;
-			}
-		}
- 	}
-	
-	@Test
-	public void testNoSuspend() throws IOException {
-		final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-		final SuspendableOutputStream f = new SuspendableOutputStream(bos);
-		f.write(TEST.getBytes());
-		f.flush();
-		assertEquals("String should be fully written", TEST, bos.toString());
-	}
-	
-	@Test
-	public void testStop() throws IOException {
-		final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-		final SuspendableOutputStream f = new SuspendableOutputStream(bos);
-		assertEquals("Expecting NEW state first", JobStatus.State.NEW, f.getState());
-		f.requestStateChange(JobStatus.State.RUNNING);
-		f.write(TEST.getBytes());
-		f.flush();
-		
-		f.requestStateChange(JobStatus.State.STOPPED);
-		assertEquals("Expecting STOP_REQUESTED state before write", JobStatus.State.STOP_REQUESTED, f.getState());
-		try {
-			f.write("nothing".getBytes());
-			fail("Expected StreamStoppedException when writing to STOPPED stream");
-		} catch(SuspendableOutputStream.StreamStoppedException asExpected) {
-		}
-		
-		assertEquals("Expecting STOPPED state after write", JobStatus.State.STOPPED, f.getState());
-	}
-	
-	@Test
-	public void testSuspend() throws Exception {
-		final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-		final SuspendableOutputStream f = new SuspendableOutputStream(bos);
-		f.requestStateChange(JobStatus.State.RUNNING);
-		final WriterThread t = new WriterThread(f);
-		t.setDaemon(true);
-		t.start();
-		
-		final long delay = WriterThread.WRITE_DELAY * 3;
-		Thread.sleep(delay);
-		assertTrue("Expecting data to be written by WriterThread", bos.size() > 0);
-		
-		f.requestStateChange(JobStatus.State.SUSPENDED);
-		Thread.sleep(delay);
-		assertEquals("Expecting SUSPEND state after a few writes", JobStatus.State.SUSPENDED, f.getState());
-		
-		final int count = bos.size();
-		Thread.sleep(delay);
-		assertEquals("Expecting no writes in SUSPEND state", count, bos.size());
-		
-		f.requestStateChange(JobStatus.State.RUNNING);
-		Thread.sleep(delay);
-		assertEquals("Expecting RUNNING state", JobStatus.State.RUNNING, f.getState());
-		assertTrue("Expecting data to be written after resuming", bos.size() > count);
-		
-		f.close();
-		Thread.sleep(delay);
-		assertFalse("Expecting WriterThread to end after closing stream", t.isAlive());
-		assertNotNull("Expecting non-null Exception in WriterThread", t.runException);
-		assertTrue("Expecting IOException in WriterThread", t.runException instanceof IOException);
-	}
-	
-	@Test
-	public void testSuspendThenStop() throws Exception {
-		final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-		final SuspendableOutputStream f = new SuspendableOutputStream(bos);
-		assertEquals("Expecting NEW state first", JobStatus.State.NEW, f.getState());
-		final WriterThread t = new WriterThread(f);
-		t.setDaemon(true);
-		t.start();
-		
-		f.requestStateChange(JobStatus.State.SUSPENDED);
-		
-		final long delay = WriterThread.WRITE_DELAY * 3;
-		Thread.sleep(delay);
-		assertEquals("Expecting SUSPEND state after a few writes", JobStatus.State.SUSPENDED, f.getState());
-		
-		f.requestStateChange(JobStatus.State.STOPPED);
-		assertEquals("Expecting STOP_REQUESTED state before write", JobStatus.State.STOP_REQUESTED, f.getState());
-		try {
-			f.write("nothing".getBytes());
-			fail("Expected StreamStoppedException when writing to STOPPED stream");
-		} catch(SuspendableOutputStream.StreamStoppedException asExpected) {
-		}
-		
-		assertEquals("Expecting STOPPED state after write", JobStatus.State.STOPPED, f.getState());
-		f.close();
-	}
-	
-	@Test
-	public void testDone() {
-		final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-		final SuspendableOutputStream f = new SuspendableOutputStream(bos);
-		f.requestStateChange(JobStatus.State.DONE);
-		assertEquals("Expecting DONE state (1)", JobStatus.State.DONE, f.getState());
-		f.requestStateChange(JobStatus.State.SUSPENDED);
-		assertEquals("Expecting DONE state (2)", JobStatus.State.DONE, f.getState());
-		f.requestStateChange(JobStatus.State.STOPPED);
-		assertEquals("Expecting DONE state (3)", JobStatus.State.DONE, f.getState());
-	}
+    public final static String TEST = "0123456789abcdefghijklmnopqrstuvwxyz";
+
+    static class WriterThread extends Thread {
+        private final OutputStream os;
+        private final byte[] toWrite = "TEST".getBytes();
+        private Exception runException;
+        final static int WRITE_DELAY = 50;
+
+        WriterThread(OutputStream os) {
+            this.os = os;
+        }
+
+        @Override
+        public void run() {
+            try {
+                while (true) {
+                    os.write(toWrite);
+                    Thread.sleep(WRITE_DELAY);
+                }
+            } catch (Exception e) {
+                runException = e;
+            }
+        }
+    }
+
+    @Test
+    public void testNoSuspend() throws IOException {
+        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        final SuspendableOutputStream f = new SuspendableOutputStream(bos);
+        f.write(TEST.getBytes());
+        f.flush();
+        assertEquals("String should be fully written", TEST, bos.toString());
+    }
+
+    @Test
+    public void testStop() throws IOException {
+        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        final SuspendableOutputStream f = new SuspendableOutputStream(bos);
+        assertEquals("Expecting NEW state first", JobStatus.State.NEW, f
+                .getState());
+        f.requestStateChange(JobStatus.State.RUNNING);
+        f.write(TEST.getBytes());
+        f.flush();
+
+        f.requestStateChange(JobStatus.State.STOPPED);
+        assertEquals("Expecting STOP_REQUESTED state before write",
+                JobStatus.State.STOP_REQUESTED, f.getState());
+        try {
+            f.write("nothing".getBytes());
+            fail("Expected StreamStoppedException when writing to STOPPED stream");
+        } catch (SuspendableOutputStream.StreamStoppedException asExpected) {
+        }
+
+        assertEquals("Expecting STOPPED state after write",
+                JobStatus.State.STOPPED, f.getState());
+    }
+
+    @Test
+    public void testSuspend() throws Exception {
+        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        final SuspendableOutputStream f = new SuspendableOutputStream(bos);
+        f.requestStateChange(JobStatus.State.RUNNING);
+        final WriterThread t = new WriterThread(f);
+        t.setDaemon(true);
+        t.start();
+
+        final long delay = WriterThread.WRITE_DELAY * 3;
+        Thread.sleep(delay);
+        assertTrue("Expecting data to be written by WriterThread",
+                bos.size() > 0);
+
+        f.requestStateChange(JobStatus.State.SUSPENDED);
+        Thread.sleep(delay);
+        assertEquals("Expecting SUSPEND state after a few writes",
+                JobStatus.State.SUSPENDED, f.getState());
+
+        final int count = bos.size();
+        Thread.sleep(delay);
+        assertEquals("Expecting no writes in SUSPEND state", count, bos.size());
+
+        f.requestStateChange(JobStatus.State.RUNNING);
+        Thread.sleep(delay);
+        assertEquals("Expecting RUNNING state", JobStatus.State.RUNNING, f
+                .getState());
+        assertTrue("Expecting data to be written after resuming",
+                bos.size() > count);
+
+        f.close();
+        Thread.sleep(delay);
+        assertFalse("Expecting WriterThread to end after closing stream", t
+                .isAlive());
+        assertNotNull("Expecting non-null Exception in WriterThread",
+                t.runException);
+        assertTrue("Expecting IOException in WriterThread",
+                t.runException instanceof IOException);
+    }
+
+    @Test
+    public void testSuspendThenStop() throws Exception {
+        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        final SuspendableOutputStream f = new SuspendableOutputStream(bos);
+        assertEquals("Expecting NEW state first", JobStatus.State.NEW, f
+                .getState());
+        final WriterThread t = new WriterThread(f);
+        t.setDaemon(true);
+        t.start();
+
+        f.requestStateChange(JobStatus.State.SUSPENDED);
+
+        final long delay = WriterThread.WRITE_DELAY * 3;
+        Thread.sleep(delay);
+        assertEquals("Expecting SUSPEND state after a few writes",
+                JobStatus.State.SUSPENDED, f.getState());
+
+        f.requestStateChange(JobStatus.State.STOPPED);
+        assertEquals("Expecting STOP_REQUESTED state before write",
+                JobStatus.State.STOP_REQUESTED, f.getState());
+        try {
+            f.write("nothing".getBytes());
+            fail("Expected StreamStoppedException when writing to STOPPED stream");
+        } catch (SuspendableOutputStream.StreamStoppedException asExpected) {
+        }
+
+        assertEquals("Expecting STOPPED state after write",
+                JobStatus.State.STOPPED, f.getState());
+        f.close();
+    }
+
+    @Test
+    public void testDone() {
+        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        final SuspendableOutputStream f = new SuspendableOutputStream(bos);
+        f.requestStateChange(JobStatus.State.DONE);
+        assertEquals("Expecting DONE state (1)", JobStatus.State.DONE, f
+                .getState());
+        f.requestStateChange(JobStatus.State.SUSPENDED);
+        assertEquals("Expecting DONE state (2)", JobStatus.State.DONE, f
+                .getState());
+        f.requestStateChange(JobStatus.State.STOPPED);
+        assertEquals("Expecting DONE state (3)", JobStatus.State.DONE, f
+                .getState());
+    }
 }



Mime
View raw message