use of org.jboss.msc.Service in project wildfly by wildfly.
the class WeldBootstrapService method start.
/**
* Starts the weld container
*
* @throws IllegalStateException if the container is already running
*/
public synchronized void start(final StartContext context) {
if (!runOnce.compareAndSet(false, true)) {
ServiceController<?> controller = context.getController().getServiceContainer().getService(deploymentServiceName);
controller.addListener(new LifecycleListener() {
@Override
public void handleEvent(final ServiceController<?> controller, final LifecycleEvent event) {
if (event == LifecycleEvent.DOWN) {
controller.setMode(ServiceController.Mode.ACTIVE);
controller.removeListener(this);
}
}
});
controller.setMode(ServiceController.Mode.NEVER);
return;
}
if (started) {
throw WeldLogger.ROOT_LOGGER.alreadyRunning("WeldContainer");
}
started = true;
WeldLogger.DEPLOYMENT_LOGGER.startingWeldService(deploymentName);
// set up injected services
addWeldService(SecurityServices.class, securityServicesSupplier.get());
TransactionServices transactionServices = weldTransactionServicesSupplier != null ? weldTransactionServicesSupplier.get() : null;
if (transactionServices != null) {
addWeldService(TransactionServices.class, transactionServices);
}
if (!deployment.getServices().contains(ExecutorServices.class)) {
addWeldService(ExecutorServices.class, executorServicesSupplier.get());
}
ModuleGroupSingletonProvider.addClassLoaders(deployment.getModule().getClassLoader(), deployment.getSubDeploymentClassLoaders());
ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(deployment.getModule().getClassLoader());
bootstrap.startContainer(deploymentName, environment, deployment);
WeldProvider.containerInitialized(Container.instance(deploymentName), getBeanManager(), deployment);
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
}
weldBootstrapServiceConsumer.accept(this);
// this is the actual service that clients depend on
// we install it here so that if a restart needs to happen all our dependants won't be able to start
final ServiceBuilder<?> weldBootstrapServiceBuilder = context.getChildTarget().addService(weldBootstrapServiceName);
Consumer<WeldBootstrapService> provider = weldBootstrapServiceBuilder.provides(weldBootstrapServiceName);
weldBootstrapServiceBuilder.setInstance(new Service() {
@Override
public void start(StartContext context) throws StartException {
provider.accept(WeldBootstrapService.this);
}
@Override
public void stop(StopContext context) {
context.getController().setMode(ServiceController.Mode.REMOVE);
}
});
weldBootstrapServiceBuilder.install();
controller = context.getController();
}
use of org.jboss.msc.Service in project wildfly by wildfly.
the class EJBRemotingConnectorClientMappingsEntryProviderService method build.
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceName name = this.getServiceName();
ServiceBuilder<?> builder = target.addService(name);
Consumer<Map.Entry<String, List<ClientMapping>>> entry = new CompositeDependency(this.group, this.remotingConnectorInfo).register(builder).provides(name);
Service service = new FunctionalService<>(entry, Function.identity(), this);
return builder.setInstance(service);
}
use of org.jboss.msc.Service in project wildfly by wildfly.
the class MetricsContextService method install.
static void install(OperationContext context, boolean securityEnabled) {
ServiceBuilder<?> serviceBuilder = context.getServiceTarget().addService(METRICS_HTTP_CONTEXT_CAPABILITY.getCapabilityServiceName());
Supplier<ExtensibleHttpManagement> extensibleHttpManagement = serviceBuilder.requires(context.getCapabilityServiceName(HTTP_EXTENSIBILITY_CAPABILITY, ExtensibleHttpManagement.class));
Supplier<WildFlyMetricRegistry> wildflyMetricRegistry = serviceBuilder.requires(METRICS_REGISTRY_RUNTIME_CAPABILITY.getCapabilityServiceName());
Consumer<MetricsContextService> metricsContext = serviceBuilder.provides(METRICS_HTTP_CONTEXT_CAPABILITY.getCapabilityServiceName());
final Supplier<Boolean> securityEnabledSupplier;
if (context.getCapabilityServiceSupport().hasCapability(METRICS_HTTP_SECURITY_CAPABILITY)) {
securityEnabledSupplier = serviceBuilder.requires(ServiceName.parse(METRICS_HTTP_SECURITY_CAPABILITY));
} else {
securityEnabledSupplier = new Supplier<Boolean>() {
@Override
public Boolean get() {
return securityEnabled;
}
};
}
Service metricsContextService = new MetricsContextService(metricsContext, extensibleHttpManagement, wildflyMetricRegistry, securityEnabledSupplier);
serviceBuilder.setInstance(metricsContextService).install();
}
use of org.jboss.msc.Service in project wildfly by wildfly.
the class AbstractModulesServiceConfigurator method build.
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = target.addService(this.getServiceName());
Consumer<T> modules = this.loader.register(builder).provides(this.getServiceName());
Service service = new FunctionalService<>(modules, this, this);
return builder.setInstance(service);
}
use of org.jboss.msc.Service in project wildfly by wildfly.
the class CacheContainerServiceConfigurator method build.
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = new AsyncServiceConfigurator(this.getServiceName()).build(target);
Consumer<EmbeddedCacheManager> container = new CompositeDependency(this.configuration).register(builder).provides(this.names);
Service service = new FunctionalService<>(container, this, this, this);
return builder.setInstance(service).setInitialMode(ServiceController.Mode.PASSIVE);
}
Aggregations