Search in sources :

Example 1 with ServiceBuilder

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

the class SessionBeanHomeProcessor method configureHome.

private void configureHome(final DeploymentPhaseContext phaseContext, final ComponentDescription componentDescription, final SessionBeanComponentDescription ejbComponentDescription, final EJBViewDescription homeView, final EJBViewDescription ejbObjectView) {
    homeView.getConfigurators().add(new ViewConfigurator() {

        @Override
        public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
            configuration.addClientPostConstructInterceptor(org.jboss.invocation.Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPostConstruct.TERMINAL_INTERCEPTOR);
            configuration.addClientPreDestroyInterceptor(org.jboss.invocation.Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPreDestroy.TERMINAL_INTERCEPTOR);
            //loop over methods looking for create methods:
            for (Method method : configuration.getProxyFactory().getCachedMethods()) {
                if (method.getName().startsWith("create")) {
                    //we have a create method
                    if (ejbObjectView == null) {
                        throw EjbLogger.ROOT_LOGGER.invalidEjbLocalInterface(componentDescription.getComponentName());
                    }
                    Method initMethod = resolveInitMethod(ejbComponentDescription, method);
                    final SessionBeanHomeInterceptorFactory factory = new SessionBeanHomeInterceptorFactory(initMethod);
                    //add a dependency on the view to create
                    configuration.getDependencies().add(new DependencyConfigurator<ViewService>() {

                        @Override
                        public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ViewService service) throws DeploymentUnitProcessingException {
                            serviceBuilder.addDependency(ejbObjectView.getServiceName(), ComponentView.class, factory.getViewToCreate());
                        }
                    });
                    //add the interceptor
                    configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
                    configuration.addViewInterceptor(method, factory, InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
                } else if (method.getName().equals("getEJBMetaData") && method.getParameterTypes().length == 0 && ((EJBViewDescription) description).getMethodIntf() == MethodIntf.HOME) {
                    final Class<?> ejbObjectClass;
                    try {
                        ejbObjectClass = ClassLoadingUtils.loadClass(ejbObjectView.getViewClassName(), context.getDeploymentUnit());
                    } catch (ClassNotFoundException e) {
                        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getComponentName());
                    }
                    final EjbMetadataInterceptor factory = new EjbMetadataInterceptor(ejbObjectClass, configuration.getViewClass().asSubclass(EJBHome.class), null, true, componentDescription instanceof StatelessComponentDescription);
                    //add a dependency on the view to create
                    componentConfiguration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {

                        @Override
                        public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ComponentStartService service) throws DeploymentUnitProcessingException {
                            serviceBuilder.addDependency(configuration.getViewServiceName(), ComponentView.class, factory.getHomeView());
                        }
                    });
                    //add the interceptor
                    configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
                    configuration.addViewInterceptor(method, new ImmediateInterceptorFactory(factory), InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
                } else if (method.getName().equals("remove") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == Object.class) {
                    configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
                    configuration.addViewInterceptor(method, InvalidRemoveExceptionMethodInterceptor.FACTORY, InterceptorOrder.View.INVALID_METHOD_EXCEPTION);
                } else if (method.getName().equals("remove") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == Handle.class) {
                    configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
                    configuration.addViewInterceptor(method, HomeRemoveInterceptor.FACTORY, InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
                }
            }
        }
    });
}
Also used : ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) EJBHome(javax.ejb.EJBHome) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) DependencyConfigurator(org.jboss.as.ee.component.DependencyConfigurator) Method(java.lang.reflect.Method) ViewService(org.jboss.as.ee.component.ViewService) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) Handle(javax.ejb.Handle) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) SessionBeanHomeInterceptorFactory(org.jboss.as.ejb3.component.interceptors.SessionBeanHomeInterceptorFactory) ComponentView(org.jboss.as.ee.component.ComponentView) StatelessComponentDescription(org.jboss.as.ejb3.component.stateless.StatelessComponentDescription) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) EjbMetadataInterceptor(org.jboss.as.ejb3.component.interceptors.EjbMetadataInterceptor) ComponentStartService(org.jboss.as.ee.component.ComponentStartService)

