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