private static void checkContainerState(Container container) { ContainerState state = container.getState(); if (state.equals(ContainerState.STOPPED) || state.equals(ContainerState.SHUTDOWN)) { throw BeanManagerLogger.LOG.beanManagerNotAvailable(); } }
@Override public CDI<Object> getCDI() { if (ModuleGroupSingletonProvider.deploymentClassLoaders.isEmpty()) { throw WeldLogger.ROOT_LOGGER.weldNotInitialized(); } final Container container = Container.instance(); checkContainerState(container); return containers.get(container); }
final BeanManager manager = (BeanManager) new InitialContext().lookup("java:comp/BeanManager"); if (manager != null && Container.available()) { final Bean<BoundSessionContext> sessionContextBean = (Bean<BoundSessionContext>) manager.resolve(manager.getBeans( BoundSessionContext.class, BoundLiteral.INSTANCE)); final BoundSessionContext sessionContext = (BoundSessionContext) manager.getReference(sessionContextBean, BoundSessionContext.class, ctx); sessionContext.invalidate(); sessionContext.deactivate(); sessionContext.dissociate(sessionContexts.get()); final BoundRequestContext requestContext = (BoundRequestContext) manager.getReference(requestContextBean, BoundRequestContext.class, ctx); requestContext.invalidate(); requestContext.deactivate(); requestContext.dissociate(requestContexts.get()); final BoundConversationContext conversationContext = (BoundConversationContext) manager.getReference( conversationContextBean, BoundConversationContext.class, ctx); conversationContext.invalidate(); conversationContext.deactivate(); conversationContext.dissociate(boundRequests.get());
public static boolean available(String contextId) { return isSet(contextId) && instance(contextId).getState().isAvailable(); }
final BeanManager manager = (BeanManager) new InitialContext().lookup(STANDARD_BEAN_MANAGER_JNDI_NAME); if (manager != null && Container.available()) { final BoundSessionContext sessionContext = (BoundSessionContext) manager.getReference(sessionContextBean, BoundSessionContext.class, ctx); sessionContext.associate(sessionContexts.get()); sessionContext.activate(); final BoundRequestContext requestContext = (BoundRequestContext) manager.getReference(requestContextBean, BoundRequestContext.class, ctx); requestContext.associate(requestContexts.get()); requestContext.activate(); final BoundConversationContext conversationContext = (BoundConversationContext) manager.getReference( conversationContextBean, BoundConversationContext.class, ctx); BoundRequest request = new MutableBoundRequest(requestContexts.get(), sessionContexts.get()); boundRequests.set(request); conversationContext.associate(request); conversationContext.activate();
if (!deployment.getServices().contains(ExecutorServices.class)) { addWeldService(ExecutorServices.class, executorServicesSupplier.get()); try { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(deployment.getModule().getClassLoader()); bootstrap.startContainer(deploymentName, environment, deployment); WeldProvider.containerInitialized(Container.instance(deploymentName), getBeanManager(), deployment); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
/** * 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); }
@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; }
@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 static boolean available(String contextId) { return isSet(contextId) && instance(contextId).getState().isAvailable(); }
public static boolean available(String contextId) { return isSet(contextId) && instance(contextId).getState().isAvailable(); }
public static boolean available(String contextId) { return isSet(contextId) && instance(contextId).getState().isAvailable(); }
public static boolean available(String contextId) { return isSet(contextId) && instance(contextId).getState().isAvailable(); }