-
1. Re: [JBoss MSC 1.4.x] How to get the org.jboss.msc.Service from a ServiceController?
fthiel Sep 4, 2018 7:16 AM (in response to fthiel)Ok, I've managed to work my way through some of the source code and this WildFly 14 High Availability Guide also helped. I was aiming to only use non-deprecated code but in the end I couldn't find a way to do this. So I use a mix of new and deprecated classes.
My services still implementing the deprecated interface org.jboss.msc.service.Service. In my ServiceActivator I use the new Api, these test classes jboss-msc/src/test/java/org/jboss/msc/multi_value_services at 1.4.3.Final · jboss-msc/jboss-msc · GitHub were helpful.
To get a service or better the value of a service from the ServiceContainer I found this way:
Supplier<Object> serviceSupplier = new ActiveServiceSupplier<>(serviceContainer, serviceName);
serviceSupplier.get();
This gets me the value of the specified service, but the service must implement the deprecated interface org.jboss.msc.service.Service.
-
2. Re: [JBoss MSC 1.4.x] How to get the org.jboss.msc.Service from a ServiceController?
ropalka Sep 5, 2018 9:45 AM (in response to fthiel)Hi Falco,
new MSC services API is based just on requires and provides clauses.
Obtaining services from controllers was deprecated and there is no alternative.
In case your application needs service instances then such services must allow it explicitly.
Here's simple example:
...
ServiceName HTTP_SERVER = ServiceName.of("http", "server");
ServiceName APPLICATION = ServiceName.of("application");ServiceBuilder<?> sb1 = serviceContainer.addService(HTTP_SERVER);
sb1.setInstance(new HttpServer(sb1.provides(HTTP_SERVER)));
ServiceController serverController = sb1.install();
ServiceBuilder<?> sb2 = serviceContainer.addService(APPLICATION);
sb2.setInstance(new Application(sb2.requires(HTTP_SERVER)));
ServiceController appController = sb2.install();
...private static final class HttpServer implements org.jboss.msc.Service {
private final Consumer<HttpServer> service;
private HttpServer(Consumer<HttpServer> service) { this.service = service; }public void start(StartContext context) { service.accept(this); }
public void stop(StopContext context) {}
public String getHost() { return "localhost"; }
public int getPort() { return 80; }
}
private static final class Application implements org.jboss.msc.Service {
private final Supplier<HttpServer> server;
private Application(Supplier<HttpServer> server) { this.server = server; }// the following method is obtaining Service instance in a new way (replacement for ServiceController.getService())
public void start(StartContext context) { System.out.println(server.get().getHost() + ":" + server.get().getPort()); }
public void stop(StopContext context) {}
}
-
3. Re: [JBoss MSC 1.4.x] How to get the org.jboss.msc.Service from a ServiceController?
fthiel Sep 19, 2018 4:21 AM (in response to ropalka)Hi Richard,
thank you for your reply and I'm sincerely sorry for not seeing your answer earlier.
Your explanation and your example helped me to understand the last things that were still unclear to me.