本文整理汇总了Java中javax.enterprise.context.spi.CreationalContext.release方法的典型用法代码示例。如果您正苦于以下问题:Java CreationalContext.release方法的具体用法?Java CreationalContext.release怎么用?Java CreationalContext.release使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.enterprise.context.spi.CreationalContext
的用法示例。
在下文中一共展示了CreationalContext.release方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInjectionTarget
import javax.enterprise.context.spi.CreationalContext; //导入方法依赖的package包/类
@Test
public void testInjectionTarget() {
BeanManager beanManager = current().getBeanManager();
// CDI uses an AnnotatedType object to read the annotations of a class
AnnotatedType<String> type = beanManager.createAnnotatedType(String.class);
// The extension uses an InjectionTarget to delegate instantiation,
// dependency injection
// and lifecycle callbacks to the CDI container
InjectionTarget<String> it = beanManager.createInjectionTarget(type);
// each instance needs its own CDI CreationalContext
CreationalContext<String> ctx = beanManager.createCreationalContext(null);
// instantiate the framework component and inject its dependencies
String instance = it.produce(ctx); // call the constructor
it.inject(instance, ctx); // call initializer methods and perform field
// injection
it.postConstruct(instance); // call the @PostConstruct method
// destroy the framework component instance and clean up dependent
// objects
assertNotNull("the String instance is injected now", instance);
assertTrue("the String instance is injected now but it's empty", instance.isEmpty());
it.preDestroy(instance); // call the @PreDestroy method
it.dispose(instance); // it is now safe to discard the instance
ctx.release(); // clean up dependent objects
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:25,代码来源:InjectSPITestCase.java
示例2: destroy
import javax.enterprise.context.spi.CreationalContext; //导入方法依赖的package包/类
/**
* Destroy the instance.
*
* @param contextual the contextual.
*/
public void destroy(Contextual contextual) {
String scopeId = (String) request.getAttribute(SCOPE_ID);
if (null != scopeId) {
HttpSession session = request.getSession();
if (contextual instanceof PassivationCapable == false) {
throw new RuntimeException("Unexpected type for contextual");
}
PassivationCapable pc = (PassivationCapable) contextual;
final String sessionKey = SCOPE_ID + "-" + scopeId;
Map<String, Object> scopeMap = (Map<String, Object>) session.getAttribute(sessionKey);
if (null != scopeMap) {
Object instance = scopeMap.get(INSTANCE + pc.getId());
CreationalContext<?> creational = (CreationalContext<?>) scopeMap.get(CREATIONAL + pc.getId());
if (null != instance && null != creational) {
contextual.destroy(instance, creational);
creational.release();
}
}
}
}
示例3: execute
import javax.enterprise.context.spi.CreationalContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <R> R execute(DefaultAssetTask task, Class<R> resultType) {
String taskId = UUID.randomUUID().toString();
TaskContext context = new DefaultTaskContext(taskId, task);
Bean<Task> bean = getBean(task.getTaskName());
CreationalContext<Task> creationalContext = (CreationalContext<Task>) beanManager.createCreationalContext(bean);
try {
CurrentTaskContext.set(context);
Task instance = (Task) beanManager.getReference(bean, Task.class, creationalContext);
R result = (R) instance.execute();
beanManager.fireEvent(new TaskExecuted(context));
return result;
} finally {
CurrentTaskContext.clear();
creationalContext.release();
}
}
示例4: execute
import javax.enterprise.context.spi.CreationalContext; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public <R> R execute(@Valid RodeoCommand<R> command) {
CreationalContext<Object> context = beanManager.createCreationalContext(null);
try {
AnnotatedType type = (AnnotatedType) beanManager.createAnnotatedType(command.getClass());
beanManager.createInjectionTarget(type).inject(command, context);
return command.execute();
} finally {
context.release();
}
}
示例5: destroy
import javax.enterprise.context.spi.CreationalContext; //导入方法依赖的package包/类
@Override
public void destroy(T instance, CreationalContext<T> creationalContext) {
try {
target.preDestroy(instance);
target.dispose(instance);
} catch (Exception cause) {
throw new InjectionException("Error while destroying " + this, cause);
} finally {
creationalContext.release();
}
}
示例6: programmaticInjection
import javax.enterprise.context.spi.CreationalContext; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> void programmaticInjection(Class clazz, T injectionObject) throws NamingException {
InitialContext initialContext = new InitialContext();
Object lookup = initialContext.lookup("java:comp/BeanManager");
BeanManager beanManager = (BeanManager) lookup;
AnnotatedType annotatedType = beanManager.createAnnotatedType(clazz);
InjectionTarget injectionTarget = beanManager.createInjectionTarget(annotatedType);
CreationalContext creationalContext = beanManager.createCreationalContext(null);
injectionTarget.inject(injectionObject, creationalContext);
creationalContext.release();
}
示例7: destroy
import javax.enterprise.context.spi.CreationalContext; //导入方法依赖的package包/类
@Override
public void destroy(Bean<T> bean, T instance, CreationalContext<T> creationalContext) {
Assert.requireNonNull(bean, "bean");
Assert.requireNonNull(creationalContext, "creationalContext");
injectionTarget.preDestroy(instance);
creationalContext.release();
}
示例8: unregisterTransformers
import javax.enterprise.context.spi.CreationalContext; //导入方法依赖的package包/类
/**
* Unregister all transformers.
*/
public void unregisterTransformers() {
for (Transformer<?, ?> transformer : _transformers) {
_transformerRegistry.removeTransformer(transformer);
}
for (CreationalContext<?> context : _cdiCreationalContexts) {
context.release();
}
_cdiCreationalContexts.clear();
}
示例9: unregisterValidators
import javax.enterprise.context.spi.CreationalContext; //导入方法依赖的package包/类
/**
* Unregister all validators.
*/
public void unregisterValidators() {
for (Validator validator : _validators) {
_validatorRegistry.removeValidator(validator);
}
for (CreationalContext<?> context : _cdiCreationalContexts) {
context.release();
}
_cdiCreationalContexts.clear();
}
示例10: destroy
import javax.enterprise.context.spi.CreationalContext; //导入方法依赖的package包/类
@Override
public void destroy(T instance, CreationalContext<T> creationalContext) {
creationalContext.release();
}
示例11: destroy
import javax.enterprise.context.spi.CreationalContext; //导入方法依赖的package包/类
@Override
public void destroy(Bean<T> bean, T instance, CreationalContext<T> creationalContext) {
creationalContext.release();
}
示例12: destroy
import javax.enterprise.context.spi.CreationalContext; //导入方法依赖的package包/类
@Override
public void destroy(final Bean<R> bean, final R instance, final CreationalContext<R> creationalContext) {
creationalContext.release();
}
示例13: destroy
import javax.enterprise.context.spi.CreationalContext; //导入方法依赖的package包/类
public void destroy(T instance, CreationalContext<T> creationalContext) {
creationalContext.release();
}
示例14: destroy
import javax.enterprise.context.spi.CreationalContext; //导入方法依赖的package包/类
@Override
public void destroy(MetricsCollector instance, CreationalContext<MetricsCollector> creationalContext) {
creationalContext.release();
}