incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r963718 - in /sling/trunk/contrib/extensions/bgservlets: ./ src/main/java/org/apache/sling/bgservlets/ src/main/java/org/apache/sling/bgservlets/impl/ src/main/java/org/apache/sling/bgservlets/impl/webconsole/
Date Tue, 13 Jul 2010 14:13:16 GMT
Author: bdelacretaz
Date: Tue Jul 13 14:13:16 2010
New Revision: 963718

URL: http://svn.apache.org/viewvc?rev=963718&view=rev
Log:
SLING-550 - basic webconsole plugin

Added:
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobStatus.java
  (with props)
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/Predicate.java
  (with props)
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/Activator.java
  (with props)
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/webconsole/
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/webconsole/ExecutionEngineConsolePlugin.java
  (with props)
Modified:
    sling/trunk/contrib/extensions/bgservlets/pom.xml
    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/impl/ExecutionEngineImpl.java
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/FilterChainExecutionJob.java
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/ServletResponseWrapper.java

Modified: sling/trunk/contrib/extensions/bgservlets/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/pom.xml?rev=963718&r1=963717&r2=963718&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/pom.xml (original)
+++ sling/trunk/contrib/extensions/bgservlets/pom.xml Tue Jul 13 14:13:16 2010
@@ -55,6 +55,8 @@
           <instructions>
             <Export-Package>org.apache.sling.bgservlets</Export-Package>
             <Private-Package>org.apache.sling.bgservlets.impl.*</Private-Package>
+            <DynamicImport-Package>org.apache.felix.webconsole</DynamicImport-Package>
+            <Bundle-Activator>org.apache.sling.bgservlets.impl.Activator</Bundle-Activator>
           </instructions>
         </configuration>
       </plugin>
@@ -90,5 +92,10 @@
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.webconsole</artifactId>
+      <version>3.0.0</version>
+    </dependency>
   </dependencies>
 </project>
\ No newline at end of file

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=963718&r1=963717&r2=963718&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
Tue Jul 13 14:13:16 2010
@@ -18,6 +18,8 @@
  */
 package org.apache.sling.bgservlets;
 
+import java.util.Iterator;
+
 /** Service that executes Runnables, will later allow
  * 	them to be suspended, resumed, stopped and restarted.
  */
@@ -25,4 +27,12 @@ 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);
 }
\ No newline at end of file

Added: 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=963718&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobStatus.java
(added)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobStatus.java
Tue Jul 13 14:13:16 2010
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+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
+	}
+
+	/** 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

Propchange: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobStatus.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/JobStatus.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: 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=963718&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/Predicate.java
(added)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/Predicate.java
Tue Jul 13 14:13:16 2010
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.bgservlets;
+
+/** Simple typed predicate */
+public interface Predicate<T> {
+	boolean isTrue(T subject);
+}

Propchange: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/Predicate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/Predicate.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: 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=963718&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/Activator.java
(added)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/Activator.java
Tue Jul 13 14:13:16 2010
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.bgservlets.impl;
+
+import org.apache.sling.bgservlets.impl.webconsole.ExecutionEngineConsolePlugin;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Bundle activator */
+public class Activator implements BundleActivator {
+	private final Logger log = LoggerFactory.getLogger(getClass());
+	
+    /**
+     * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+     */
+    public void start(BundleContext context) throws Exception {
+        try {
+            ExecutionEngineConsolePlugin.initPlugin(context);
+        } catch (Throwable ignore) {
+        	// Happens for example if the webconsole is not installed
+            log.debug("Exception in start()", ignore);
+        }
+    }
+
+    /**
+     * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+     */
+    public void stop(BundleContext context) throws Exception {
+        try {
+            ExecutionEngineConsolePlugin.destroyPlugin();
+        } catch (Throwable ignore) {
+            log.debug("Exception in stop()", ignore);
+        }
+    }
+}

Propchange: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/Activator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/Activator.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

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=963718&r1=963717&r2=963718&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
Tue Jul 13 14:13:16 2010
@@ -18,6 +18,9 @@
  */
 package org.apache.sling.bgservlets.impl;
 
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.Executor;
@@ -29,7 +32,11 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.api.SlingException;
 import org.apache.sling.bgservlets.ExecutionEngine;
