Logo Search packages:      
Sourcecode: nailgun version File versions  Download package

static void com::martiansoftware::nailgun::NGServer::main ( String[]  args  )  throws NumberFormatException, UnknownHostException [inline, static]

Creates and starts a new NGServer. A single optional argument is valid, specifying the port on which this NGServer should listen. If omitted, NGServer.DEFAULT_PORT will be used.

Parameters:
args a single optional argument specifying the port on which to listen.
Exceptions:
NumberFormatException if a non-numeric port is specified

Definition at line 411 of file NGServer.java.

References getPort(), NGServer(), and port.

                                                                                                {

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

            // null server address means bind to everything local
            InetAddress serverAddress = null;
            int port = NGConstants.DEFAULT_PORT;
            
            // parse the sole command line parameter, which
            // may be an inetaddress to bind to, a port number,
            // or an inetaddress followed by a port, separated
            // by a colon
            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 (addrPart != null) {
                        serverAddress = InetAddress.getByName(addrPart);
                  }
                  if (portPart != null) {
                        port = Integer.parseInt(portPart);
                  }
            }

            NGServer server = new NGServer(serverAddress, port);
            Thread t = new Thread(server);
            t.setName("NGServer(" + serverAddress + ", " + port + ")");
            t.start();

            Runtime.getRuntime().addShutdownHook(new NGServerShutdowner(server));
            
            // if the port is 0, it will be automatically determined.
            // add this little wait so the ServerSocket can fully
            // initialize and we can see what port it chose.
            int runningPort = server.getPort();
            while (runningPort == 0) {
                  try { Thread.sleep(50); } catch (Throwable toIgnore) {}
                  runningPort = server.getPort();
            }
            
            System.out.println("NGServer started on "
                                          + ((serverAddress == null) 
                                                ? "all interfaces" 
                                                : serverAddress.getHostAddress())
                                + ", port " 
                                          + runningPort 
                                          + ".");
      }


Generated by  Doxygen 1.6.0   Back to index