X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdolda%2Fjsvc%2Fj2ee%2FServlet.java;h=2b149c910bb36ae340a4c2a977ea1da56845bba1;hb=762009abaf3acc38003c9635115c721c602bdaa5;hp=165b0f2e2cfe489515da86777d8430b85e4749c0;hpb=7114c38b358d27e6c390a689a50c7f9d2d2a048c;p=jsvc.git diff --git a/src/dolda/jsvc/j2ee/Servlet.java b/src/dolda/jsvc/j2ee/Servlet.java index 165b0f2..2b149c9 100644 --- a/src/dolda/jsvc/j2ee/Servlet.java +++ b/src/dolda/jsvc/j2ee/Servlet.java @@ -8,16 +8,9 @@ import javax.servlet.http.*; import javax.servlet.*; public class Servlet extends HttpServlet { - private Responder root; - private ThreadGroup workers; - private long reqs = 0; + private ThreadContext tg; - public void init() throws ServletException { - workers = new ThreadGroup("JSvc worker threads") { - public void uncaughtException(Thread t, Throwable e) { - log("Worker thread terminated with an uncaught exception", e); - } - }; + public void init(ServletConfig cfg) throws ServletException { Properties sprop = new Properties(); try { InputStream pi = Servlet.class.getClassLoader().getResourceAsStream("jsvc.properties"); @@ -32,30 +25,17 @@ public class Servlet extends HttpServlet { String clnm = (String)sprop.get("jsvc.bootstrap"); if(clnm == null) throw(new ServletException("No JSvc bootstrapper specified")); + Class bc; try { - Class rc = Class.forName(clnm); - Method cm = rc.getMethod("responder"); - Object resp = cm.invoke(null); - if(!(resp instanceof Responder)) - throw(new ServletException("JSvc bootstrapper did not return a responder")); - root = (Responder)resp; + bc = Class.forName(clnm); } catch(ClassNotFoundException e) { throw(new ServletException("Invalid JSvc bootstrapper specified", e)); - } catch(NoSuchMethodException e) { - throw(new ServletException("Invalid JSvc bootstrapper specified", e)); - } catch(IllegalAccessException e) { - throw(new ServletException("Invalid JSvc bootstrapper specified", e)); - } catch(InvocationTargetException e) { - throw(new ServletException("JSvc bootstrapper failed", e)); } - ServletContext ctx = getServletContext(); - ctx.setAttribute("jsvc.starttime", System.currentTimeMillis()); + tg = new ThreadContext(null, "JSvc service", J2eeContext.create(cfg), bc); } public void destroy() { - workers.interrupt(); - if(root instanceof ContextResponder) - ((ContextResponder)root).destroy(); + tg.shutdown(); } public void service(HttpServletRequest req, HttpServletResponse resp) { @@ -65,9 +45,8 @@ public class Servlet extends HttpServlet { } catch(UnsupportedEncodingException e) { throw(new Error(e)); } - long mynum = reqs++; Request rr = new J2eeRequest(getServletConfig(), req, resp); - RequestThread w = new RequestThread(root, rr, workers, "Worker thread " + mynum); + RequestThread w = tg.respond(rr); w.start(); try { w.join();