Search in sources :

Example 11 with InjectedValue

use of org.jboss.msc.value.InjectedValue in project wildfly by wildfly.

the class JSR77ManagementSubsystemAdd method performBoottime.

@Override
protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    context.addStep(new AbstractDeploymentChainStep() {

        protected void execute(DeploymentProcessorTarget processorTarget) {
            processorTarget.addDeploymentProcessor(JSR77ManagementExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_JSR77, new Jsr77DependenciesProcessor());
        }
    }, OperationContext.Stage.RUNTIME);
    final boolean appclient = context.getProcessType() == ProcessType.APPLICATION_CLIENT;
    if (!appclient) {
        context.addStep(new OperationStepHandler() {

            @Override
            public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                ServiceTarget target = context.getServiceTarget();
                ServiceName mbeanServerServiceName = context.getCapabilityServiceName(JSR77ManagementRootResource.JMX_CAPABILITY, MBeanServer.class);
                RegisterMBeanServerDelegateService mbeanServerService = new RegisterMBeanServerDelegateService();
                target.addService(RegisterMBeanServerDelegateService.SERVICE_NAME, mbeanServerService).addDependency(mbeanServerServiceName, PluggableMBeanServer.class, mbeanServerService.injectedMbeanServer).addDependency(Services.JBOSS_SERVER_CONTROLLER, ModelController.class, mbeanServerService.injectedController).setInitialMode(Mode.ACTIVE).install();
                RegisterManagementEJBService managementEjbService = new RegisterManagementEJBService();
                target.addService(RegisterManagementEJBService.SERVICE_NAME, managementEjbService).addDependency(DeploymentRepositoryService.SERVICE_NAME, DeploymentRepository.class, managementEjbService.deploymentRepositoryValue).addDependency(mbeanServerServiceName, MBeanServer.class, managementEjbService.mbeanServerValue).addDependency(EJBClientContextService.DEFAULT_SERVICE_NAME, EJBClientContextService.class, managementEjbService.ejbClientContextValue).addDependency(AssociationService.SERVICE_NAME, AssociationService.class, managementEjbService.associationServiceInjector).setInitialMode(Mode.PASSIVE).install();
                // TODO null for source ok?
                final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(JNDI_NAME);
                final BinderService binderService = new BinderService(bindInfo.getBindName(), null);
                final InjectedValue<ClassLoader> viewClassLoader = new InjectedValue<ClassLoader>();
                binderService.getManagedObjectInjector().inject(new RemoteViewManagedReferenceFactory(APP_NAME, MODULE_NAME, DISTINCT_NAME, EJB_NAME, ManagementHome.class.getName(), false, viewClassLoader, appclient));
                viewClassLoader.setValue(Values.immediateValue(ManagementHome.class.getClassLoader()));
                target.addService(bindInfo.getBinderServiceName(), binderService).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).install();
                // Rollback is handled by the parent step
                context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
            }
        }, Stage.RUNTIME);
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) InjectedValue(org.jboss.msc.value.InjectedValue) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ServiceTarget(org.jboss.msc.service.ServiceTarget) OperationFailedException(org.jboss.as.controller.OperationFailedException) RemoteViewManagedReferenceFactory(org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory) AssociationService(org.jboss.as.ejb3.remote.AssociationService) BinderService(org.jboss.as.naming.service.BinderService) ManagementHome(javax.management.j2ee.ManagementHome) DeploymentProcessorTarget(org.jboss.as.server.DeploymentProcessorTarget) ServiceName(org.jboss.msc.service.ServiceName) AbstractDeploymentChainStep(org.jboss.as.server.AbstractDeploymentChainStep) ModelNode(org.jboss.dmr.ModelNode) ModelController(org.jboss.as.controller.ModelController) PluggableMBeanServer(org.jboss.as.server.jmx.PluggableMBeanServer) MBeanServer(javax.management.MBeanServer)

Example 12 with InjectedValue

use of org.jboss.msc.value.InjectedValue in project wildfly by wildfly.

the class RegisterManagementEJBService method start.

