Search in sources :

Example 1 with BatchEEServiceManager

use of org.apache.openejb.batchee.BatchEEServiceManager in project tomee by apache.

the class Assembler method buildContainerSystem.

// ///////////////////////////////////////////////////////////////////
// //
// //    Public Methods Used for Assembly
// //
// ///////////////////////////////////////////////////////////////////
/**
 * When given a complete OpenEjbConfiguration graph this method
 * will construct an entire container system and return a reference to that
 * container system, as ContainerSystem instance.
 *
 * This method leverage the other assemble and apply methods which
 * can be used independently.
 *
 * Assembles and returns the {@link CoreContainerSystem} using the
 * information from the {@link OpenEjbConfiguration} object passed in.
 * <pre>
 * This method performs the following actions(in order):
 *
 * 1  Assembles ProxyFactory
 * 2  Assembles External JNDI Contexts
 * 3  Assembles TransactionService
 * 4  Assembles SecurityService
 * 5  Assembles ConnectionManagers
 * 6  Assembles Connectors
 * 7  Assembles Containers
 * 8  Assembles Applications
 * </pre>
 *
 * @param configInfo OpenEjbConfiguration
 * @throws Exception if there was a problem constructing the ContainerSystem.
 * @see OpenEjbConfiguration
 */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void buildContainerSystem(final OpenEjbConfiguration configInfo) throws Exception {
    final SystemInstance systemInstance = SystemInstance.get();
    if (systemInstance.getOptions().get(OPENEJB_JPA_DEPLOY_TIME_ENHANCEMENT_PROP, false)) {
        systemInstance.addObserver(new DeployTimeEnhancer());
    }
    if (hasBatchEE()) {
        systemInstance.addObserver(new BatchEEServiceManager());
    }
    for (final ServiceInfo serviceInfo : configInfo.facilities.services) {
        createService(serviceInfo);
    }
    final ContainerSystemInfo containerSystemInfo = configInfo.containerSystem;
    if (configInfo.facilities.intraVmServer != null) {
        createProxyFactory(configInfo.facilities.intraVmServer);
    }
    for (final JndiContextInfo contextInfo : configInfo.facilities.remoteJndiContexts) {
        createExternalContext(contextInfo);
    }
    createTransactionManager(configInfo.facilities.transactionService);
    createSecurityService(configInfo.facilities.securityService);
    final Set<String> reservedResourceIds = new HashSet<>(configInfo.facilities.resources.size());
    for (final AppInfo appInfo : containerSystemInfo.applications) {
        reservedResourceIds.addAll(appInfo.resourceIds);
    }
    final Map<AppInfo, ClassLoader> appInfoClassLoaders = new HashMap<>();
    final Map<String, ClassLoader> appClassLoaders = new HashMap<>();
    for (final AppInfo appInfo : containerSystemInfo.applications) {
        appInfoClassLoaders.put(appInfo, createAppClassLoader(appInfo));
        appClassLoaders.put(appInfo.appId, createAppClassLoader(appInfo));
    }
    final Set<String> rIds = new HashSet<>(configInfo.facilities.resources.size());
    for (final ResourceInfo resourceInfo : configInfo.facilities.resources) {
        createResource(configInfo.facilities.services, resourceInfo);
        rIds.add(resourceInfo.id);
    }
    rIds.removeAll(reservedResourceIds);
    final ContainerSystem component = systemInstance.getComponent(ContainerSystem.class);
    if (component != null) {
        postConstructResources(rIds, ParentClassLoaderFinder.Helper.get(), component.getJNDIContext(), null);
    } else {
        throw new RuntimeException("ContainerSystem has not been initialzed");
    }
    // Containers - create containers using the application's classloader
    final Map<String, List<ContainerInfo>> appContainers = new HashMap<>();
    for (final ContainerInfo serviceInfo : containerSystemInfo.containers) {
        List<ContainerInfo> containerInfos = appContainers.computeIfAbsent(serviceInfo.originAppName, k -> new ArrayList<>());
        containerInfos.add(serviceInfo);
    }
    for (final Entry<String, List<ContainerInfo>> stringListEntry : appContainers.entrySet()) {
        final List<ContainerInfo> containerInfos = stringListEntry.getValue();
        final ClassLoader classLoader = appClassLoaders.get(stringListEntry.getKey());
        final ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
        try {
            if (classLoader != null) {
                Thread.currentThread().setContextClassLoader(classLoader);
            }
            for (final ContainerInfo containerInfo : containerInfos) {
                createContainer(containerInfo);
            }
        } finally {
            Thread.currentThread().setContextClassLoader(oldCl);
        }
    }
    // before any deployment bind global to be able to share the same context
    createJavaGlobal();
    for (final AppInfo appInfo : containerSystemInfo.applications) {
        try {
            // use the classloader from the map above
            createApplication(appInfo, appInfoClassLoaders.get(appInfo));
        } catch (final DuplicateDeploymentIdException e) {
        // already logged.
        } catch (final Throwable e) {
            logger.error("appNotDeployed", e, appInfo.path);
            final DeploymentExceptionManager exceptionManager = systemInstance.getComponent(DeploymentExceptionManager.class);
            if (exceptionManager != null && e instanceof Exception) {
                exceptionManager.saveDeploymentException(appInfo, (Exception) e);
            }
        }
    }
    systemInstance.fireEvent(new ContainerSystemPostCreate());
}
Also used : CoreContainerSystem(org.apache.openejb.core.CoreContainerSystem) ContainerSystem(org.apache.openejb.spi.ContainerSystem) HashMap(java.util.HashMap) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) SystemInstance(org.apache.openejb.loader.SystemInstance) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) ContainerSystemPostCreate(org.apache.openejb.assembler.classic.event.ContainerSystemPostCreate) InvalidObjectException(java.io.InvalidObjectException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ObjectStreamException(java.io.ObjectStreamException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) URISyntaxException(java.net.URISyntaxException) UndeployException(org.apache.openejb.UndeployException) DefinitionException(javax.enterprise.inject.spi.DefinitionException) ConstructionException(org.apache.xbean.recipe.ConstructionException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ValidationException(javax.validation.ValidationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) DuplicateDeploymentIdException(org.apache.openejb.DuplicateDeploymentIdException) TimeoutException(java.util.concurrent.TimeoutException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) DeploymentException(javax.enterprise.inject.spi.DeploymentException) NoSuchApplicationException(org.apache.openejb.NoSuchApplicationException) MalformedURLException(java.net.MalformedURLException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) DuplicateDeploymentIdException(org.apache.openejb.DuplicateDeploymentIdException) BatchEEServiceManager(org.apache.openejb.batchee.BatchEEServiceManager)

Aggregations

IOException (java.io.IOException)1 InvalidObjectException (java.io.InvalidObjectException)1 ObjectStreamException (java.io.ObjectStreamException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 DefinitionException (javax.enterprise.inject.spi.DefinitionException)1 DeploymentException (javax.enterprise.inject.spi.DeploymentException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1 NamingException (javax.naming.NamingException)1 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)1