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