@Override
public void start(StartContext context) throws StartException {
    final DeploymentRepository repository = deploymentRepositoryValue.getValue();
    moduleIdentifier = new DeploymentModuleIdentifier(APP_NAME, MODULE_NAME, DISTINCT_NAME);
    final InjectedValue<ComponentView> injectedHomeView = new InjectedValue<ComponentView>();
    injectedHomeView.setValue(new ImmediateValue<ComponentView>(new ManagementHomeEjbComponentView()));
    final InjectedValue<ComponentView> injectedRemoteView = new InjectedValue<ComponentView>();
    injectedRemoteView.setValue(new ImmediateValue<ComponentView>(new ManagementRemoteEjbComponentView(mbeanServerValue.getValue())));
    Map<String, InjectedValue<ComponentView>> views = new HashMap<String, InjectedValue<ComponentView>>();
    views.put(ManagementHome.class.getName(), injectedHomeView);
    views.put(Management.class.getName(), injectedRemoteView);
    final EjbDeploymentInformation ejb = new ManagementEjbDeploymentInformation(EJB_NAME, views, SecurityActions.getClassLoader(this.getClass()));
    final ModuleDeployment deployment = new ModuleDeployment(moduleIdentifier, Collections.singletonMap(EJB_NAME, ejb));
    repository.add(moduleIdentifier, deployment);
    repository.startDeployment(moduleIdentifier);
    doPrivileged((PrivilegedAction<Void>) () -> {
        final ClassLoader classLoader = getClass().getClassLoader();
        EJBClientContext.getContextManager().setClassLoaderDefault(classLoader, ejbClientContextValue.getValue().getClientContext());
        Discovery.getContextManager().setClassLoaderDefault(classLoader, Discovery.create(associationServiceInjector.getValue().getLocalDiscoveryProvider()));
        return null;
    });
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) ManagementEjbDeploymentInformation(org.jboss.as.jsr77.ejb.ManagementEjbDeploymentInformation) EjbDeploymentInformation(org.jboss.as.ejb3.deployment.EjbDeploymentInformation) HashMap(java.util.HashMap) Management(javax.management.j2ee.Management) ManagementHomeEjbComponentView(org.jboss.as.jsr77.ejb.ManagementHomeEjbComponentView) ManagementEjbDeploymentInformation(org.jboss.as.jsr77.ejb.ManagementEjbDeploymentInformation) ManagementRemoteEjbComponentView(org.jboss.as.jsr77.ejb.ManagementRemoteEjbComponentView) ManagementHome(javax.management.j2ee.ManagementHome) ModuleDeployment(org.jboss.as.ejb3.deployment.ModuleDeployment) ManagementHomeEjbComponentView(org.jboss.as.jsr77.ejb.ManagementHomeEjbComponentView) ManagementRemoteEjbComponentView(org.jboss.as.jsr77.ejb.ManagementRemoteEjbComponentView) ComponentView(org.jboss.as.ee.component.ComponentView) DeploymentModuleIdentifier(org.jboss.as.ejb3.deployment.DeploymentModuleIdentifier) DeploymentRepository(org.jboss.as.ejb3.deployment.DeploymentRepository)

Example 13 with InjectedValue

use of org.jboss.msc.value.InjectedValue in project wildfly by wildfly.

the class EjbJndiBindingsDeploymentUnitProcessor method registerRemoteBinding.

private void registerRemoteBinding(final EJBComponentDescription componentDescription, final ViewDescription viewDescription, final String jndiName) {
    final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
    final InjectedValue<ClassLoader> viewClassLoader = new InjectedValue<ClassLoader>();
    moduleDescription.getBindingConfigurations().add(new BindingConfiguration(jndiName, new RemoteViewInjectionSource(null, moduleDescription.getEarApplicationName(), moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), viewDescription.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient)));
    componentDescription.getConfigurators().add(new ComponentConfigurator() {

        public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
            viewClassLoader.setValue(Values.immediateValue(configuration.getModuleClassLoader()));
        }
    });
}
Also used : ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) InjectedValue(org.jboss.msc.value.InjectedValue) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) RemoteViewInjectionSource(org.jboss.as.ejb3.remote.RemoteViewInjectionSource) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration)

Example 14 with InjectedValue

use of org.jboss.msc.value.InjectedValue 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 15 with InjectedValue

use of org.jboss.msc.value.InjectedValue in project wildfly by wildfly.

