use of org.jboss.msc.Service in project wildfly by wildfly.
the class LocalSingletonServiceConfiguratorFactoryServiceConfigurator method build.
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = target.addService(this.getServiceName());
Consumer<SingletonServiceConfiguratorFactory> factory = builder.provides(this.getServiceName());
Service service = Service.newInstance(factory, new LocalSingletonServiceBuilderFactory(this));
return builder.setInstance(service);
}
use of org.jboss.msc.Service in project wildfly by wildfly.
the class IdentityServiceConfigurator method build.
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = target.addService(this.getServiceName());
Consumer<T> injector = builder.provides(this.getServiceName());
Supplier<T> requirement = builder.requires(this.requirementName);
Service service = new FunctionalService<>(injector, Function.identity(), requirement);
return builder.setInstance(service).setInitialMode(this.initialMode);
}
use of org.jboss.msc.Service in project wildfly by wildfly.
the class SingleSignOnSessionFactoryServiceConfigurator method build.
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = target.addService(this.getServiceName());
Consumer<SingleSignOnSessionFactory> factory = new CompositeDependency(this.manager, this.keyStore, this.credentialSource, this.sslContext).register(builder).provides(this.getServiceName());
Service service = new FunctionalService<>(factory, Function.identity(), this);
return builder.setInstance(service);
}
use of org.jboss.msc.Service in project wildfly by wildfly.
the class WeldBootstrapService method startServiceShutdown.
void startServiceShutdown() {
// the start service has been shutdown, which means either we are being shutdown/undeployed
// or we are going to need to bounce the whole deployment
this.started = false;
if (controller.getServiceContainer().isShutdown()) {
// container is being shutdown, no action required
return;
}
ServiceController<?> deploymentController = controller.getServiceContainer().getService(deploymentServiceName);
if (deploymentController.getMode() != ServiceController.Mode.ACTIVE) {
// deployment is not active, no action required
return;
}
// add a listener to tentatively 'bounce' this service
// if the service does actually restart then this will trigger a full deployment restart
// we do it this way as we don't have visibility into MSC in the general sense
// so we don't really know if this service is supposed to go away
// this 'potential bounce' is hard to do in a non-racey manner
// we need to add the listener first, but the listener may be invoked before the CAS to never
CompletableFuture<Boolean> attemptingBounce = new CompletableFuture();
try {
CompletableFuture<Boolean> listenerDone = new CompletableFuture<>();
LifecycleListener listener = new LifecycleListener() {
@Override
public void handleEvent(final ServiceController<?> controller, final LifecycleEvent event) {
try {
try {
if (controller.getServiceContainer().isShutdown() || !attemptingBounce.get()) {
controller.removeListener(this);
return;
}
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
if (deploymentController.getMode() != ServiceController.Mode.ACTIVE || controller.getMode() == ServiceController.Mode.REMOVE) {
return;
}
if (event == LifecycleEvent.DOWN) {
controller.removeListener(this);
do {
if (controller.getMode() != ServiceController.Mode.NEVER) {
return;
}
} while (!controller.compareAndSetMode(ServiceController.Mode.NEVER, ServiceController.Mode.ACTIVE));
}
} finally {
listenerDone.complete(true);
}
}
};
//
controller.getServiceContainer().addService(controller.getName().append("fakeStabilityService")).setInstance(new Service() {
@Override
public void start(StartContext context) throws StartException {
context.asynchronous();
listenerDone.handle(new BiFunction<Boolean, Throwable, Object>() {
@Override
public Object apply(Boolean aBoolean, Throwable throwable) {
context.getController().setMode(ServiceController.Mode.REMOVE);
context.complete();
return null;
}
});
}
@Override
public void stop(StopContext context) {
}
}).install();
controller.addListener(listener);
if (!controller.compareAndSetMode(ServiceController.Mode.ACTIVE, ServiceController.Mode.NEVER)) {
controller.removeListener(listener);
attemptingBounce.complete(false);
listenerDone.complete(false);
} else {
attemptingBounce.complete(true);
}
} catch (Throwable t) {
// should never happen
// but lets be safe
attemptingBounce.completeExceptionally(t);
throw new RuntimeException(t);
}
}
use of org.jboss.msc.Service in project wildfly by wildfly.
the class SimpleSessionIdentifierCodecServiceConfigurator method build.
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = target.addService(this.getServiceName());
Consumer<SessionIdentifierCodec> codec = this.server.register(builder).provides(this.getServiceName());
Service service = new FunctionalService<>(codec, this, this.server);
return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
Aggregations