1 package org.ibex.jinetd;
2 import org.ibex.util.*;
7 public class Root extends Loader {
9 private final Host host;
10 private final Watched port;
12 public Root(String path) {
14 host = new Host(path + File.separatorChar + "host", null);
15 port = new PortDir(path + File.separatorChar + "port");
18 public Watched slash(String part) {
19 if (part.equals("host")) return host;
20 if (part.equals("port")) return port;
21 if (part.equals("LIB")) return super.slash(part);
25 public static void reboot() {
30 public void changed(Watched w) {
31 if (w.part.equals("host")) {
32 Log.warn(this, "/host changed");
33 } else if (w.part.equals("port")) {
34 Log.warn(this, "/port changed");
35 } else if (w.getAbsolutePath().startsWith("/jinetd/LIB/")) {
36 if (w.lastModifiedAtLastScan != -1) {
37 Log.error(this, "jinetd upgraded; bouncing the JVM....");
41 Log.info(this, "unknown directory " + w.part + " changed");
45 private static class PortDir extends Watched {
46 public PortDir(String path) { super(path); }
47 public Watched slash(String part) {
48 String ipaddr = part.indexOf(':') == -1 ? null : part.substring(0, part.indexOf(':'));
49 String portnum = part.indexOf(':') == -1 ? part : part.substring(part.indexOf(':') + 1);
51 return new Port(this.path + File.separatorChar + part,
52 ipaddr == null ? null : NetworkInterface.getByInetAddress(InetAddress.getByName(ipaddr)),
53 portnum.equals("*") ? 0 : Integer.parseInt(portnum));
54 } catch (UnknownHostException e) { Log.warn(this, "can't resolve host for port directory: " + part);
55 } catch (NumberFormatException e) { Log.warn(this, "invalid port directory: " + part);
56 } catch (Exception e) { Log.warn(this, "error instantiating Port: " + part);