1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
5 package org.ibex.jinetd;
6 import org.ibex.util.*;
11 public class Root extends Loader {
13 public static String root = System.getProperty("jinetd.root", null);
14 private final Host host;
15 private final Watched port;
17 public Root(String path) {
19 host = new Host(path + File.separatorChar + "host", null);
20 port = new PortDir(path + File.separatorChar + "port");
23 public Watched slash(String part) {
24 if (part.equals("host")) return host;
25 if (part.equals("port")) return port;
26 if (part.equals("LIB")) return super.slash(part);
27 if (part.endsWith(".jar")) return super.slash(part);
31 public static void reboot() {
36 public void changed(Watched w) {
37 if (w.part.equals("host")) {
38 Log.debug(this, "/host changed");
39 } else if (w.part.equals("port")) {
40 Log.debug(this, "/port changed");
41 } else if (w.getAbsolutePath().endsWith(".jar")) {
42 if (w.lastModifiedAtLastScan != -1) {
43 Log.error(this, "jinetd upgraded; bouncing the JVM....");
47 Log.debug(this, "unknown directory " + w.part + " changed");
51 private static class PortDir extends Watched {
52 public PortDir(String path) { super(path); }
53 public Watched slash(String part) {
54 String ipaddr = part.indexOf('_') == -1 ? null : part.substring(0, part.indexOf('_'));
55 String portnum = part.indexOf('_') == -1 ? part : part.substring(part.indexOf('_') + 1);
57 return Port.newPort(this.path + File.separatorChar + part,
58 ipaddr == null ? null : InetAddress.getByName(ipaddr),
59 portnum.equals("*") ? 0 : Integer.parseInt(portnum));
60 } catch (UnknownHostException e) { Log.warn(this, "can't resolve host for port directory: " + part);
61 } catch (NumberFormatException e) { Log.warn(this, "invalid port directory: " + part);
62 } catch (Exception e) { Log.warn(this, "error instantiating Port: " + part);