diff -r 40fc213a7f43 -r 90be53f96e0c webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Quoridor.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Quoridor.java Fri Apr 15 21:18:29 2011 +0200 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Quoridor.java Sun Jul 17 15:40:50 2011 +0200 @@ -18,19 +18,16 @@ package cz.xelfi.quoridor.webidor.resources; -import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory; -import com.sun.jersey.api.core.PackagesResourceConfig; -import com.sun.jersey.api.core.ResourceConfig; import com.sun.jersey.api.json.JSONWithPadding; -import com.sun.jersey.spi.resource.Singleton; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.net.ServerSocket; import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.UUID; +import javax.annotation.ManagedBean; +import javax.inject.Singleton; import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; @@ -39,7 +36,6 @@ import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response.Status; -import org.glassfish.grizzly.http.server.HttpServer; /** * @@ -47,16 +43,17 @@ */ @Path("/") @Singleton -public final class Quoridor { +@ManagedBean +public class Quoridor { private final File path; private Games games; private Users users; private final Map loggedIn; public Quoridor() { - final String prop = System.getProperty("quoridor.dir"); // NOI18N + String prop = System.getProperty("quoridor.dir"); // NOI18N if (prop == null) { - throw new IllegalStateException("quoridor.dir property must be specified"); // NOI18N + prop = System.getProperty("user.dir") + File.separatorChar + ".quoridor"; // NOI18N } path = new File(prop); path.mkdirs(); @@ -144,53 +141,4 @@ return getUsers().getUserInfo(callback, id, ret); } } - - // - // start the server - // - - public static void main(String[] args) throws IOException, InterruptedException { - int port = 9222; - try { - port = Integer.parseInt(args[0]); - } catch (Exception ex) { - // OK - } - HttpServer s = start(port); - System.out.println( - "Quoridor started at port " + port + "\n" + "Hit enter to stop it..." - ); - if (args.length < 2 || !args[args.length - 1].equals("--kill")) { - System.out.println("Hit enter to stop it..."); - System.in.read(); - } else { - synchronized (Quoridor.class) { - Quoridor.class.wait(); - } - } - System.in.read(); - s.stop(); - System.exit(0); - } - - public static HttpServer start(int port) throws IOException { - if (port == -1) { - ServerSocket ss = new ServerSocket(0); - port =ss.getLocalPort(); - ss.close(); - } - final String baseUri = "http://localhost:" + port + "/"; - - if (System.getProperty("quoridor.dir") == null) { - File home = new File(System.getProperty("user.home")); - File quoridor = new File(home, ".quoridor"); - System.setProperty("quoridor.dir", quoridor.getPath()); - } - - ResourceConfig rc = new PackagesResourceConfig("cz.xelfi.quoridor.webidor"); - HttpServer server = GrizzlyServerFactory.createHttpServer(baseUri, rc); - server.start(); - return server; - } - }