public static void main()

in nailgun-server/src/main/java/com/facebook/nailgun/NGServer.java [433:491]


  public static void main(String[] args) throws NumberFormatException, UnknownHostException {

    if (args.length > 2) {
      usage();
      return;
    }

    // null server address means bind to everything local
    NGListeningAddress listeningAddress;
    int timeoutMillis = NGConstants.HEARTBEAT_TIMEOUT_MILLIS;

    // parse the command line parameters, which
    // may be an inetaddress to bind to, a port number,
    // an inetaddress followed by a port, separated
    // by a colon, or the string "local:/path/to/socket"
    // for a Unix domain socket or Windows named pipe.
    // if a second parameter is provided it
    // is interpreted as the number of milliseconds to
    // wait between heartbeats before considering the
    // client to have disconnected.
    if (args.length != 0) {
      String[] argParts = args[0].split(":");
      String addrPart = null;
      String portPart = null;
      if (argParts.length == 2) {
        addrPart = argParts[0];
        portPart = argParts[1];
      } else if (argParts[0].indexOf('.') >= 0) {
        addrPart = argParts[0];
      } else {
        portPart = argParts[0];
      }
      if ("local".equals(addrPart) && portPart != null) {
        // Treat the port part as a path to a local Unix domain socket
        // or Windows named pipe.
        listeningAddress = new NGListeningAddress(portPart);
      } else if (addrPart != null && portPart != null) {
        listeningAddress =
            new NGListeningAddress(InetAddress.getByName(addrPart), Integer.parseInt(portPart));
      } else if (addrPart != null && portPart == null) {
        listeningAddress =
            new NGListeningAddress(InetAddress.getByName(addrPart), NGConstants.DEFAULT_PORT);
      } else {
        listeningAddress = new NGListeningAddress(null, Integer.parseInt(portPart));
      }
      if (args.length == 2) {
        timeoutMillis = Integer.parseInt(args[1]);
      }
    } else {
      listeningAddress = new NGListeningAddress(null, NGConstants.DEFAULT_PORT);
    }

    NGServer server = new NGServer(listeningAddress, DEFAULT_SESSIONPOOLSIZE, timeoutMillis);
    Thread t = new Thread(server);
    t.setName("NGServer(" + listeningAddress.toString() + ")");
    t.start();

    Runtime.getRuntime().addShutdownHook(new NGServerShutdowner(server));
  }