use of io.quarkus.arc.InstanceHandle in project quarkus by quarkusio.
the class HttpSessionContext method get.
@SuppressWarnings("unchecked")
@Override
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
HttpServletRequest request = servletRequest();
if (request == null) {
throw new ContextNotActiveException();
}
InjectableBean<T> bean = (InjectableBean<T>) contextual;
ComputingCache<Key, ContextInstanceHandle<?>> contextualInstances = getContextualInstances(request);
if (creationalContext != null) {
return (T) contextualInstances.getValue(new Key(creationalContext, bean.getIdentifier())).get();
} else {
InstanceHandle<T> handle = (InstanceHandle<T>) contextualInstances.getValueIfPresent(new Key(null, bean.getIdentifier()));
return handle != null ? handle.get() : null;
}
}
use of io.quarkus.arc.InstanceHandle in project quarkus by quarkusio.
the class MicroProfileRestClientEnricher method forClass.
@Override
public void forClass(MethodCreator constructor, AssignableResultHandle webTargetBase, ClassInfo interfaceClass, IndexView index) {
ResultHandle clientHeadersFactory = null;
AnnotationInstance registerClientHeaders = interfaceClass.classAnnotation(REGISTER_CLIENT_HEADERS);
boolean useDefaultHeaders = true;
if (registerClientHeaders != null) {
String headersFactoryClass = registerClientHeaders.valueWithDefault(index).asClass().name().toString();
if (!headersFactoryClass.equals(DEFAULT_HEADERS_FACTORY)) {
// Arc.container().instance(...).get():
ResultHandle containerHandle = constructor.invokeStaticMethod(MethodDescriptor.ofMethod(Arc.class, "container", ArcContainer.class));
ResultHandle instanceHandle = constructor.invokeInterfaceMethod(MethodDescriptor.ofMethod(ArcContainer.class, "instance", InstanceHandle.class, Class.class, Annotation[].class), containerHandle, constructor.loadClassFromTCCL(headersFactoryClass), constructor.newArray(Annotation.class, 0));
clientHeadersFactory = constructor.invokeInterfaceMethod(MethodDescriptor.ofMethod(InstanceHandle.class, "get", Object.class), instanceHandle);
useDefaultHeaders = false;
}
}
if (useDefaultHeaders) {
clientHeadersFactory = constructor.newInstance(MethodDescriptor.ofConstructor(DEFAULT_HEADERS_FACTORY));
}
ResultHandle restClientFilter = constructor.newInstance(MethodDescriptor.ofConstructor(MicroProfileRestClientRequestFilter.class, ClientHeadersFactory.class), clientHeadersFactory);
constructor.assign(webTargetBase, constructor.invokeInterfaceMethod(MethodDescriptor.ofMethod(Configurable.class, "register", Configurable.class, Object.class), webTargetBase, restClientFilter));
}
use of io.quarkus.arc.InstanceHandle in project quarkus by quarkusio.
the class MongoHealthCheck method configure.
public void configure(MongodbConfig config) {
Iterable<InstanceHandle<MongoClient>> handle = Arc.container().select(MongoClient.class, Any.Literal.INSTANCE).handles();
Iterable<InstanceHandle<ReactiveMongoClient>> reactiveHandlers = Arc.container().select(ReactiveMongoClient.class, Any.Literal.INSTANCE).handles();
if (config.defaultMongoClientConfig != null) {
MongoClient client = getClient(handle, null);
ReactiveMongoClient reactiveClient = getReactiveClient(reactiveHandlers, null);
if (client != null) {
checks.add(new MongoClientCheck(CLIENT_DEFAULT, client, config.defaultMongoClientConfig));
}
if (reactiveClient != null) {
checks.add(new ReactiveMongoClientCheck(CLIENT_DEFAULT_REACTIVE, reactiveClient, config.defaultMongoClientConfig));
}
}
config.mongoClientConfigs.forEach(new BiConsumer<String, MongoClientConfig>() {
@Override
public void accept(String name, MongoClientConfig cfg) {
MongoClient client = getClient(handle, name);
ReactiveMongoClient reactiveClient = getReactiveClient(reactiveHandlers, name);
if (client != null) {
checks.add(new MongoClientCheck(name, client, config.defaultMongoClientConfig));
}
if (reactiveClient != null) {
checks.add(new ReactiveMongoClientCheck(name, reactiveClient, config.defaultMongoClientConfig));
}
}
});
}
use of io.quarkus.arc.InstanceHandle in project quarkus by quarkusio.
the class RepositoryDataAccessImplementor method getRepositoryInstance.
/**
* Implements getting repository from Arc container.
* <code>Arc.container().instance(Repository.class, new Annotation[0]).get()</code>
*/
private ResultHandle getRepositoryInstance(BytecodeCreator creator) {
ResultHandle arcContainer = creator.invokeStaticMethod(ofMethod(Arc.class, "container", ArcContainer.class));
ResultHandle instanceHandle = creator.invokeInterfaceMethod(ofMethod(ArcContainer.class, "instance", InstanceHandle.class, Class.class, Annotation[].class), arcContainer, creator.loadClassFromTCCL(repositoryClassName), creator.newArray(Annotation.class, 0));
ResultHandle instance = creator.invokeInterfaceMethod(ofMethod(InstanceHandle.class, "get", Object.class), instanceHandle);
creator.ifNull(instance).trueBranch().throwException(RuntimeException.class, repositoryClassName + " instance was not found");
return instance;
}
use of io.quarkus.arc.InstanceHandle in project quarkus by quarkusio.
the class RepositoryDataAccessImplementor method getRepositoryInstance.
/**
* Implements getting repository from Arc container.
* <code>Arc.container().instance(Repository.class, new Annotation[0]).get()</code>
*/
private ResultHandle getRepositoryInstance(BytecodeCreator creator) {
ResultHandle arcContainer = creator.invokeStaticMethod(ofMethod(Arc.class, "container", ArcContainer.class));
ResultHandle instanceHandle = creator.invokeInterfaceMethod(ofMethod(ArcContainer.class, "instance", InstanceHandle.class, Class.class, Annotation[].class), arcContainer, creator.loadClass(repositoryClassName), creator.newArray(Annotation.class, 0));
ResultHandle instance = creator.invokeInterfaceMethod(ofMethod(InstanceHandle.class, "get", Object.class), instanceHandle);
creator.ifNull(instance).trueBranch().throwException(RuntimeException.class, repositoryClassName + " instance was not found");
return instance;
}
Aggregations