Example 2 with ServiceBuilder

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

the class RemoveOnCancelScheduledExecutorServiceBuilder method build.

@Override
public ServiceBuilder<ScheduledExecutorService> build(ServiceTarget target) {
    Function<ScheduledExecutorService, ScheduledExecutorService> mapper = executor -> JBossExecutors.protectedScheduledExecutorService(executor);
    Supplier<ScheduledExecutorService> supplier = () -> {
        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(this.size, this.factory);
        executor.setRemoveOnCancelPolicy(true);
        executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
        return executor;
    };
    Service<ScheduledExecutorService> service = new SuppliedValueService<>(mapper, supplier, ScheduledExecutorService::shutdown);
    return new AsynchronousServiceBuilder<>(this.name, service).startSynchronously().build(target).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
Also used : Service(org.jboss.msc.service.Service) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) AsynchronousServiceBuilder(org.wildfly.clustering.service.AsynchronousServiceBuilder) Function(java.util.function.Function) Supplier(java.util.function.Supplier) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService) ServiceController(org.jboss.msc.service.ServiceController) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ServiceName(org.jboss.msc.service.ServiceName) ServiceTarget(org.jboss.msc.service.ServiceTarget) JBossExecutors(org.jboss.threads.JBossExecutors) ThreadFactory(java.util.concurrent.ThreadFactory) Builder(org.wildfly.clustering.service.Builder) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService)

Example 3 with ServiceBuilder

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

the class KeyAffinityServiceFactoryBuilder method build.

@Override
public ServiceBuilder<KeyAffinityServiceFactory> build(ServiceTarget target) {
    int bufferSize = this.bufferSize;
    Function<ExecutorService, KeyAffinityServiceFactory> mapper = executor -> new KeyAffinityServiceFactory() {

        @Override
        public <K> KeyAffinityService<K> createService(Cache<K, ?> cache, KeyGenerator<K> generator) {
            CacheMode mode = cache.getCacheConfiguration().clustering().cacheMode();
            return mode.isDistributed() || mode.isReplicated() ? new KeyAffinityServiceImpl<>(executor, cache, generator, bufferSize, Collections.singleton(cache.getCacheManager().getAddress()), false) : new SimpleKeyAffinityService<>(generator);
        }
    };
    Supplier<ExecutorService> supplier = () -> {
        ThreadGroup threadGroup = new ThreadGroup("KeyAffinityService ThreadGroup");
        String namePattern = "KeyAffinityService Thread Pool -- %t";
        PrivilegedAction<ThreadFactory> action = () -> new JBossThreadFactory(threadGroup, Boolean.FALSE, null, namePattern, null, null);
        return Executors.newCachedThreadPool(doPrivileged(action));
    };
    Service<KeyAffinityServiceFactory> service = new SuppliedValueService<>(mapper, supplier, ExecutorService::shutdown);
    return new AsynchronousServiceBuilder<>(this.getServiceName(), service).startSynchronously().build(target).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
Also used : Service(org.jboss.msc.service.Service) AccessController.doPrivileged(java.security.AccessController.doPrivileged) Cache(org.infinispan.Cache) Function(java.util.function.Function) Supplier(java.util.function.Supplier) KeyGenerator(org.infinispan.affinity.KeyGenerator) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService) KeyAffinityService(org.infinispan.affinity.KeyAffinityService) KeyAffinityServiceFactory(org.wildfly.clustering.infinispan.spi.affinity.KeyAffinityServiceFactory) ServiceTarget(org.jboss.msc.service.ServiceTarget) ThreadFactory(java.util.concurrent.ThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) Address(org.infinispan.remoting.transport.Address) JBossThreadFactory(org.jboss.threads.JBossThreadFactory) PathAddress(org.jboss.as.controller.PathAddress) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) AsynchronousServiceBuilder(org.wildfly.clustering.service.AsynchronousServiceBuilder) PrivilegedAction(java.security.PrivilegedAction) Executors(java.util.concurrent.Executors) KeyAffinityServiceImpl(org.infinispan.affinity.impl.KeyAffinityServiceImpl) ServiceController(org.jboss.msc.service.ServiceController) CacheMode(org.infinispan.configuration.cache.CacheMode) ServiceName(org.jboss.msc.service.ServiceName) Collections(java.util.Collections) Builder(org.wildfly.clustering.service.Builder) JBossThreadFactory(org.jboss.threads.JBossThreadFactory) CacheMode(org.infinispan.configuration.cache.CacheMode) KeyAffinityServiceFactory(org.wildfly.clustering.infinispan.spi.affinity.KeyAffinityServiceFactory) PrivilegedAction(java.security.PrivilegedAction) ExecutorService(java.util.concurrent.ExecutorService) KeyGenerator(org.infinispan.affinity.KeyGenerator) Cache(org.infinispan.Cache) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService)

