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