Search in sources :

Example 41 with Service

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();
}
Also used : StopContext(org.jboss.msc.service.StopContext) ExecutorService(java.util.concurrent.ExecutorService) Service(org.jboss.msc.Service) LifecycleListener(org.jboss.msc.service.LifecycleListener) StartContext(org.jboss.msc.service.StartContext) TransactionServices(org.jboss.weld.transaction.spi.TransactionServices) ExecutorServices(org.jboss.weld.manager.api.ExecutorServices) LifecycleEvent(org.jboss.msc.service.LifecycleEvent) StartException(org.jboss.msc.service.StartException)

Example 42 with Service

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);
}
Also used : FunctionalService(org.wildfly.clustering.service.FunctionalService) ServiceName(org.jboss.msc.service.ServiceName) FunctionalService(org.wildfly.clustering.service.FunctionalService) Service(org.jboss.msc.Service) ClientMapping(org.jboss.as.network.ClientMapping) CompositeDependency(org.wildfly.clustering.service.CompositeDependency)

Example 43 with 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();
}
Also used : Service(org.jboss.msc.Service) ExtensibleHttpManagement(org.jboss.as.server.mgmt.domain.ExtensibleHttpManagement)

Example 44 with Service

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);
}
Also used : FunctionalService(org.wildfly.clustering.service.FunctionalService) FunctionalService(org.wildfly.clustering.service.FunctionalService) Service(org.jboss.msc.Service)

Example 45 with 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);
}
Also used : FunctionalService(org.wildfly.clustering.service.FunctionalService) AsyncServiceConfigurator(org.wildfly.clustering.service.AsyncServiceConfigurator) FunctionalService(org.wildfly.clustering.service.FunctionalService) ExecutorService(java.util.concurrent.ExecutorService) Service(org.jboss.msc.Service) CompositeDependency(org.wildfly.clustering.service.CompositeDependency) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Aggregations

Service (org.jboss.msc.Service)76 FunctionalService (org.wildfly.clustering.service.FunctionalService)46 CompositeDependency (org.wildfly.clustering.service.CompositeDependency)26 ServiceName (org.jboss.msc.service.ServiceName)23 AsyncServiceConfigurator (org.wildfly.clustering.service.AsyncServiceConfigurator)13 Dependency (org.wildfly.clustering.service.Dependency)7 ServiceSupplierDependency (org.wildfly.clustering.service.ServiceSupplierDependency)7 SupplierDependency (org.wildfly.clustering.service.SupplierDependency)7 StartContext (org.jboss.msc.service.StartContext)4 ExecutorService (java.util.concurrent.ExecutorService)3 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)3 ServerEnvironmentService (org.jboss.as.server.ServerEnvironmentService)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 ServiceTarget (org.jboss.msc.service.ServiceTarget)3 StopContext (org.jboss.msc.service.StopContext)3 RouteLocator (org.wildfly.clustering.web.routing.RouteLocator)3 Supplier (java.util.function.Supplier)2 CapabilityServiceConfigurator (org.jboss.as.clustering.controller.CapabilityServiceConfigurator)2 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)2 CacheFactoryBuilder (org.jboss.as.ejb3.cache.CacheFactoryBuilder)2