Pluggable argument with reference to port
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 07 Sep 2009 17:43:43 +0200
changeset 6833cf89760fab
parent 67 f5741fe21fe6
child 69 90de58894949
Pluggable argument with reference to port
freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java
freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/UITest.java
     1.1 --- a/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java	Mon Sep 07 17:03:46 2009 +0200
     1.2 +++ b/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java	Mon Sep 07 17:43:43 2009 +0200
     1.3 @@ -193,22 +193,33 @@
     1.4      //
     1.5  
     1.6      public static void main(String[] args) throws Exception {
     1.7 -        Callable<Void> r = startServers();
     1.8 +        int port = 9998;
     1.9 +        if (args.length > 1) {
    1.10 +            port = Integer.parseInt(args[0]);
    1.11 +        }
    1.12  
    1.13 -        System.in.read();
    1.14 +
    1.15 +        Callable<Void> r = startServers(port);
    1.16 +
    1.17 +        if (args.length > 2 && args[1].equals("--kill")) {
    1.18 +            System.out.println("Hit enter to stop it...");
    1.19 +            System.in.read();
    1.20 +        } else {
    1.21 +            synchronized (UI.class) {
    1.22 +                UI.class.wait();
    1.23 +            }
    1.24 +        }
    1.25          r.call();
    1.26          System.exit(0);
    1.27      }
    1.28  
    1.29 -    static Callable<Void> startServers() throws Exception {
    1.30 -        final HttpServer api = Quoridor.start(9998);
    1.31 +    static Callable<Void> startServers(int port) throws Exception {
    1.32 +        final HttpServer api = Quoridor.start(port + 1);
    1.33          Client client = new Client();
    1.34 -        base = client.resource(new URI("http://localhost:9998/api/"));
    1.35 +        base = client.resource(new URI("http://localhost:" + (port + 1) + "/api/"));
    1.36  
    1.37 -        final HttpServer s = start(9997);
    1.38 -        System.out.println(
    1.39 -            "Quoridor started at port 9997\n" + "Hit enter to stop it..."
    1.40 -        );
    1.41 +        final HttpServer s = start(port);
    1.42 +        System.out.println("Quoridor started at port " + port);
    1.43  
    1.44          return new Callable<Void>() {
    1.45              public Void call() throws Exception {
     2.1 --- a/freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/UITest.java	Mon Sep 07 17:03:46 2009 +0200
     2.2 +++ b/freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/UITest.java	Mon Sep 07 17:43:43 2009 +0200
     2.3 @@ -63,10 +63,10 @@
     2.4          dir = File.createTempFile("quoridor", ".dir");
     2.5          dir.delete();
     2.6          System.setProperty("quoridor.dir", dir.getPath());
     2.7 -        stop = UI.startServers();
     2.8 +        stop = UI.startServers(9991);
     2.9  
    2.10          Client client = new Client();
    2.11 -        webResource = client.resource(new URI("http://localhost:9997/"));
    2.12 +        webResource = client.resource(new URI("http://localhost:9991/"));
    2.13      }
    2.14  
    2.15      @After