Search in sources :

Example 56 with ServiceBuilder

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

the class EJBComponentSuspendDeploymentUnitProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext context) {
    final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
    final String topLevelName;
    // check if the controller is installed
    if (!RequestControllerActivationMarker.isRequestControllerEnabled(deploymentUnit)) {
        return;
    }
    if (deploymentUnit.getParent() == null) {
        topLevelName = deploymentUnit.getName();
    } else {
        topLevelName = deploymentUnit.getParent().getName();
    }
    for (ComponentDescription component : deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION).getComponentDescriptions()) {
        if (component instanceof EJBComponentDescription) {
            final String entryPoint = ENTRY_POINT_NAME + deploymentUnit.getName() + "." + component.getComponentName();
            ControlPointService.install(context.getServiceTarget(), topLevelName, entryPoint);
            component.getConfigurators().add(new ComponentConfigurator() {

                @Override
                public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) {
                    EjbSuspendInterceptor interceptor = null;
                    ImmediateInterceptorFactory factory = null;
                    for (ViewConfiguration view : configuration.getViews()) {
                        EJBViewConfiguration ejbView = (EJBViewConfiguration) view;
                        if (INTERFACES.contains(ejbView.getMethodIntf())) {
                            if (factory == null) {
                                interceptor = new EjbSuspendInterceptor();
                                factory = new ImmediateInterceptorFactory(interceptor);
                            }
                            view.addViewInterceptor(factory, InterceptorOrder.View.GRACEFUL_SHUTDOWN);
                        }
                    }
                    configuration.getCreateDependencies().add(new DependencyConfigurator<EJBComponentCreateService>() {

                        @Override
                        public void configureDependency(ServiceBuilder<?> serviceBuilder, EJBComponentCreateService service) {
                            serviceBuilder.addDependency(ControlPointService.serviceName(topLevelName, entryPoint), ControlPoint.class, service.getControlPointInjector());
                        }
                    });
                }
            });
        }
    }
}
Also used : EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) EJBViewConfiguration(org.jboss.as.ejb3.component.EJBViewConfiguration) DependencyConfigurator(org.jboss.as.ee.component.DependencyConfigurator) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) EJBViewConfiguration(org.jboss.as.ejb3.component.EJBViewConfiguration) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) EJBComponentCreateService(org.jboss.as.ejb3.component.EJBComponentCreateService) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 57 with ServiceBuilder

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

the class EjbJndiBindingsDeploymentUnitProcessor method registerControlPointBinding.

private void registerControlPointBinding(final EJBComponentDescription componentDescription, final ViewDescription viewDescription, final String jndiName, final DeploymentUnit deploymentUnit) {
    final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
    final InjectedValue<ClassLoader> viewClassLoader = new InjectedValue<ClassLoader>();
    final InjectedValue<ControlPoint> controlPointInjectedValue = new InjectedValue<>();
    final RemoteViewInjectionSource delegate = new RemoteViewInjectionSource(null, moduleDescription.getEarApplicationName(), moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), viewDescription.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient);
    final ServiceName depName = ControlPointService.serviceName(deploymentUnit.getParent() == null ? deploymentUnit.getName() : deploymentUnit.getParent().getName(), EJBComponentSuspendDeploymentUnitProcessor.ENTRY_POINT_NAME + deploymentUnit.getName() + "." + componentDescription.getComponentName());
    componentDescription.getConfigurators().add((context, description, configuration) -> {
        viewClassLoader.setValue(Values.immediateValue(configuration.getModuleClassLoader()));
        configuration.getCreateDependencies().add((serviceBuilder, service) -> serviceBuilder.addDependency(depName, ControlPoint.class, controlPointInjectedValue));
    });
    // we need to wrap the injection source to allow graceful shutdown to function, although this is not ideal
    // as it will also reject local lookups as well, although in general local code should never be looking up the
    // exported bindings
    // the other option would be to reject it at the remote naming service level, however then we loose the per-deployment granularity
    final InjectionSource is = new InjectionSource() {

        @Override
        public void getResourceValue(ResolutionContext resolutionContext, ServiceBuilder<?> serviceBuilder, DeploymentPhaseContext phaseContext, Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
            final InjectedValue<ManagedReferenceFactory> delegateInjection = new InjectedValue<>();
            delegate.getResourceValue(resolutionContext, serviceBuilder, phaseContext, delegateInjection);
            injector.inject(new RemoteViewManagedReferenceFactory(moduleDescription.getEarApplicationName(), moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), viewDescription.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient) {

                @Override
                public ManagedReference getReference() {
                    ControlPoint cp = controlPointInjectedValue.getValue();
                    try {
                        RunResult res = cp.beginRequest();
                        if (res != RunResult.RUN) {
                            throw EjbLogger.ROOT_LOGGER.containerSuspended();
                        }
                        try {
                            return delegateInjection.getValue().getReference();
                        } finally {
                            cp.requestComplete();
                        }
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            });
        }
    };
    moduleDescription.getBindingConfigurations().add(new BindingConfiguration(jndiName, is));
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) RemoteViewInjectionSource(org.jboss.as.ejb3.remote.RemoteViewInjectionSource) ControlPoint(org.wildfly.extension.requestcontroller.ControlPoint) RemoteViewManagedReferenceFactory(org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory) ManagedReference(org.jboss.as.naming.ManagedReference) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) InjectionSource(org.jboss.as.ee.component.InjectionSource) RemoteViewInjectionSource(org.jboss.as.ejb3.remote.RemoteViewInjectionSource) Injector(org.jboss.msc.inject.Injector) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) RemoteViewManagedReferenceFactory(org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory) RunResult(org.wildfly.extension.requestcontroller.RunResult) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration)

