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);
15 private final Host host;
16 private final Watched port;
18 private static final ThreadPool tp = new ThreadPool(10, 100);
20 public Root(String path) {
22 host = new Host(path + File.separatorChar + "host", null);
23 port = new PortDir(path + File.separatorChar + "port");
26 public Watched slash(String part) {
27 if (part.equals("host")) return host;
28 if (part.equals("port")) return port;
29 if (part.equals("LIB")) return super.slash(part);
30 if (part.endsWith(".jar")) return super.slash(part);
34 public static void reboot() {
39 public void changed(Watched w) {
40 if (w.part.equals("host")) {
41 Log.debug(this, "/host changed");
42 } else if (w.part.equals("port")) {
43 Log.debug(this, "/port changed");
44 } else if (w.getAbsolutePath().endsWith(".jar")) {
45 if (w.lastModifiedAtLastScan != -1) {
46 Log.error(this, "jinetd upgraded; bouncing the JVM....");
50 Log.debug(this, "unknown directory " + w.part + " changed");
54 private static class PortDir extends Watched {
55 public PortDir(String path) { super(path); }
56 public Watched slash(String part) {
57 String ipaddr = part.indexOf('_') == -1 ? null : part.substring(0, part.indexOf('_'));
58 String portnum = part.indexOf('_') == -1 ? part : part.substring(part.indexOf('_') + 1);
60 return Port.newPort(this.path + File.separatorChar + part,
61 ipaddr == null ? null : InetAddress.getByName(ipaddr),
62 portnum.equals("*") ? 0 : Integer.parseInt(portnum),
64 } catch (UnknownHostException e) { Log.warn(this, "can't resolve host for port directory: " + part);
65 } catch (NumberFormatException e) { Log.warn(this, "invalid port directory: " + part);
66 } catch (Exception e) { Log.warn(this, "error instantiating Port: " + part);