Example 4 with ServiceBuilder

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

the class CamelContextActivationProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit depUnit = phaseContext.getDeploymentUnit();
    CamelDeploymentSettings depSettings = depUnit.getAttachment(CamelDeploymentSettings.ATTACHMENT_KEY);
    if (!depSettings.isEnabled()) {
        return;
    }
    String runtimeName = depUnit.getName();
    ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    ServiceName camelActivationServiceName = depUnit.getServiceName().append(CAMEL_CONTEXT_ACTIVATION_SERVICE_NAME.append(runtimeName));
    List<SpringCamelContextBootstrap> camelctxBootstrapList = depUnit.getAttachmentList(CamelConstants.CAMEL_CONTEXT_BOOTSTRAP_KEY);
    CamelContextActivationService activationService = new CamelContextActivationService(camelctxBootstrapList, runtimeName);
    ServiceBuilder builder = serviceTarget.addService(camelActivationServiceName, activationService);
    // Ensure all camel contexts in the deployment are started before constructing servlets etc
    depUnit.addToAttachmentList(Attachments.WEB_DEPENDENCIES, camelActivationServiceName);
    // Add JNDI binding dependencies to CamelContextActivationService
    for (SpringCamelContextBootstrap bootstrap : camelctxBootstrapList) {
        for (String jndiName : bootstrap.getJndiNames()) {
            if (jndiName.startsWith("${")) {
                // Don't add the binding if it appears to be a Spring property placeholder value
                // these can't be resolved before refresh() has been called on the ApplicationContext
                LOGGER.warn("Skipping JNDI binding dependency for property placeholder value: {}", jndiName);
            } else {
                LOGGER.debug("Add CamelContextActivationService JNDI binding dependency for {}", jndiName);
                installBindingDependency(builder, jndiName);
            }
        }
    }
    builder.install();
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) ServiceTarget(org.jboss.msc.service.ServiceTarget) CamelContextActivationService(org.wildfly.extension.camel.service.CamelContextActivationService) SpringCamelContextBootstrap(org.wildfly.extension.camel.SpringCamelContextBootstrap) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) ServiceBuilder(org.jboss.msc.service.ServiceBuilder)

Example 5 with ServiceBuilder

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

the class RaAdd method performRuntime.

