X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdolda%2Fjsvc%2FThreadContext.java;h=6eb7d87a0cd86a666bebdd897e3f67d500ff95da;hb=f05313f6190e2ddb2caaac60f7d7d242913d47b3;hp=27d90bf925c4c8a2dc2586293f5c912e332490ff;hpb=5cdd61df59fc87e9f8dbbfb0f1ea1c535a3694f9;p=jsvc.git diff --git a/src/dolda/jsvc/ThreadContext.java b/src/dolda/jsvc/ThreadContext.java index 27d90bf..6eb7d87 100644 --- a/src/dolda/jsvc/ThreadContext.java +++ b/src/dolda/jsvc/ThreadContext.java @@ -72,7 +72,10 @@ public class ThreadContext extends ThreadGroup { if(st.st == "killed") logger.log(Level.WARNING, "Thread " + rt + " refused to die; killing again"); if(now - st.lastkill > 5000) { - rt.stop(); + if(forcelimit) + rt.stop(); + else + rt.interrupt(); st.st = "killed"; st.lastkill = now; } else { @@ -115,8 +118,8 @@ public class ThreadContext extends ThreadGroup { } public void shutdown() { - if(root instanceof ContextResponder) - ((ContextResponder)root).destroy(); + if(root instanceof Destroyable) + ((Destroyable)root).destroy(); try { long last = 0; while(true) { @@ -137,7 +140,11 @@ public class ThreadContext extends ThreadGroup { } public RequestThread respond(Request req) { - return(new RequestThread(root, req, workers, "Worker thread " + reqs++)); + return(ctx.worker(root, req, workers, "Worker thread " + reqs++)); + } + + public long requests() { + return(reqs); } private Responder bootstrap(final Class bootclass) { @@ -190,4 +197,31 @@ public class ThreadContext extends ThreadGroup { } return(null); } + + public static class CreateException extends Exception { + public CreateException(String message) { + super(message); + } + + public CreateException(String message, Throwable cause) { + super(message, cause); + } + } + + public static ThreadContext create(ServerContext ctx, ClassLoader cl) throws CreateException { + String nm = "JSvc Service"; + if(ctx.name() != null) + nm = "JSvc Service for " + ctx.name(); + + String clnm = ctx.libconfig("jsvc.bootstrap", null); + if(clnm == null) + throw(new CreateException("No JSvc bootstrapper specified")); + Class bc; + try { + bc = cl.loadClass(clnm); + } catch(ClassNotFoundException e) { + throw(new CreateException("Invalid JSvc bootstrapper specified", e)); + } + return(new ThreadContext(null, nm, ctx, bc)); + } }