-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project2Application.java
59 lines (47 loc) · 2.19 KB
/
Project2Application.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package sk.stuba.fei.uim.vsa.pr2;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.logging.LoggingFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sk.stuba.fei.uim.vsa.pr2.service.ThesisService;
import java.net.URI;
import java.util.logging.Level;
import static sk.stuba.fei.uim.vsa.pr2.ApplicationConfiguration.BASE_URI;
public class Project2Application {
private static final Logger log = LoggerFactory.getLogger(Project2Application.class);
public static HttpServer startServer() {
final ResourceConfig rc = ResourceConfig.forApplicationClass(JAXRSApplicationConfiguration.class);
// rc.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME),
// Level.FINEST, LoggingFeature.Verbosity.PAYLOAD_ANY, 99999));
log.info("Starting Grizzly2 HTTP server...");
log.info("Server listening on " + BASE_URI);
return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
}
public static void main(String[] args) {
try {
final HttpServer server = startServer();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
ThesisService.getInstance().close();
log.info("Shutting down the application...");
server.shutdownNow();
log.info("Exiting");
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}));
log.info("Last steps of setting up the application...");
postStart();
log.info(String.format("Application started.%nStop the application using CRL+C"));
Thread.currentThread().join();
} catch (InterruptedException e) {
log.error(e.getMessage(), e);
}
}
public static void postStart() {
// TODO sem napíš akékoľvek nastavenia, či volania, ktoré sa majú udiať ihneď po štarte servera
ThesisService.getInstance();
}
}