Search in sources :

Example 1 with Container

use of org.jboss.weld.Container in project core by weld.

the class WeldBuilderTest method testInterceptorBuilder.

@Test
public void testInterceptorBuilder() {
    try (WeldContainer container = new Weld().disableDiscovery().beanClasses(Coorge.class, BuilderInterceptorBinding.class).addContainerLifecycleObserver(ContainerLifecycleObserver.afterBeanDiscovery((e) -> e.addInterceptor().addBinding(new BuilderInterceptorBinding.BuilderInterceptorBindingLiteral()).priority(2500).intercept(InterceptionType.AROUND_INVOKE, invocationContext -> {
        try {
            Integer result = ((Integer) invocationContext.proceed());
            return result + 10;
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return null;
    }))).initialize()) {
        Coorge coorge = container.select(Coorge.class).get();
        assertEquals(coorge.ping(), 11);
    }
}
Also used : Alpha2(org.jboss.weld.environment.se.test.builder.alphas.Alpha2) ContainerLifecycleObserver.afterBeanDiscovery(org.jboss.weld.environment.se.ContainerLifecycleObserver.afterBeanDiscovery) ConfigurationKey(org.jboss.weld.config.ConfigurationKey) Assert.assertTrue(org.junit.Assert.assertTrue) ObserverException(javax.enterprise.event.ObserverException) Test(org.junit.Test) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) WeldContainer(org.jboss.weld.environment.se.WeldContainer) DefinitionException(javax.enterprise.inject.spi.DefinitionException) Alpha1(org.jboss.weld.environment.se.test.builder.alphas.Alpha1) WeldConfiguration(org.jboss.weld.config.WeldConfiguration) Beta2(org.jboss.weld.environment.se.test.builder.alphas.betas.Beta2) ArrayList(java.util.ArrayList) Beta1(org.jboss.weld.environment.se.test.builder.alphas.betas.Beta1) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) ContainerLifecycleObserver(org.jboss.weld.environment.se.ContainerLifecycleObserver) Assert.assertFalse(org.junit.Assert.assertFalse) Any(javax.enterprise.inject.Any) InterceptionType(javax.enterprise.inject.spi.InterceptionType) Assert.assertEquals(org.junit.Assert.assertEquals) Container(org.jboss.weld.Container) Weld(org.jboss.weld.environment.se.Weld) WeldContainer(org.jboss.weld.environment.se.WeldContainer) ObserverException(javax.enterprise.event.ObserverException) DefinitionException(javax.enterprise.inject.spi.DefinitionException) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 2 with Container

use of org.jboss.weld.Container in project wildfly by wildfly.

the class WeldProvider method getCDI.

@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);
}
Also used : Container(org.jboss.weld.Container)

Example 3 with Container

use of org.jboss.weld.Container in project core by weld.

the class ConversationAwareViewHandler method getConversationContext.

/**
 * Get conversation context. May return null if the container is not available.
 *
 * @return the conversation context or null if the container is not booted
 */
private ConversationContext getConversationContext(String id) {
    if (conversationContext == null) {
        synchronized (this) {
            if (conversationContext == null) {
                if (!Container.available(id)) {
                    return null;
                }
                Container container = Container.instance(id);
                conversationContext = container.deploymentManager().instance().select(HttpConversationContext.class).get();
            }
        }
    }
    return conversationContext;
}
Also used : Container(org.jboss.weld.Container)

Example 4 with Container

use of org.jboss.weld.Container in project core by weld.

the class WeldRuntime method shutdown.

public void shutdown() {
    try {
        // The container must destroy all contexts.
        // For non-web modules, fire @BeforeDestroyed event
        fireEventForNonWebModules(Object.class, ContextEvent.APPLICATION_BEFORE_DESTROYED, BeforeDestroyedLiteral.APPLICATION);
        deploymentManager.instance().select(ApplicationContext.class).get().invalidate();
        deploymentManager.instance().select(SingletonContext.class).get().invalidate();
    } finally {
        // fire @Destroyed(ApplicationScope.class) for non-web modules
        fireEventForNonWebModules(Object.class, ContextEvent.APPLICATION_DESTROYED, DestroyedLiteral.APPLICATION);
        try {
            // Finally, the container must fire an event of type BeforeShutdown.
            BeforeShutdownImpl.fire(deploymentManager);
        } finally {
            Container container = Container.instance(contextId);
            container.setState(ContainerState.SHUTDOWN);
            container.cleanup();
        }
    }
}
Also used : Container(org.jboss.weld.Container)

Example 5 with Container

use of org.jboss.weld.Container in project wildfly by wildfly.

the class WeldBootstrapService method stop.

/**
 * This is a no-op if {@link WeldStartService#start(StartContext)} completes normally and the shutdown is performed in
 * {@link WeldStartService#stop(org.jboss.msc.service.StopContext)}.
 */
public synchronized void stop(final StopContext context) {
    weldBootstrapServiceConsumer.accept(null);
    if (started) {
        // WeldStartService#stop() not completed - attempt to perform the container cleanup
        final Container container = Container.instance(deploymentName);
        if (container != null && !ContainerState.SHUTDOWN.equals(container.getState())) {
            context.asynchronous();
            final ExecutorService executorService = serverExecutorSupplier.get();
            final Runnable task = new Runnable() {

                @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();
                        startServiceShutdown();
                    } finally {
                        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
                        ModuleGroupSingletonProvider.removeClassLoader(deployment.getModule().getClassLoader());
                        context.complete();
                    }
                }
            };
            try {
                executorService.execute(task);
            } catch (RejectedExecutionException e) {
                task.run();
            }
        }
    }
}
Also used : Container(org.jboss.weld.Container) ExecutorService(java.util.concurrent.ExecutorService) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

Container (org.jboss.weld.Container)5 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ObserverException (javax.enterprise.event.ObserverException)1 Any (javax.enterprise.inject.Any)1 DefinitionException (javax.enterprise.inject.spi.DefinitionException)1 InterceptionType (javax.enterprise.inject.spi.InterceptionType)1 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)1 ConfigurationKey (org.jboss.weld.config.ConfigurationKey)1 WeldConfiguration (org.jboss.weld.config.WeldConfiguration)1 ContainerLifecycleObserver (org.jboss.weld.environment.se.ContainerLifecycleObserver)1 ContainerLifecycleObserver.afterBeanDiscovery (org.jboss.weld.environment.se.ContainerLifecycleObserver.afterBeanDiscovery)1 Weld (org.jboss.weld.environment.se.Weld)1 WeldContainer (org.jboss.weld.environment.se.WeldContainer)1 Alpha1 (org.jboss.weld.environment.se.test.builder.alphas.Alpha1)1 Alpha2 (org.jboss.weld.environment.se.test.builder.alphas.Alpha2)1 Beta1 (org.jboss.weld.environment.se.test.builder.alphas.betas.Beta1)1 Beta2 (org.jboss.weld.environment.se.test.builder.alphas.betas.Beta2)1