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", "/jinetd");
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);
26 public static void reboot() {
31 public void changed(Watched w) {
32 if (w.part.equals("host")) {
33 Log.debug(this, "/host changed");
34 } else if (w.part.equals("port")) {
35 Log.debug(this, "/port changed");
36 } else if (w.getAbsolutePath().startsWith(Root.root + "/LIB/")) {
37 if (w.lastModifiedAtLastScan != -1) {
38 Log.error(this, "jinetd upgraded; bouncing the JVM....");
42 Log.debug(this, "unknown directory " + w.part + " changed");
46 private static class PortDir extends Watched {
47 public PortDir(String path) { super(path); }
48 public Watched slash(String part) {
49 String ipaddr = part.indexOf('_') == -1 ? null : part.substring(0, part.indexOf('_'));
50 String portnum = part.indexOf('_') == -1 ? part : part.substring(part.indexOf('_') + 1);
52 return new Port(this.path + File.separatorChar + part,
53 ipaddr == null ? null : InetAddress.getByName(ipaddr),
54 portnum.equals("*") ? 0 : Integer.parseInt(portnum));
55 } catch (UnknownHostException e) { Log.warn(this, "can't resolve host for port directory: " + part);
56 } catch (NumberFormatException e) { Log.warn(this, "invalid port directory: " + part);
57 } catch (Exception e) { Log.warn(this, "error instantiating Port: " + part);