1 package org.ibex.jinetd;
2 import org.ibex.util.*;
7 public class Root extends Loader {
9 public static String root = System.getProperty("jinetd.root", null);
10 private final Host host;
11 private final Watched port;
13 public Root(String path) {
15 host = new Host(path + File.separatorChar + "host", null);
16 port = new PortDir(path + File.separatorChar + "port");
19 public Watched slash(String part) {
20 if (part.equals("host")) return host;
21 if (part.equals("port")) return port;
22 if (part.equals("LIB")) return super.slash(part);
23 if (part.endsWith(".jar")) return super.slash(part);
27 public static void reboot() {
32 public void changed(Watched w) {
33 if (w.part.equals("host")) {
34 Log.debug(this, "/host changed");
35 } else if (w.part.equals("port")) {
36 Log.debug(this, "/port changed");
37 } else if (w.getAbsolutePath().endsWith(".jar")) {
38 if (w.lastModifiedAtLastScan != -1) {
39 Log.error(this, "jinetd upgraded; bouncing the JVM....");
43 Log.debug(this, "unknown directory " + w.part + " changed");
47 private static class PortDir extends Watched {
48 public PortDir(String path) { super(path); }
49 public Watched slash(String part) {
50 String ipaddr = part.indexOf('_') == -1 ? null : part.substring(0, part.indexOf('_'));
51 String portnum = part.indexOf('_') == -1 ? part : part.substring(part.indexOf('_') + 1);
53 return Port.newPort(this.path + File.separatorChar + part,
54 ipaddr == null ? null : InetAddress.getByName(ipaddr),
55 portnum.equals("*") ? 0 : Integer.parseInt(portnum));
56 } catch (UnknownHostException e) { Log.warn(this, "can't resolve host for port directory: " + part);
57 } catch (NumberFormatException e) { Log.warn(this, "invalid port directory: " + part);
58 } catch (Exception e) { Log.warn(this, "error instantiating Port: " + part);