Search in sources :

Example 36 with Service

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

Example 37 with 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);
}
Also used : Service(org.jboss.msc.Service)

Example 38 with Service

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);
}
Also used : FunctionalService(org.wildfly.clustering.service.FunctionalService) FunctionalService(org.wildfly.clustering.service.FunctionalService) Service(org.jboss.msc.Service) DefaultSingleSignOnSessionFactory(org.wildfly.security.http.util.sso.DefaultSingleSignOnSessionFactory) SingleSignOnSessionFactory(org.wildfly.security.http.util.sso.SingleSignOnSessionFactory) CompositeDependency(org.wildfly.clustering.service.CompositeDependency)

Example 39 with 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);
    }
}
Also used : StopContext(org.jboss.msc.service.StopContext) ExecutorService(java.util.concurrent.ExecutorService) Service(org.jboss.msc.Service) LifecycleListener(org.jboss.msc.service.LifecycleListener) CompletableFuture(java.util.concurrent.CompletableFuture) StartContext(org.jboss.msc.service.StartContext) LifecycleEvent(org.jboss.msc.service.LifecycleEvent) ServiceController(org.jboss.msc.service.ServiceController) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 40 with Service

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

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