public WeldBootstrapService(final WeldDeployment deployment, final Environment environment, final String deploymentName, final Consumer<WeldBootstrapService> weldBootstrapServiceConsumer, final Supplier<ExecutorServices> executorServicesSupplier, final Supplier<ExecutorService> serverExecutorSupplier, final Supplier<SecurityServices> securityServicesSupplier, final Supplier<TransactionServices> weldTransactionServicesSupplier ) { this.deployment = deployment; this.environment = environment; this.deploymentName = deploymentName; this.weldBootstrapServiceConsumer = weldBootstrapServiceConsumer; this.executorServicesSupplier = executorServicesSupplier; this.serverExecutorSupplier = serverExecutorSupplier; this.securityServicesSupplier = securityServicesSupplier; this.weldTransactionServicesSupplier = weldTransactionServicesSupplier; this.bootstrap = new WeldBootstrap(); Map<String, BeanDeploymentArchive> bdas = new HashMap<String, BeanDeploymentArchive>(); BeanDeploymentArchiveImpl rootBeanDeploymentArchive = null; for (BeanDeploymentArchive archive : deployment.getBeanDeploymentArchives()) { bdas.put(archive.getId(), archive); if (archive instanceof BeanDeploymentArchiveImpl) { BeanDeploymentArchiveImpl bda = (BeanDeploymentArchiveImpl) archive; if (bda.isRoot()) { rootBeanDeploymentArchive = bda; } } } this.rootBeanDeploymentArchive = rootBeanDeploymentArchive; this.beanDeploymentArchives = Collections.unmodifiableMap(bdas); }
if (!deployment.getServices().contains(ExecutorServices.class)) { addWeldService(ExecutorServices.class, executorServicesSupplier.get()); ModuleGroupSingletonProvider.addClassLoaders(deployment.getModule().getClassLoader(), deployment.getSubDeploymentClassLoaders()); WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(deployment.getModule().getClassLoader()); bootstrap.startContainer(deploymentName, environment, deployment); WeldProvider.containerInitialized(Container.instance(deploymentName), getBeanManager(), deployment);
/** * Adds a {@link Service} to the deployment. This method must not be called after the container has started */ public <T extends org.jboss.weld.bootstrap.api.Service> void addWeldService(Class<T> type, T service) { deployment.addWeldService(type, service); }
/** {@inheritDoc} */ public synchronized BeanDeploymentArchive loadBeanDeploymentArchive(final Class<?> beanClass) { final BeanDeploymentArchive bda = this.getBeanDeploymentArchive(beanClass); if (bda != null) { return bda; } Module module = Module.forClass(beanClass); if (module == null) { // Bean class loaded by the bootstrap class loader if (bootstrapClassLoaderBeanDeploymentArchive == null) { bootstrapClassLoaderBeanDeploymentArchive = createAndRegisterAdditionalBeanDeploymentArchive(module, beanClass); } else { bootstrapClassLoaderBeanDeploymentArchive.addBeanClass(beanClass); } return bootstrapClassLoaderBeanDeploymentArchive; } /* * No, there is no BDA for the class yet. Let's create one. */ return createAndRegisterAdditionalBeanDeploymentArchive(module, beanClass); }
public WeldDeployment(Set<BeanDeploymentArchiveImpl> beanDeploymentArchives, Collection<Metadata<Extension>> extensions, Module module, Set<ClassLoader> subDeploymentClassLoaders, DeploymentUnit deploymentUnit, BeanDeploymentModule rootBeanDeploymentModule, Map<ModuleIdentifier, EEModuleDescriptor> eeModuleDescriptors) { this.subDeploymentClassLoaders = new HashSet<ClassLoader>(subDeploymentClassLoaders); this.beanDeploymentArchives = Collections.newSetFromMap(new ConcurrentHashMap<>()); this.beanDeploymentArchives.addAll(beanDeploymentArchives); this.extensions = new HashSet<Metadata<Extension>>(extensions); this.serviceRegistry = new SimpleServiceRegistry(); this.additionalBeanDeploymentArchivesByClassloader = new ConcurrentHashMap<>(); this.module = module; this.rootBeanDeploymentModule = rootBeanDeploymentModule; this.eeModuleDescriptors = eeModuleDescriptors; // add static services this.serviceRegistry.add(ProxyServices.class, new ProxyServicesImpl(module)); this.serviceRegistry.add(ResourceLoader.class, new WeldModuleResourceLoader(module)); calculateAccessibilityGraph(this.beanDeploymentArchives); makeTopLevelBdasVisibleFromStaticModules(); }
/** * Starts the weld container * * @throws IllegalStateException if the container is already running */ public synchronized void start(final StartContext context) { if (started) { throw WeldMessages.MESSAGES.alreadyRunning("WeldContainer"); } started = true; WeldLogger.DEPLOYMENT_LOGGER.startingWeldService(deploymentName); // set up injected services addWeldService(SecurityServices.class, securityServices.getValue()); addWeldService(TransactionServices.class, weldTransactionServices.getValue()); for (BeanDeploymentArchive bda : getBeanDeploymentArchives()) { bda.getServices().add(ResourceInjectionServices.class, resourceInjectionServices.getValue()); } ModuleGroupSingletonProvider.addClassLoaders(deployment.getModule().getClassLoader(), deployment.getSubDeploymentClassLoaders()); ClassLoader oldTccl = SecurityActions.getContextClassLoader(); try { SecurityActions.setContextClassLoader(deployment.getModule().getClassLoader()); bootstrap.startContainer(environment, deployment); } finally { SecurityActions.setContextClassLoader(oldTccl); } }
@Override public void run() { WeldLogger.DEPLOYMENT_LOGGER.debugf("Weld container cleanup for deployment %s", deploymentName); ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); try { WildFlySecurityManager .setCurrentContextClassLoaderPrivileged(deployment.getModule().getClassLoader()); WeldProvider.containerShutDown(container); container.setState(ContainerState.SHUTDOWN); container.cleanup(); setStarted(false); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl); ModuleGroupSingletonProvider.removeClassLoader(deployment.getModule().getClassLoader()); context.complete(); } } };
public WeldBootstrapService(WeldDeployment deployment, Environment environment, final String deploymentName) { this.deployment = deployment; this.environment = environment; this.deploymentName = deploymentName; this.bootstrap = new WeldBootstrap(); Map<String, BeanDeploymentArchive> bdas = new HashMap<String, BeanDeploymentArchive>(); for (BeanDeploymentArchive archive : deployment.getBeanDeploymentArchives()) { bdas.put(archive.getId(), archive); } bdas.put(deployment.getAdditionalBeanDeploymentArchive().getId(), deployment.getAdditionalBeanDeploymentArchive()); this.beanDeploymentArchives = Collections.unmodifiableMap(bdas); }
/** * Adds a {@link Service} to the deployment. This method must not be called after the container has started */ public <T extends org.jboss.weld.bootstrap.api.Service> void addWeldService(Class<T> type, T service) { deployment.getServices().add(type, service); deployment.getAdditionalBeanDeploymentArchive().getServices().add(type, service); }
final WeldDeployment deployment = new WeldDeployment(beanDeploymentArchives, extensions, module, subDeploymentLoaders, deploymentUnit, rootBeanDeploymentModule, eeModuleDescriptors);
private void installBootstrapConfigurationService(WeldDeployment deployment, DeploymentUnit parentDeploymentUnit) { final boolean nonPortableMode = parentDeploymentUnit.getAttachment(WeldConfiguration.ATTACHMENT_KEY).isNonPortableMode(); final ExternalConfiguration configuration = new ExternalConfigurationBuilder() .add(ConfigurationKey.NON_PORTABLE_MODE.get(), nonPortableMode) .add(ConfigurationKey.ALLOW_OPTIMIZED_CLEANUP.get(), true) .build(); deployment.getServices().add(ExternalConfiguration.class, configuration); }
@Override public BeanManager getBeanManager() { checkContainerState(container); final String callerName = getCallingClassName(); if(callerName.startsWith("org.glassfish.soteria")) { //the Java EE Security RI uses CDI.current() to perform bean lookup, however //as it is part of the container its bean archive does not have visibility to deployment beans //we use this code path to enable it to get the bean manager of the current module //so it can look up the deployment beans it needs to work try { BeanManager bm = (BeanManager) new InitialContext().lookup("java:comp/BeanManager"); if(bm != null) { return bm; } } catch (NamingException e) { //ignore } } final ClassLoader tccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); final Class<?> callerClass = Reflections.loadClass(callerName, tccl); if (callerClass != null) { final BeanDeploymentArchive bda = deployment.getBeanDeploymentArchive(callerClass); if (bda != null) { return new BeanManagerProxy(container.beanDeploymentArchives().get(bda)); } } // fallback for cases when we are unable to load the class or no BeanManager exists yet for the given BDA return rootBeanManager; }
/** * Gets the {@link BeanManager} linked to the additional classes bean deployment archive. This BeanManager has access to all * beans in a deployment * * @throws IllegalStateException if the container is not running */ public BeanManager getBeanManager() { if (!started) { throw WeldMessages.MESSAGES.notStarted("WeldContainer"); } return bootstrap.getManager(deployment.getAdditionalBeanDeploymentArchive()); }
/** * Stops the container * Executed in WeldStartService to shutdown the runtime before NamingService is closed. * * @throws IllegalStateException if the container is not running */ @Override public void stop(final StopContext context) { final WeldBootstrapService bootstrapService = bootstrapSupplier.get(); if (!bootstrapService.isStarted()) { throw WeldLogger.ROOT_LOGGER.notStarted("WeldContainer"); } WeldLogger.DEPLOYMENT_LOGGER.stoppingWeldService(bootstrapService.getDeploymentName()); ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); try { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(bootstrapService.getDeployment().getModule().getClassLoader()); WeldProvider.containerShutDown(Container.instance(bootstrapService.getDeploymentName())); bootstrapService.getBootstrap().shutdown(); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl); ModuleGroupSingletonProvider.removeClassLoader(bootstrapService.getDeployment().getModule().getClassLoader()); } bootstrapService.setStarted(false); }
final WeldDeployment deployment = new WeldDeployment(beanDeploymentArchives, extensions, module, subDeploymentLoaders);
/** * Stops the container * * @throws IllegalStateException if the container is not running */ public synchronized void stop(final StopContext context) { if (!started) { throw WeldMessages.MESSAGES.notStarted("WeldContainer"); } WeldLogger.DEPLOYMENT_LOGGER.stoppingWeldService(deploymentName); ClassLoader oldTccl = SecurityActions.getContextClassLoader(); try { SecurityActions.setContextClassLoader(deployment.getModule().getClassLoader()); bootstrap.shutdown(); } finally { SecurityActions.setContextClassLoader(oldTccl); ModuleGroupSingletonProvider.removeClassLoader(deployment.getModule().getClassLoader()); } started = false; }