001: /*
002: * JBoss, Home of Professional Open Source
003: * Copyright 2005, JBoss Inc., and individual contributors as indicated
004: * by the @authors tag. See the copyright.txt in the distribution for a
005: * full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jbpm.job.executor;
023:
024: import java.io.IOException;
025: import java.io.PrintWriter;
026: import java.util.Collection;
027: import java.util.Iterator;
028:
029: import javax.servlet.ServletException;
030: import javax.servlet.http.HttpServlet;
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletResponse;
033:
034: import org.jbpm.JbpmConfiguration;
035:
036: /**
037: * starts the job executor on init and closes the
038: * jbpm configuration upon destroy. The closing of the
039: * jbpm configuration will also shut down the job executor
040: * thread pool.
041: * <h1>Config parameters</h1>
042: * <table>
043: * <tr>
044: * <th>Name</th>
045: * <th>Description</th>
046: * <th>Type</th>
047: * <th>Default value</th>
048: * </tr>
049: * <tr>
050: * <td>jbpm.configuration.resource</td>
051: * <td>resource location of the jbpm.cfg.xml</td>
052: * <td>String</td>
053: * <td>jbpm.cfg.xml</td>
054: * </tr>
055: * </table>
056: *
057: * <p>Configuration example:
058: * <pre>
059: * <web-app>
060: * ...
061: * <servlet >
062: * <servlet-name>JobExecutorServlet</servlet-name>
063: * <servlet-class>org.jbpm.job.executor.JobExecutorServlet</servlet-class>
064: * <load-on-startup>1</load-on-startup>
065: * </servlet>
066: * <servlet-mapping >
067: * <servlet-name>JobExecutorServlet</servlet-name>
068: * <url-pattern>/jobexecutor</url-pattern>
069: * </servlet-mapping>
070: * ...
071: * </web-app>
072: * </pre>
073: * </p>
074: */
075: public class JobExecutorServlet extends HttpServlet {
076:
077: private static final long serialVersionUID = 1L;
078:
079: JbpmConfiguration jbpmConfiguration;
080:
081: public void init() throws ServletException {
082: String configurationName = getInitParameter(
083: "jbpm.configuration.resource", null);
084: jbpmConfiguration = JbpmConfiguration
085: .getInstance(configurationName);
086: jbpmConfiguration.startJobExecutor();
087: }
088:
089: protected void doGet(HttpServletRequest request,
090: HttpServletResponse response) throws ServletException,
091: IOException {
092: PrintWriter out = response.getWriter();
093: out.println("<html>");
094: out.println("<body>");
095: out.println("<h2>JBoss jBPM Scheduler Servlet</h2><hr />");
096: Collection threads = jbpmConfiguration.getJobExecutor()
097: .getThreads().values();
098: Iterator iter = threads.iterator();
099: while (iter.hasNext()) {
100: Thread thread = (Thread) iter.next();
101: out.println("<h4>" + thread.getName() + "</h4>");
102: out.println("<b>isAlive</b>:" + thread.isAlive());
103: }
104: out.println("</body>");
105: out.println("</html>");
106: }
107:
108: String getInitParameter(String name, String defaultValue) {
109: String value = getInitParameter(name);
110: if (value != null) {
111: return value;
112: }
113: return defaultValue;
114: }
115: }
|