@Vetoed public class WeldContainer extends AbstractCDI<Object> implements AutoCloseable, org.jboss.weld.environment.ContainerInstance
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 Singleton bean.
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());
Weldorg.jboss.weld.inject.WeldInstance.Handler<T>knownClassNames| Modifier and Type | Method and Description |
|---|---|
protected void |
checkState()
Check whether the container is in a "valid" state, no-op by default.
|
void |
close() |
static WeldContainer |
current()
A convenient method for
CDI.current(). |
org.jboss.weld.events.WeldEvent<Object> |
event()
Provides access to all events within the application.
|
javax.enterprise.inject.spi.BeanManager |
getBeanManager()
Provides direct access to the BeanManager.
|
String |
getId()
Weld containers must have a unique identifier assigned when there are multiple Weld instances running at once.
|
protected org.jboss.weld.inject.WeldInstance<Object> |
getInstance()
Subclasses are allowed to override the default behavior, i.e.
|
static List<String> |
getRunningContainerIds() |
javax.enterprise.inject.Instance<Object> |
instance()
Deprecated.
Applications are encouraged to use methods for programmatic lookup directly.
|
static WeldContainer |
instance(String id) |
boolean |
isRunning() |
void |
shutdown()
Shutdown the container.
|
destroy, get, getCallingClassName, getHandler, getPriorityComparator, handlers, isAmbiguous, isResolvable, isUnsatisfied, iterator, select, select, select, selectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic static WeldContainer instance(String id)
id - null if no such container existspublic static WeldContainer current()
CDI.current(). Returns current WeldContainer instance
if there is exactly one instance running. Throws IllegalStateException in any other case.WeldContainer instance if and only if exactly one instance exists{@link - IllegalStateException} if there is 0 or more than 1 instance runningpublic static List<String> getRunningContainerIds()
public javax.enterprise.inject.Instance<Object> instance()
Instance.public org.jboss.weld.events.WeldEvent<Object> event()
weldContainer.event().select(Bar.class).fire(new Bar());
public String getId()
getId in interface org.jboss.weld.environment.ContainerInstancepublic javax.enterprise.inject.spi.BeanManager getBeanManager()
getBeanManager in interface org.jboss.weld.environment.ContainerInstancegetBeanManager in class javax.enterprise.inject.spi.CDI<Object>public void shutdown()
shutdown in interface org.jboss.weld.environment.ContainerInstanceWeld.initialize()public boolean isRunning()
true if the container was initialized completely and is not shut down yet, false otherwisepublic void close()
close in interface AutoCloseableprotected org.jboss.weld.inject.WeldInstance<Object> getInstance()
AbstractCDIgetInstance in class AbstractCDI<Object>Instance the relevant calls are delegated toprotected void checkState()
AbstractCDISubclasses are allowed to override the default behavior, i.e. to check whether a container is running.
checkState in class AbstractCDI<Object>Copyright © 2017. All rights reserved.