Search in sources :

Example 6 with StopContext

use of org.jboss.msc.service.StopContext in project wildfly by wildfly.

the class JaegerTracerConfigurationAddHandler method performRuntime.

@Override
@SuppressWarnings("unchecked")
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    super.performRuntime(context, operation, model);
    CapabilityServiceBuilder builder = context.getCapabilityServiceTarget().addCapability(TRACER_CAPABILITY);
    String outboundSocketBindingName = TracerAttributes.SENDER_BINDING.resolveModelAttribute(context, model).asStringOrNull();
    Supplier<OutboundSocketBinding> outboundSocketBindingSupplier;
    if (outboundSocketBindingName != null) {
        outboundSocketBindingSupplier = builder.requiresCapability(OUTBOUND_SOCKET_BINDING_CAPABILITY_NAME, OutboundSocketBinding.class, outboundSocketBindingName);
    } else {
        outboundSocketBindingSupplier = () -> null;
    }
    TracerConfiguration config = new JaegerTracerConfiguration(context, context.getCurrentAddressValue(), operation, outboundSocketBindingSupplier);
    Consumer<TracerConfiguration> injector = builder.provides(TRACER_CAPABILITY);
    builder.setInstance(new Service() {

        @Override
        public void start(StartContext context) {
            injector.accept(config);
            WildFlyTracerFactory.registerTracer(config.getName()).accept(config);
        }

        @Override
        public void stop(StopContext context) {
            WildFlyTracerFactory.registerTracer(config.getName()).accept(null);
        }
    });
    builder.setInitialMode(ON_DEMAND).install();
}
Also used : JaegerTracerConfiguration(org.wildfly.extension.microprofile.opentracing.resolver.JaegerTracerConfiguration) CapabilityServiceBuilder(org.jboss.as.controller.CapabilityServiceBuilder) StopContext(org.jboss.msc.service.StopContext) StartContext(org.jboss.msc.service.StartContext) OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) TracerConfiguration(org.wildfly.microprofile.opentracing.smallrye.TracerConfiguration) JaegerTracerConfiguration(org.wildfly.extension.microprofile.opentracing.resolver.JaegerTracerConfiguration) Service(org.jboss.msc.Service)

Example 7 with StopContext

use of org.jboss.msc.service.StopContext in project wildfly by wildfly.

the class SubsystemAdd method performBoottime.

@Override
protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    WildFlyTracerFactory.registerTracer(ENV_TRACER).accept(new JaegerEnvTracerConfiguration());
    TracingExtensionLogger.ROOT_LOGGER.activatingSubsystem();
    String defaultTracer = DEFAULT_TRACER.resolveModelAttribute(context, operation).asStringOrNull();
    if (defaultTracer != null && !defaultTracer.isEmpty()) {
        CapabilityServiceBuilder<?> builder = context.getCapabilityServiceTarget().addCapability(DEFAULT_TRACER_CAPABILITY);
        final Supplier<TracerConfiguration> config = builder.requiresCapability(TRACER_CAPABILITY_NAME, TracerConfiguration.class, defaultTracer);
        final Consumer<TracerConfiguration> injector = builder.provides(DEFAULT_TRACER_CAPABILITY);
        builder.setInstance(new Service() {

            @Override
            public void start(StartContext context) throws StartException {
                injector.accept(config.get());
                WildFlyTracerFactory.registerDefaultTracer().accept(config.get());
            }

            @Override
            public void stop(StopContext context) {
                injector.accept(null);
                WildFlyTracerFactory.registerDefaultTracer().accept(config.get());
            }
        }).setInitialMode(ServiceController.Mode.ACTIVE).install();
    }
    context.addStep(new AbstractDeploymentChainStep() {

        @Override
        public void execute(DeploymentProcessorTarget processorTarget) {
            processorTarget.addDeploymentProcessor(SubsystemExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_MICROPROFILE_OPENTRACING, new TracingDependencyProcessor());
            processorTarget.addDeploymentProcessor(SubsystemExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_MICROPROFILE_OPENTRACING, new TracingDeploymentProcessor());
        }
    }, OperationContext.Stage.RUNTIME);
}
Also used : StopContext(org.jboss.msc.service.StopContext) TracerConfiguration(org.wildfly.microprofile.opentracing.smallrye.TracerConfiguration) JaegerEnvTracerConfiguration(org.wildfly.extension.microprofile.opentracing.resolver.JaegerEnvTracerConfiguration) Service(org.jboss.msc.Service) JaegerEnvTracerConfiguration(org.wildfly.extension.microprofile.opentracing.resolver.JaegerEnvTracerConfiguration) StartContext(org.jboss.msc.service.StartContext) DeploymentProcessorTarget(org.jboss.as.server.DeploymentProcessorTarget) StartException(org.jboss.msc.service.StartException) AbstractDeploymentChainStep(org.jboss.as.server.AbstractDeploymentChainStep)

Example 8 with StopContext

use of org.jboss.msc.service.StopContext 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 9 with StopContext

use of org.jboss.msc.service.StopContext in project wildfly-camel by wildfly-extras.

the class CamelContextFactoryBindingService method addService.

public static ServiceController<?> addService(final ServiceTarget serviceTarget) {
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(CamelConstants.CAMEL_CONTEXT_FACTORY_BINDING_NAME);
    BinderService binderService = new BinderService(bindInfo.getBindName()) {

        @Override
        public synchronized void start(StartContext context) throws StartException {
            super.start(context);
            LOGGER.info("Bound camel naming object: {}", bindInfo.getAbsoluteJndiName());
        }

        @Override
        public synchronized void stop(StopContext context) {
            LOGGER.debug("Unbind camel naming object: {}", bindInfo.getAbsoluteJndiName());
            super.stop(context);
        }
    };
    Injector<ManagedReferenceFactory> injector = binderService.getManagedObjectInjector();
    ServiceBuilder<?> builder = serviceTarget.addService(bindInfo.getBinderServiceName(), binderService);
    builder.addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector());
    builder.addDependency(CamelConstants.CAMEL_CONTEXT_FACTORY_SERVICE_NAME, CamelContextFactory.class, new ManagedReferenceInjector<CamelContextFactory>(injector));
    return builder.install();
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) StopContext(org.jboss.msc.service.StopContext) StartContext(org.jboss.msc.service.StartContext) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) CamelContextFactory(org.wildfly.extension.camel.CamelContextFactory) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 10 with StopContext

use of org.jboss.msc.service.StopContext 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)

Aggregations

StopContext (org.jboss.msc.service.StopContext)11 StartContext (org.jboss.msc.service.StartContext)10 Service (org.jboss.msc.Service)4 BinderService (org.jboss.as.naming.service.BinderService)3 Service (org.jboss.msc.service.Service)3 StartException (org.jboss.msc.service.StartException)3 File (java.io.File)2 URL (java.net.URL)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)2 ContextNames (org.jboss.as.naming.deployment.ContextNames)2 ServiceController (org.jboss.msc.service.ServiceController)2 TracerConfiguration (org.wildfly.microprofile.opentracing.smallrye.TracerConfiguration)2 IoCallback (io.undertow.io.IoCallback)1 Sender (io.undertow.io.Sender)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 Resource (io.undertow.server.handlers.resource.Resource)1 ResourceChangeListener (io.undertow.server.handlers.resource.ResourceChangeListener)1