return(ctx.worker(root, req, workers, "Worker thread " + reqs++));
}
+ public long requests() {
+ return(reqs);
+ }
+
private Responder bootstrap(final Class<?> bootclass) {
final Throwable[] err = new Throwable[1];
final Responder[] res = new Responder[1];
--- /dev/null
+package dolda.jsvc.jmx;
+
+import javax.management.*;
+import java.util.*;
+import dolda.jsvc.*;
+
+public class Context implements ContextMBean {
+ public final ObjectName name;
+ private final ThreadContext b;
+
+ public Context(ThreadContext ctx) {
+ this.b = ctx;
+ Hashtable<String, String> info = new Hashtable<String, String>();
+ info.put("type", "Context");
+ info.put("name", getname());
+ try {
+ name = new ObjectName("dolda.jsvc", info);
+ } catch(MalformedObjectNameException e) {
+ throw(new RuntimeException(e));
+ }
+ }
+
+ public long getrequests() {
+ return(b.requests());
+ }
+
+ public String getname() {
+ return(b.server().name());
+ }
+}
--- /dev/null
+package dolda.jsvc.jmx;
+
+public interface ContextMBean {
+ public String getname();
+ public long getrequests();
+}
public final long mtime;
public final ThreadContext tg;
private final Environment env;
+ public final dolda.jsvc.jmx.Context mbean;
private static String mangle(File f) {
String ret = f.getName();
this.env = env;
loadconfig();
this.tg = ThreadContext.create(this, loader);
+ mbean = new dolda.jsvc.jmx.Context(tg);
}
private void loadconfig() {
import dolda.jsvc.*;
import dolda.jsvc.util.*;
import dolda.jsvc.j2ee.PosixArgs;
+import java.lang.management.ManagementFactory;
+import javax.management.*;
public class DirServer extends Server {
private final Map<File, DSContext> contexts = new HashMap<File, DSContext>();
- private final Environment env;
+ public final Environment env;
private final Logger logger = Logger.getLogger("dolda.jsvc.scgi.dirserver");
private Thread sdhook = null, main = null;
if(ctx != null) {
if(ctx.mtime < file.lastModified()) {
ctx.tg.shutdown();
+ try {
+ ManagementFactory.getPlatformMBeanServer().unregisterMBean(ctx.mbean.name);
+ } catch(InstanceNotFoundException e) {
+ } catch(MBeanRegistrationException e) {
+ }
contexts.remove(file);
ctx = null;
act = "reloaded %s as %s";
}
if(ctx == null) {
ctx = new DSContext(file, env);
+ try {
+ ManagementFactory.getPlatformMBeanServer().registerMBean(ctx.mbean, ctx.mbean.name);
+ } catch(InstanceAlreadyExistsException e) {
+ } catch(MBeanRegistrationException e) {
+ } catch(NotCompliantMBeanException e) {
+ }
contexts.put(file, ctx);
logger.config(String.format(act, file, ctx.name()));
}
}
}
super.shutdown();
+ try {
+ ManagementFactory.getPlatformMBeanServer().unregisterMBean(dolda.jsvc.scgi.jmx.Server.name);
+ } catch(InstanceNotFoundException e) {
+ } catch(MBeanRegistrationException e) {
+ }
}
private static void usage(PrintStream out) {
return; /* Because javac is stupid. :-/ */
}
DirServer s = new DirServer(sk, env);
+ try {
+ ManagementFactory.getPlatformMBeanServer().registerMBean(new dolda.jsvc.scgi.jmx.Server(s), dolda.jsvc.scgi.jmx.Server.name);
+ } catch(InstanceAlreadyExistsException e) {
+ } catch(MBeanRegistrationException e) {
+ } catch(NotCompliantMBeanException e) {
+ }
if(charset != null)
s.headcs = charset;
--- /dev/null
+package dolda.jsvc.scgi.jmx;
+
+import javax.management.*;
+import dolda.jsvc.scgi.*;
+
+public class Server implements ServerMBean {
+ public static final ObjectName name;
+ private final DirServer b;
+
+ static {
+ try {
+ name = new ObjectName("dolda.jsvc", "type", "ScgiServer");
+ } catch(MalformedObjectNameException e) {
+ throw(new RuntimeException(e));
+ }
+ }
+
+ public Server(DirServer b) {
+ this.b = b;
+ }
+
+ public String getdataroot() {
+ return(b.env.root.getPath());
+ }
+}
--- /dev/null
+package dolda.jsvc.scgi.jmx;
+
+public interface ServerMBean {
+ public String getdataroot();
+}