Search in sources :

Example 6 with ModuleDeployment

use of org.jboss.as.ejb3.deployment.ModuleDeployment 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;
    }
    // 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 EJB 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, countdown);
    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(), (InjectedValue<Object>) entry.getValue());
    }
    builder.addDependency(DeploymentRepository.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);
    startBuilder.addDependencies(componentStartServices);
    startBuilder.addDependency(moduleDeploymentService);
    startBuilder.addDependency(DeploymentRepository.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)

Example 7 with ModuleDeployment

use of org.jboss.as.ejb3.deployment.ModuleDeployment in project wildfly by wildfly.

the class AssociationImpl method registerModuleAvailabilityListener.

@Override
public ListenerHandle registerModuleAvailabilityListener(@NotNull final ModuleAvailabilityListener moduleAvailabilityListener) {
    final DeploymentRepositoryListener listener = new DeploymentRepositoryListener() {

        public void listenerAdded(final DeploymentRepository repository) {
            List<ModuleAvailabilityListener.ModuleIdentifier> identifierList = new ArrayList<>();
            for (DeploymentModuleIdentifier identifier : repository.getModules().keySet()) {
                final ModuleAvailabilityListener.ModuleIdentifier moduleIdentifier = toModuleIdentifier(identifier);
                identifierList.add(moduleIdentifier);
            }
            moduleAvailabilityListener.moduleAvailable(identifierList);
        }

        private ModuleAvailabilityListener.ModuleIdentifier toModuleIdentifier(final DeploymentModuleIdentifier identifier) {
            return new ModuleAvailabilityListener.ModuleIdentifier(identifier.getApplicationName(), identifier.getModuleName(), identifier.getDistinctName());
        }

        public void deploymentAvailable(final DeploymentModuleIdentifier deployment, final ModuleDeployment moduleDeployment) {
            moduleAvailabilityListener.moduleAvailable(Collections.singletonList(toModuleIdentifier(deployment)));
        }

        public void deploymentStarted(final DeploymentModuleIdentifier deployment, final ModuleDeployment moduleDeployment) {
        }

        public void deploymentRemoved(final DeploymentModuleIdentifier deployment) {
            moduleAvailabilityListener.moduleUnavailable(Collections.singletonList(toModuleIdentifier(deployment)));
        }

        @Override
        public void deploymentSuspended(DeploymentModuleIdentifier deployment) {
            moduleAvailabilityListener.moduleUnavailable(Collections.singletonList(toModuleIdentifier(deployment)));
        }

        @Override
        public void deploymentResumed(DeploymentModuleIdentifier deployment) {
            moduleAvailabilityListener.moduleAvailable(Collections.singletonList(toModuleIdentifier(deployment)));
        }
    };
    deploymentRepository.addListener(listener);
    return () -> deploymentRepository.removeListener(listener);
}
Also used : ModuleDeployment(org.jboss.as.ejb3.deployment.ModuleDeployment) DeploymentRepositoryListener(org.jboss.as.ejb3.deployment.DeploymentRepositoryListener) ArrayList(java.util.ArrayList) DeploymentModuleIdentifier(org.jboss.as.ejb3.deployment.DeploymentModuleIdentifier) DeploymentRepository(org.jboss.as.ejb3.deployment.DeploymentRepository) DeploymentModuleIdentifier(org.jboss.as.ejb3.deployment.DeploymentModuleIdentifier) ModuleAvailabilityListener(org.jboss.ejb.server.ModuleAvailabilityListener)

Aggregations

ModuleDeployment (org.jboss.as.ejb3.deployment.ModuleDeployment)7 DeploymentModuleIdentifier (org.jboss.as.ejb3.deployment.DeploymentModuleIdentifier)6 EjbDeploymentInformation (org.jboss.as.ejb3.deployment.EjbDeploymentInformation)4 InjectedValue (org.jboss.msc.value.InjectedValue)3 HashMap (java.util.HashMap)2 ComponentView (org.jboss.as.ee.component.ComponentView)2 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)2 DeploymentRepository (org.jboss.as.ejb3.deployment.DeploymentRepository)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 Module (org.jboss.modules.Module)2 ServiceName (org.jboss.msc.service.ServiceName)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Management (javax.management.j2ee.Management)1 ManagementHome (javax.management.j2ee.ManagementHome)1 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)1 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)1 ViewDescription (org.jboss.as.ee.component.ViewDescription)1 StartupCountdown (org.jboss.as.ee.component.deployers.StartupCountdown)1