@Override
public void performRuntime(final OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException {
    final ModelNode model = resource.getModel();
    // TODO WFLY-15231 -- this logic is using the wrong attributes, so it's currently doing nothing
    if (ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
        if (model.hasDefined(SECURITY_DOMAIN.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN.getName(), ELYTRON_ENABLED.getName());
        else if (model.hasDefined(SECURITY_DOMAIN_AND_APPLICATION.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
        else if (model.hasDefined(APPLICATION.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(APPLICATION.getName(), ELYTRON_ENABLED.getName());
    } else {
        if (model.hasDefined(AUTHENTICATION_CONTEXT.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT.getName(), ELYTRON_ENABLED.getName());
        else if (model.hasDefined(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
    }
    // do the same for recovery security attributes
    if (RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
        if (model.hasDefined(RECOVERY_SECURITY_DOMAIN.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(RECOVERY_SECURITY_DOMAIN.getName(), RECOVERY_ELYTRON_ENABLED.getName());
    } else {
        if (model.hasDefined(RECOVERY_AUTHENTICATION_CONTEXT.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(RECOVERY_AUTHENTICATION_CONTEXT.getName(), RECOVERY_ELYTRON_ENABLED.getName());
    }
    // Compensating is remove
    final String name = context.getCurrentAddressValue();
    final String archiveOrModuleName;
    final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
    if (!model.hasDefined(ARCHIVE.getName()) && !model.hasDefined(MODULE.getName())) {
        throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
    }
    if (model.get(ARCHIVE.getName()).isDefined()) {
        archiveOrModuleName = model.get(ARCHIVE.getName()).asString();
    } else {
        archiveOrModuleName = model.get(MODULE.getName()).asString();
    }
    ModifiableResourceAdapter resourceAdapter = RaOperationUtil.buildResourceAdaptersObject(name, context, operation, archiveOrModuleName);
    List<ServiceController<?>> newControllers = new ArrayList<ServiceController<?>>();
    if (model.get(ARCHIVE.getName()).isDefined()) {
        RaOperationUtil.installRaServices(context, name, resourceAdapter, newControllers);
    } else {
        RaOperationUtil.installRaServicesAndDeployFromModule(context, name, resourceAdapter, archiveOrModuleName, newControllers);
        if (context.isBooting()) {
            context.addStep(new OperationStepHandler() {

                public void execute(final OperationContext context, ModelNode operation) throws OperationFailedException {
                    // Next lines activate configuration on module deployed rar
                    // in case there is 2 different resource-adapter config using same module deployed rar
                    // a Deployment sercivice could be already present and need a restart to consider also this
                    // newly added configuration
                    ServiceName restartedServiceName = RaOperationUtil.restartIfPresent(context, archiveOrModuleName, name);
                    if (restartedServiceName == null) {
                        RaOperationUtil.activate(context, name, archiveOrModuleName);
                    }
                    context.completeStep(new OperationContext.RollbackHandler() {

                        @Override
                        public void handleRollback(OperationContext context, ModelNode operation) {
                            try {
                                RaOperationUtil.removeIfActive(context, archiveOrModuleName, name);
                            } catch (OperationFailedException e) {
                            }
                        }
                    });
                }
            }, OperationContext.Stage.RUNTIME);
        }
    }
    ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, name));
    Activation raxml = (Activation) RaxmlController.getValue();
    ServiceName serviceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, name);
    String bootStrapCtxName = DEFAULT_NAME;
    if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) {
        bootStrapCtxName = raxml.getBootstrapContext();
    }
    ResourceAdapterStatisticsService raStatsService = new ResourceAdapterStatisticsService(context.getResourceRegistrationForUpdate(), name, statsEnabled);
    ServiceBuilder statsServiceBuilder = context.getServiceTarget().addService(ServiceName.of(ConnectorServices.RA_SERVICE, name).append(ConnectorServices.STATISTICS_SUFFIX), raStatsService);
    statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), Object.class, raStatsService.getBootstrapContextInjector()).addDependency(serviceName, Object.class, raStatsService.getResourceAdapterDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
    PathElement peStats = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
    final Resource statsResource = new IronJacamarResource.IronJacamarRuntimeResource();
    resource.registerChild(peStats, statsResource);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) ResourceAdapterStatisticsService(org.jboss.as.connector.services.resourceadapters.statistics.ResourceAdapterStatisticsService) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ArrayList(java.util.ArrayList) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) PathElement(org.jboss.as.controller.PathElement) ServiceName(org.jboss.msc.service.ServiceName) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

ServiceBuilder (org.jboss.msc.service.ServiceBuilder)59 ServiceName (org.jboss.msc.service.ServiceName)35 ServiceTarget (org.jboss.msc.service.ServiceTarget)23 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)17 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)15 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)14 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)14 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)12 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)12 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)10 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)9 Module (org.jboss.modules.Module)9 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 ImmediateInterceptorFactory (org.jboss.invocation.ImmediateInterceptorFactory)7 ArrayList (java.util.ArrayList)6 OperationFailedException (org.jboss.as.controller.OperationFailedException)6 Resource (org.jboss.as.controller.registry.Resource)6 ModelNode (org.jboss.dmr.ModelNode)6