use of io.quarkus.arc.InjectableContext in project quarkus by quarkusio.
the class ClientProxies method getDelegate.
public static <T> T getDelegate(InjectableBean<T> bean) {
List<InjectableContext> contexts = Arc.container().getContexts(bean.getScope());
T result = null;
if (contexts.size() == 1) {
result = contexts.get(0).getIfActive(bean, ClientProxies::newCreationalContext);
} else {
InjectableContext selectedContext = null;
for (int i = 0; i < contexts.size(); i++) {
InjectableContext context = contexts.get(i);
if (result != null) {
if (context.isActive()) {
throw new IllegalArgumentException("More than one context object for the given scope: " + selectedContext + " " + context);
}
} else {
result = context.getIfActive(bean, ClientProxies::newCreationalContext);
if (result != null) {
selectedContext = context;
}
}
}
}
if (result == null) {
throw new ContextNotActiveException();
}
return result;
}
use of io.quarkus.arc.InjectableContext in project camunda-bpm-platform by camunda.
the class BusinessProcessContextTest method shouldThrowUnsupportedOperationExceptionOnInjectableContextGetState.
@Test
public void shouldThrowUnsupportedOperationExceptionOnInjectableContextGetState() {
InjectableContext businessProcessContext = Arc.container().getActiveContext(BusinessProcessScoped.class);
assertThatThrownBy(businessProcessContext::getState).isInstanceOf(UnsupportedOperationException.class).hasMessage("io.quarkus.arc.InjectableContext#getState is unsupported");
}
use of io.quarkus.arc.InjectableContext in project camunda-bpm-platform by camunda.
the class BusinessProcessContextTest method shouldThrowUnsupportedOperationExceptionOnInjectableContextDestroyContextual.
@Test
public void shouldThrowUnsupportedOperationExceptionOnInjectableContextDestroyContextual() {
Bean<?> bean = Arc.container().beanManager().getBeans(BusinessProcessScopedBean.class).stream().findFirst().get();
InjectableContext businessProcessContext = Arc.container().getActiveContext(BusinessProcessScoped.class);
assertThatThrownBy(() -> businessProcessContext.destroy(bean)).isInstanceOf(UnsupportedOperationException.class).hasMessage("io.quarkus.arc.InjectableContext#destroy(contextual) is unsupported");
}
use of io.quarkus.arc.InjectableContext in project camunda-bpm-platform by camunda.
the class BusinessProcessContextTest method shouldThrowUnsupportedOperationExceptionOnInjectableContextDestroy.
@Test
public void shouldThrowUnsupportedOperationExceptionOnInjectableContextDestroy() {
InjectableContext businessProcessContext = Arc.container().getActiveContext(BusinessProcessScoped.class);
assertThatThrownBy(businessProcessContext::destroy).isInstanceOf(UnsupportedOperationException.class).hasMessage("io.quarkus.arc.InjectableContext#destroy is unsupported");
}
use of io.quarkus.arc.InjectableContext in project quarkus by quarkusio.
the class InstanceImpl method destroy.
@Override
public void destroy(Object instance) {
Objects.requireNonNull(instance);
if (instance instanceof ClientProxy) {
ClientProxy proxy = (ClientProxy) instance;
InjectableContext context = Arc.container().getActiveContext(proxy.arc_bean().getScope());
if (context == null) {
throw new ContextNotActiveException("No active context found for: " + proxy.arc_bean().getScope());
}
context.destroy(proxy.arc_bean());
} else {
// First try to destroy a dependent instance
if (!creationalContext.destroyDependentInstance(instance)) {
// If not successful then try the singleton context
SingletonContext singletonContext = (SingletonContext) Arc.container().getActiveContext(Singleton.class);
singletonContext.destroyInstance(instance);
}
}
}
Aggregations