Example 58 with ServiceBuilder

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

the class JndiNamingDependencyProcessor method installComponentJndiAggregatingServices.

private static Set<ServiceName> installComponentJndiAggregatingServices(final ServiceTarget target, final Map<ServiceName, Set<ServiceName>> mappings) {
    if (mappings == null)
        return Collections.emptySet();
    final Set<ServiceName> retVal = new HashSet<>();
    ServiceBuilder sb;
    ServiceName sn;
    for (final Map.Entry<ServiceName, Set<ServiceName>> mapping : mappings.entrySet()) {
        sn = mapping.getKey().append(JNDI_AGGREGATION_SERVICE_SUFFIX);
        retVal.add(sn);
        sb = target.addService(sn);
        for (final ServiceName depName : mapping.getValue()) sb.requires(depName);
        sb.install();
    }
    return retVal;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ServiceName(org.jboss.msc.service.ServiceName) Map(java.util.Map) HashSet(java.util.HashSet) ServiceBuilder(org.jboss.msc.service.ServiceBuilder)

Example 59 with ServiceBuilder

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

the class ParsedKernelDeploymentProcessor method describeBean.

protected void describeBean(final Module module, final ServiceTarget serviceTarget, DeploymentReflectionIndex deploymentIndex, BeanMetaDataConfig beanConfig) {
    final BeanState state = BeanState.NOT_INSTALLED;
    final ServiceName describedServiceName = BeanMetaDataConfig.toBeanName(beanConfig.getName(), state.next());
    final DescribedPojoPhase describedService = new DescribedPojoPhase(deploymentIndex, beanConfig);
    final ServiceBuilder describedServiceBuilder = serviceTarget.addService(describedServiceName, describedService);
    describedService.registerAliases(describedServiceBuilder);
    final ConfigVisitor visitor = new DefaultConfigVisitor(describedServiceBuilder, state, module, deploymentIndex);
    beanConfig.visit(visitor);
    describedServiceBuilder.setInitialMode(beanConfig.getMode().getMode());
    describedServiceBuilder.install();
}
Also used : DescribedPojoPhase(org.jboss.as.pojo.service.DescribedPojoPhase) DefaultConfigVisitor(org.jboss.as.pojo.descriptor.DefaultConfigVisitor) ConfigVisitor(org.jboss.as.pojo.descriptor.ConfigVisitor) DefaultConfigVisitor(org.jboss.as.pojo.descriptor.DefaultConfigVisitor) ServiceName(org.jboss.msc.service.ServiceName) ServiceBuilder(org.jboss.msc.service.ServiceBuilder)

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