+import org.apache.sling.bgservlets.JobStatus;
+import org.apache.sling.bgservlets.Predicate;
 import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /** Simple ExecutionEngine
  * 	TODO should use Sling's thread pool, and check synergies
@@ -38,7 +45,38 @@ import org.osgi.service.component.Compon
 @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 {
@@ -56,19 +94,46 @@ public class ExecutionEngineImpl impleme
         BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>(4);

         RejectedExecutionHandler handler = new RejectedExecutionHandler() {
 			public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
-				throw new QueueFullException(r);
+				onJobRejected(r);
 			}
 		};
-        executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit,
workQueue, handler); 
+        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(Runnable job) {
-		// TODO wrap job in our own Runnable to detect start/end etc.
-		executor.execute(job);
+	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/FilterChainExecutionJob.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/FilterChainExecutionJob.java?rev=963718&r1=963717&r2=963718&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/FilterChainExecutionJob.java
(original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/FilterChainExecutionJob.java
Tue Jul 13 14:13:16 2010
@@ -24,16 +24,19 @@ import javax.servlet.FilterChain;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.sling.bgservlets.JobStatus;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /** Runnable that executes a FilterChain, using 
  * 	a ServletResponseWrapper to capture the output.
  */
-class FilterChainExecutionJob implements Runnable {
+class FilterChainExecutionJob implements Runnable, JobStatus {
 	private final Logger log = LoggerFactory.getLogger(getClass());
 	private final FilterChain chain;
 	private final ServletResponseWrapper response;
+	private final String path;
+	private State state = State.NEW;
 	
 	// TODO is it ok to keep a reference to the request until run() is called??
 	private final HttpServletRequest request;
@@ -42,14 +45,14 @@ class FilterChainExecutionJob implements
 		this.chain = chain;
 		this.request = request;
 		response  = new ServletResponseWrapper(hsr);
+		path = response.getOutputPath();
 	}
 	
 	public String toString() {
-		return "Background request job: " + response;
+		return getClass().getSimpleName() + ", state=" + state + ", path=" + path;
 	}
 	
 	public void run() {
-		log.info("{} execution starts", this);
 		try {
 			chain.doFilter(request, response);
 		} catch(Exception e) {
@@ -63,6 +66,18 @@ class FilterChainExecutionJob implements
 				log.error("ServletResponseWrapper cleanup failed", ioe);
 			}
 		}
-		log.info("{} execution ends", this);
+	}
+
+	public String getPath() {
+		return path;
+	}
+
+	public State getState() {
+		return state;
+	}
+
+	public void requestStateChange(State s) {
+		// TODO need some validity checks
+		state = s;
 	}
 }

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/ServletResponseWrapper.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/ServletResponseWrapper.java?rev=963718&r1=963717&r2=963718&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/ServletResponseWrapper.java
(original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/ServletResponseWrapper.java
Tue Jul 13 14:13:16 2010
@@ -75,6 +75,10 @@ class ServletResponseWrapper extends Htt
 		return getClass().getName() + ":" + outputPath;
 	}
 	
+	String getOutputPath() {
+		return outputPath;
+	}
+	
 	void cleanup() throws IOException {
 		stream.flush();
 		stream.close();

Added: 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=963718&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/webconsole/ExecutionEngineConsolePlugin.java
(added)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/webconsole/ExecutionEngineConsolePlugin.java
Tue Jul 13 14:13:16 2010
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.bgservlets.impl.webconsole;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.felix.webconsole.AbstractWebConsolePlugin;
+import org.apache.felix.webconsole.WebConsoleConstants;
+import org.apache.sling.bgservlets.ExecutionEngine;
+import org.apache.sling.bgservlets.JobStatus;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+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;
+    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);
+        }
+    }
+
+    public static void destroyPlugin() {
+        if (plugin != null) {
+            try {
+                plugin.deactivate();
+        		log.info("{} deactivated", plugin);
+            } finally {
+                plugin = null;
+            }
+        }
+    }
+
+    @SuppressWarnings("serial")
+	public static final class Plugin extends AbstractWebConsolePlugin {
+        private ServiceRegistration serviceRegistration;
+        private ServiceTracker executionEngineTracker;
+        
+    	public void activate(BundleContext ctx) {
+            super.activate(ctx);
+            
+            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_PID, getClass().getName());
+            props.put(WebConsoleConstants.PLUGIN_LABEL, LABEL);
+
+            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;
+    		}
+            super.deactivate();
+    	}
+        @Override
+        public String getLabel() {
+            return LABEL;
+        }
+
+        @Override
+        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;
+        	}
+  
+        	pw.println("ExecutionEngine jobs:<br/>");
+        	pw.println("<pre>");
+        	final Iterator<JobStatus> it = ee.getMatchingJobStatus(null);
+        	int count = 0;
+        	while(it.hasNext()) {
+        		pw.println(it.next());
+        		count++;
+        	}
+        	pw.println("</pre>");
+        	pw.println("Total <b>" + count + "</b> jobs.<br />");
+        }
+    }
+}
\ No newline at end of file

Propchange: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/webconsole/ExecutionEngineConsolePlugin.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/webconsole/ExecutionEngineConsolePlugin.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message