forked from vert-x3/vertx-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VertxHttpServer.java
42 lines (31 loc) · 899 Bytes
/
VertxHttpServer.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
package io.vertx.example.osgi;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServer;
import org.apache.felix.ipojo.annotations.*;
import java.util.logging.Logger;
import static io.vertx.example.osgi.TcclSwitch.executeWithTCCLSwitch;
/**
* A component creating a Vert.x HTTP Server.
*/
@Component(immediate = true)
@Instantiate
public class VertxHttpServer {
private final static Logger LOGGER = Logger.getLogger("VertxHttpServer");
@Requires
Vertx vertx;
private HttpServer server;
@Validate
public void start() throws Exception {
LOGGER.info("Creating vertx HTTP server");
HttpServer server = executeWithTCCLSwitch(() -> vertx.createHttpServer());
server.requestHandler((r) -> {
r.response().end("Hello from OSGi !");
}).listen(8080);
}
@Invalidate
public void stop() {
if (server != null) {
server.close();
}
}
}