commit | author | age
|
8e2038
|
1 |
package de.uhilger.avdirektor; |
U |
2 |
|
|
3 |
import com.sun.net.httpserver.HttpServer; |
0c8d27
|
4 |
import de.uhilger.avdirektor.handler.PingHandler; |
8e2038
|
5 |
import de.uhilger.avdirektor.handler.PlayHandler; |
0c8d27
|
6 |
import de.uhilger.avdirektor.handler.StopHandler; |
8e2038
|
7 |
import de.uhilger.avdirektor.handler.StopServerHandler; |
U |
8 |
import java.io.IOException; |
|
9 |
import java.util.logging.Logger; |
|
10 |
import java.net.InetSocketAddress; |
|
11 |
|
|
12 |
/** |
|
13 |
* |
|
14 |
* @author ulrich |
|
15 |
*/ |
|
16 |
public class Server { |
|
17 |
|
|
18 |
private static final Logger logger = Logger.getLogger(Server.class.getName()); |
|
19 |
|
|
20 |
|
|
21 |
private int port; |
|
22 |
|
|
23 |
public Server(int port) { |
|
24 |
this.port = port; |
|
25 |
} |
|
26 |
|
|
27 |
public void setPort(int port) { |
|
28 |
this.port = port; |
|
29 |
} |
|
30 |
|
|
31 |
public void start() throws IOException { |
|
32 |
logger.info("Server starting on port " + port); |
0c8d27
|
33 |
|
U |
34 |
StopHandler sh = new StopHandler(); |
|
35 |
sh.setCmd(App.CMD_STOP); |
|
36 |
|
8e2038
|
37 |
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); |
U |
38 |
server.createContext("/avd/play", new PlayHandler()); |
0c8d27
|
39 |
server.createContext("/avd/stop", sh); |
U |
40 |
server.createContext("/avd/ping", new PingHandler()); |
8e2038
|
41 |
server.createContext("/avd/server/stop", new StopServerHandler()); |
U |
42 |
server.setExecutor(null); // creates a default executor |
|
43 |
server.start(); |
|
44 |
} |
|
45 |
|
|
46 |
} |