Search in sources :

Example 1 with StopContext

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

the class CamelContextRegistryBindingService method addService.

public static ServiceController<?> addService(ServiceTarget serviceTarget) {
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(CamelConstants.CAMEL_CONTEXT_REGISTRY_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_REGISTRY_SERVICE_NAME, CamelContextRegistry.class, new ManagedReferenceInjector<CamelContextRegistry>(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) CamelContextRegistry(org.wildfly.extension.camel.CamelContextRegistry) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 2 with StopContext

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

the class CamelContextBindingService method addService.

public static ServiceController<?> addService(ServiceTarget serviceTarget, final CamelContext camelctx) {
    final BindInfo bindInfo = ContextNames.bindInfoFor(CamelConstants.CAMEL_CONTEXT_BINDING_NAME + "/" + camelctx.getName());
    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.info("Unbind camel naming object: {}", bindInfo.getAbsoluteJndiName());
            super.stop(context);
        }
    };
    binderService.getManagedObjectInjector().inject(new ImmediateManagedReferenceFactory(camelctx));
    ServiceBuilder<?> builder = serviceTarget.addService(bindInfo.getBinderServiceName(), binderService);
    builder.addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector());
    return builder.install();
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) StopContext(org.jboss.msc.service.StopContext) StartContext(org.jboss.msc.service.StartContext) BindInfo(org.jboss.as.naming.deployment.ContextNames.BindInfo) ImmediateManagedReferenceFactory(org.jboss.as.naming.ImmediateManagedReferenceFactory)

Example 3 with StopContext

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

the class WildflyHibernate5ClassChangeAware method doServiceStop.

private void doServiceStop(Service puService) throws InterruptedException {
    final CountDownLatch stopLatch = new CountDownLatch(1);
    final AtomicBoolean async = new AtomicBoolean(false);
    puService.stop(new StopContext() {

        @Override
        public void asynchronous() throws IllegalStateException {
            async.set(true);
        }

        @Override
        public void complete() throws IllegalStateException {
            stopLatch.countDown();
        }

        @Override
        public long getElapsedTime() {
            return 0;
        }

        @Override
        public ServiceController<?> getController() {
            return null;
        }

        @Override
        public void execute(Runnable command) {
            command.run();
        }
    });
    if (async.get()) {
        stopLatch.await();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StopContext(org.jboss.msc.service.StopContext) ServiceController(org.jboss.msc.service.ServiceController) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 4 with StopContext

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

the class JaxrsSpringProcessor method getResteasySpringVirtualFile.

/**
 * Lookup Seam integration resource loader.
 *
 * @return the Seam integration resource loader
 * @throws DeploymentUnitProcessingException
 *          for any error
 */
protected synchronized VirtualFile getResteasySpringVirtualFile() throws DeploymentUnitProcessingException {
    if (resourceRoot != null) {
        return resourceRoot;
    }
    try {
        Module module = Module.getBootModuleLoader().loadModule(MODULE);
        URL fileUrl = module.getClassLoader().getResource(JAR_LOCATION);
        if (fileUrl == null) {
            throw JaxrsLogger.JAXRS_LOGGER.noSpringIntegrationJar();
        }
        File dir = new File(fileUrl.toURI());
        File file = null;
        for (String jar : dir.list()) {
            if (jar.endsWith(".jar")) {
                file = new File(dir, jar);
                break;
            }
        }
        if (file == null) {
            throw JaxrsLogger.JAXRS_LOGGER.noSpringIntegrationJar();
        }
        VirtualFile vf = VFS.getChild(file.toURI());
        final Closeable mountHandle = VFS.mountZip(file, vf, TempFileProviderService.provider());
        Service<Closeable> mountHandleService = new Service<Closeable>() {

            public void start(StartContext startContext) throws StartException {
            }

            public void stop(StopContext stopContext) {
                VFSUtils.safeClose(mountHandle);
            }

            public Closeable getValue() throws IllegalStateException, IllegalArgumentException {
                return mountHandle;
            }
        };
        ServiceBuilder<Closeable> builder = serviceTarget.addService(ServiceName.JBOSS.append(SERVICE_NAME), mountHandleService);
        builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
        resourceRoot = vf;
        return resourceRoot;
    } catch (Exception e) {
        throw new DeploymentUnitProcessingException(e);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) StopContext(org.jboss.msc.service.StopContext) Closeable(java.io.Closeable) Service(org.jboss.msc.service.Service) TempFileProviderService(org.jboss.as.server.deployment.module.TempFileProviderService) URL(java.net.URL) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) StartException(org.jboss.msc.service.StartException) StartContext(org.jboss.msc.service.StartContext) Module(org.jboss.modules.Module) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File)

Example 5 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)

Aggregations

StopContext (org.jboss.msc.service.StopContext)10 StartContext (org.jboss.msc.service.StartContext)9 Service (org.jboss.msc.Service)4 BinderService (org.jboss.as.naming.service.BinderService)3 StartException (org.jboss.msc.service.StartException)3 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 LifecycleEvent (org.jboss.msc.service.LifecycleEvent)2 LifecycleListener (org.jboss.msc.service.LifecycleListener)2 Service (org.jboss.msc.service.Service)2 ServiceController (org.jboss.msc.service.ServiceController)2 TracerConfiguration (org.wildfly.microprofile.opentracing.smallrye.TracerConfiguration)2 Closeable (java.io.Closeable)1 File (java.io.File)1 URL (java.net.URL)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1