forked from vert-x3/vertx-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VertxActivator.java
45 lines (36 loc) · 1.39 KB
/
VertxActivator.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
package io.vertx.example.osgi;
import io.vertx.core.Vertx;
import io.vertx.core.eventbus.EventBus;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import java.util.logging.Logger;
import static io.vertx.example.osgi.TcclSwitch.executeWithTCCLSwitch;
/**
* A bundle activator registering the Vert.x instance and the event bus as OSGi service.
*/
public class VertxActivator implements BundleActivator {
private final static Logger LOGGER = Logger.getLogger("VertxPublisher");
private ServiceRegistration<Vertx> vertxRegistration;
private ServiceRegistration<EventBus> ebRegistration;
@Override
public void start(BundleContext context) throws Exception {
LOGGER.info("Creating Vert.x instance");
Vertx vertx = executeWithTCCLSwitch(() -> Vertx.vertx());
vertxRegistration = context.registerService(Vertx.class, vertx, null);
LOGGER.info("Vert.x service registered");
ebRegistration = context.registerService(EventBus.class, vertx.eventBus(), null);
LOGGER.info("Vert.x Event Bus service registered");
}
@Override
public void stop(BundleContext context) throws Exception {
if (vertxRegistration != null) {
vertxRegistration.unregister();
vertxRegistration = null;
}
if (ebRegistration != null) {
ebRegistration.unregister();
ebRegistration = null;
}
}
}