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();
}
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);
}
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);
}
}
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();
}
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();
}
Aggregations