commit | author | age
|
9c7249
|
1 |
/* |
U |
2 |
mc2 - Mediacenter neu |
|
3 |
Copyright (C) 2021 Ulrich Hilger |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
|
|
19 |
package de.uhilger.minsrv; |
|
20 |
|
|
21 |
import com.sun.net.httpserver.HttpServer; |
|
22 |
import de.uhilger.minsrv.handler.StopServerHandler; |
|
23 |
import de.uhilger.minsrv.handler.FileHandler; |
|
24 |
import java.io.IOException; |
|
25 |
import java.util.logging.Logger; |
|
26 |
import java.net.InetSocketAddress; |
|
27 |
import java.util.concurrent.Executors; |
|
28 |
|
|
29 |
/** |
|
30 |
* |
|
31 |
* @author ulrich |
|
32 |
*/ |
|
33 |
public class Server { |
|
34 |
|
|
35 |
private static final Logger logger = Logger.getLogger(Server.class.getName()); |
|
36 |
|
|
37 |
private int port; |
|
38 |
|
|
39 |
public Server(int port) { |
|
40 |
this.port = port; |
|
41 |
} |
|
42 |
|
|
43 |
public void setPort(int port) { |
|
44 |
this.port = port; |
|
45 |
} |
|
46 |
|
|
47 |
public void start() throws IOException { |
|
48 |
logger.info("Server starting on port " + port); |
|
49 |
|
|
50 |
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); |
|
51 |
server.createContext("/mc2/av", new FileHandler(App.getInitParameter(App.IP_WWW_DATA))); |
|
52 |
server.createContext("/mc2/server/stop", new StopServerHandler()); |
|
53 |
server.setExecutor(Executors.newFixedThreadPool(20)); |
|
54 |
server.start(); |
|
55 |
} |
|
56 |
|
|
57 |
} |