the class DeploymentRepositoryProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    if (eeModuleDescription == null) {
        return;
    }
    if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
        // don't create this for EAR's, as they cannot hold Jakarta Enterprise Beans's
        return;
    }
    // Note, we do not use the EEModuleDescription.getApplicationName() because that API returns the
    // module name if the top level unit isn't a .ear, which is not what we want. We really want a
    // .ear name as application name (that's the semantic in Jakarta Enterprise Beans spec). So use EEModuleDescription.getEarApplicationName
    String applicationName = eeModuleDescription.getEarApplicationName();
    // if it's not a .ear deployment then set app name to empty string
    applicationName = applicationName == null ? "" : applicationName;
    final DeploymentModuleIdentifier identifier = new DeploymentModuleIdentifier(applicationName, eeModuleDescription.getModuleName(), eeModuleDescription.getDistinctName());
    final Collection<ComponentDescription> componentDescriptions = eeModuleDescription.getComponentDescriptions();
    final Map<String, EjbDeploymentInformation> deploymentInformationMap = new HashMap<String, EjbDeploymentInformation>();
    final Set<ServiceName> componentStartServices = new HashSet<ServiceName>();
    final Map<ServiceName, InjectedValue<?>> injectedValues = new HashMap<ServiceName, InjectedValue<?>>();
    for (final ComponentDescription component : componentDescriptions) {
        if (component instanceof EJBComponentDescription) {
            final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) component;
            componentStartServices.add(component.getStartServiceName());
            final InjectedValue<EJBComponent> componentInjectedValue = new InjectedValue<EJBComponent>();
            injectedValues.put(component.getCreateServiceName(), componentInjectedValue);
            final Map<String, InjectedValue<ComponentView>> remoteViews = new HashMap<String, InjectedValue<ComponentView>>();
            final Map<String, InjectedValue<ComponentView>> localViews = new HashMap<String, InjectedValue<ComponentView>>();
            for (final ViewDescription view : ejbComponentDescription.getViews()) {
                boolean remoteView = false;
                if (view instanceof EJBViewDescription) {
                    final MethodIntf viewType = ((EJBViewDescription) view).getMethodIntf();
                    if (viewType == MethodIntf.HOME || viewType == MethodIntf.REMOTE) {
                        remoteView = true;
                    }
                }
                final InjectedValue<ComponentView> componentViewInjectedValue = new InjectedValue<ComponentView>();
                if (remoteView) {
                    remoteViews.put(view.getViewClassName(), componentViewInjectedValue);
                } else {
                    localViews.put(view.getViewClassName(), componentViewInjectedValue);
                }
                injectedValues.put(view.getServiceName(), componentViewInjectedValue);
            }
            final InjectedValue<EjbIIOPService> iorFactory = new InjectedValue<EjbIIOPService>();
            if (ejbComponentDescription.isExposedViaIiop()) {
                injectedValues.put(ejbComponentDescription.getServiceName().append(EjbIIOPService.SERVICE_NAME), iorFactory);
            }
            final EjbDeploymentInformation info = new EjbDeploymentInformation(ejbComponentDescription.getEJBName(), componentInjectedValue, remoteViews, localViews, module.getClassLoader(), iorFactory);
            deploymentInformationMap.put(ejbComponentDescription.getEJBName(), info);
        }
    }
    final StartupCountdown countdown = deploymentUnit.getAttachment(Attachments.STARTUP_COUNTDOWN);
    final ModuleDeployment deployment = new ModuleDeployment(identifier, deploymentInformationMap);
    ServiceName moduleDeploymentService = deploymentUnit.getServiceName().append(ModuleDeployment.SERVICE_NAME);
    final ServiceBuilder<ModuleDeployment> builder = phaseContext.getServiceTarget().addService(moduleDeploymentService, deployment);
    for (Map.Entry<ServiceName, InjectedValue<?>> entry : injectedValues.entrySet()) {
        builder.addDependency(entry.getKey(), Object.class, (InjectedValue<Object>) entry.getValue());
    }
    builder.addDependency(DeploymentRepositoryService.SERVICE_NAME, DeploymentRepository.class, deployment.getDeploymentRepository());
    builder.install();
    final ModuleDeployment.ModuleDeploymentStartService deploymentStart = new ModuleDeployment.ModuleDeploymentStartService(identifier, countdown);
    final ServiceBuilder<Void> startBuilder = phaseContext.getServiceTarget().addService(deploymentUnit.getServiceName().append(ModuleDeployment.START_SERVICE_NAME), deploymentStart);
    for (final ServiceName componentStartService : componentStartServices) {
        startBuilder.requires(componentStartService);
    }
    startBuilder.requires(moduleDeploymentService);
    startBuilder.addDependency(DeploymentRepositoryService.SERVICE_NAME, DeploymentRepository.class, deploymentStart.getDeploymentRepository());
    startBuilder.install();
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) HashMap(java.util.HashMap) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) MethodIntf(org.jboss.as.ejb3.component.MethodIntf) ModuleDeployment(org.jboss.as.ejb3.deployment.ModuleDeployment) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) StartupCountdown(org.jboss.as.ee.component.deployers.StartupCountdown) HashSet(java.util.HashSet) EjbDeploymentInformation(org.jboss.as.ejb3.deployment.EjbDeploymentInformation) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) ComponentView(org.jboss.as.ee.component.ComponentView) ServiceName(org.jboss.msc.service.ServiceName) DeploymentModuleIdentifier(org.jboss.as.ejb3.deployment.DeploymentModuleIdentifier) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) EjbIIOPService(org.jboss.as.ejb3.iiop.EjbIIOPService) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

InjectedValue (org.jboss.msc.value.InjectedValue)16 ServiceName (org.jboss.msc.service.ServiceName)7 HashMap (java.util.HashMap)5 ModelNode (org.jboss.dmr.ModelNode)5 Group (org.wildfly.clustering.group.Group)5 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)4 HashSet (java.util.HashSet)3 OperationFailedException (org.jboss.as.controller.OperationFailedException)3 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 Module (org.jboss.modules.Module)3 ArrayList (java.util.ArrayList)2 ManagementHome (javax.management.j2ee.ManagementHome)2 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)2 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)2 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)2 ComponentView (org.jboss.as.ee.component.ComponentView)2 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)2 DeploymentModuleIdentifier (org.jboss.as.ejb3.deployment.DeploymentModuleIdentifier)2 EjbDeploymentInformation (org.jboss.as.ejb3.deployment.EjbDeploymentInformation)2