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);
}
}
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);
}
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;
}
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();
}
}
}
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();
}
}
}
}
Aggregations