Package org.jboss.weld.environment.se
Class WeldContainer
- java.lang.Object
-
- javax.enterprise.inject.spi.CDI<T>
-
- org.jboss.weld.AbstractCDI<Object>
-
- org.jboss.weld.environment.se.WeldContainer
-
- All Implemented Interfaces:
AutoCloseable,Iterable<Object>,javax.enterprise.inject.Instance<Object>,javax.inject.Provider<Object>,ContainerInstance
@Vetoed public class WeldContainer extends AbstractCDI<Object> implements AutoCloseable, ContainerInstance
Represents a Weld SE container.An new instance can be initialized using the Weld builder:
WeldContainer container = new Weld().initialize();
It's also possible to obtain the instance of a running container by id:
WeldContainer container = WeldContainer.instance("myCustomId");shutdown()must be always called to shutdown the container properly. AutoCloseable is implemented, so the container is automatically shut down when leaving the try-with-resources block:try (WeldContainer container = new Weld().initialize()) { container.select(Foo.class).get(); }The container is also registered as a
Singletonbean.Provides convenient access to beans, BeanManager and events, which is particularly helpful when bootstrapping an application in Java SE:
Foo foo = container.select(Foo.class).get(); container.getBeanManager().fireEvent(new Bar()) container.event().select(Bar.class).fire(new Bar());
- Author:
- Peter Royle, Martin Kouba
- See Also:
Weld
-
-
Field Summary
-
Fields inherited from class org.jboss.weld.AbstractCDI
knownClassNames
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()javax.enterprise.event.Event<Object>event()Provides access to all events within the application.javax.enterprise.inject.spi.BeanManagergetBeanManager()Provides direct access to the BeanManager.StringgetId()Weld containers must have a unique identifier assigned when there are multiple Weld instances running at once.protected javax.enterprise.inject.Instance<Object>getInstance()Subclasses are allowed to override the default behavior, i.e.static List<String>getRunningContainerIds()javax.enterprise.inject.Instance<Object>instance()Provides access to all beans within the application.static WeldContainerinstance(String id)booleanisRunning()voidshutdown()Shutdown the container.-
Methods inherited from class org.jboss.weld.AbstractCDI
destroy, get, getCallingClassName, isAmbiguous, isUnsatisfied, iterator, select, select, select
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
instance
public static WeldContainer instance(String id)
- Parameters:
id-- Returns:
- the running container with the specified identifier or
nullif no such container exists
-
getRunningContainerIds
public static List<String> getRunningContainerIds()
- Returns:
- an immutable list of ids of running containers
-
instance
public javax.enterprise.inject.Instance<Object> instance()
Provides access to all beans within the application. Retained for backward compatibility.- Returns:
- the instance
-
event
public javax.enterprise.event.Event<Object> event()
Provides access to all events within the application. For example:weldContainer.event().select(Bar.class).fire(new Bar());- Returns:
- the event
-
getId
public String getId()
Weld containers must have a unique identifier assigned when there are multiple Weld instances running at once.- Specified by:
getIdin interfaceContainerInstance- Returns:
- the container id
-
getBeanManager
public javax.enterprise.inject.spi.BeanManager getBeanManager()
Provides direct access to the BeanManager.- Specified by:
getBeanManagerin interfaceContainerInstance- Specified by:
getBeanManagerin classjavax.enterprise.inject.spi.CDI<Object>- Returns:
- beanManager
-
shutdown
public void shutdown()
Shutdown the container.- Specified by:
shutdownin interfaceContainerInstance- See Also:
Weld.initialize()
-
isRunning
public boolean isRunning()
- Returns:
trueif the container was not shut down yet,falseotherwise
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
getInstance
protected javax.enterprise.inject.Instance<Object> getInstance()
Description copied from class:AbstractCDISubclasses are allowed to override the default behavior, i.e. to cache instance per BeanManager.- Overrides:
getInstancein classAbstractCDI<Object>- Returns:
- the
Instancethe relevant calls are delegated to
-
-