X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdolda%2Fjsvc%2Fj2ee%2FServlet.java;h=082113c9f0a92bc54c27b80f30bc1d5673b21d2b;hb=6a0cb6cbc9b46f7e220e27e08b9eaa8805e99d6d;hp=4d0d3bdfb268df7060c8b4df773d7d47ec8fcf5c;hpb=104fa78539da892fb3687325bde4759461d5eac4;p=jsvc.git diff --git a/src/dolda/jsvc/j2ee/Servlet.java b/src/dolda/jsvc/j2ee/Servlet.java index 4d0d3bd..082113c 100644 --- a/src/dolda/jsvc/j2ee/Servlet.java +++ b/src/dolda/jsvc/j2ee/Servlet.java @@ -8,52 +8,39 @@ 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); - } - }; - Properties sprop = new Properties(); + public void init(ServletConfig cfg) throws ServletException { + J2eeContext ctx = J2eeContext.create(cfg); try { InputStream pi = Servlet.class.getClassLoader().getResourceAsStream("jsvc.properties"); try { - sprop.load(pi); + ctx.loadconfig(pi); } finally { pi.close(); } } catch(IOException e) { throw(new Error(e)); } - String clnm = (String)sprop.get("jsvc.bootstrap"); + String clnm = ctx.libconfig("jsvc.bootstrap", null); 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)); } + String tgn; + if(ctx.name() != null) + tgn = "JSvc service for " + ctx.name(); + else + tgn = "JSvc service"; + tg = new ThreadContext(null, tgn, ctx, bc); } public void destroy() { - workers.interrupt(); - if(root instanceof ContextResponder) - ((ContextResponder)root).destroy(); + tg.shutdown(); } public void service(HttpServletRequest req, HttpServletResponse resp) { @@ -63,9 +50,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();