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