use of javax.enterprise.inject.Instance in project stackgres by ongres.
the class DbOpsDeployedResourceScanner method getDeployedResources.
@Override
public List<HasMetadata> getDeployedResources(StackGresDbOps config) {
try (KubernetesClient client = clientFactory.create()) {
final Map<String, String> genericLabels = labelFactory.genericLabels(config);
Stream<HasMetadata> inNamespace = IN_NAMESPACE_RESOURCE_OPERATIONS.values().stream().flatMap(resourceOperationGetter -> resourceOperationGetter.apply(client).inNamespace(config.getMetadata().getNamespace()).withLabels(genericLabels).list().getItems().stream());
List<HasMetadata> deployedResources = inNamespace.filter(resource -> resource.getMetadata().getOwnerReferences().stream().anyMatch(ownerReference -> ownerReference.getKind().equals(StackGresDbOps.KIND) && ownerReference.getName().equals(config.getMetadata().getName()) && ownerReference.getUid().equals(config.getMetadata().getUid()))).collect(Collectors.toUnmodifiableList());
deployedResources.forEach(resource -> {
Instance<DeployedResourceDecorator> decorator = decorators.select(new ReconciliationScopeLiteral(StackGresDbOps.class, resource.getKind()));
if (decorator.isResolvable()) {
decorator.get().decorate(resource);
}
});
return deployedResources;
}
}
use of javax.enterprise.inject.Instance in project stackgres by ongres.
the class BackupDeployedResourceScanner method getDeployedResources.
@Override
public List<HasMetadata> getDeployedResources(StackGresBackup config) {
try (KubernetesClient client = clientFactory.create()) {
final Map<String, String> genericLabels = labelFactory.genericLabels(config);
Stream<HasMetadata> inNamespace = IN_NAMESPACE_RESOURCE_OPERATIONS.values().stream().flatMap(resourceOperationGetter -> resourceOperationGetter.apply(client).inNamespace(config.getMetadata().getNamespace()).withLabels(genericLabels).list().getItems().stream());
List<HasMetadata> deployedResources = inNamespace.filter(resource -> resource.getMetadata().getOwnerReferences().stream().anyMatch(ownerReference -> ownerReference.getKind().equals(StackGresBackup.KIND) && ownerReference.getName().equals(config.getMetadata().getName()) && ownerReference.getUid().equals(config.getMetadata().getUid()))).collect(Collectors.toUnmodifiableList());
deployedResources.forEach(resource -> {
Instance<DeployedResourceDecorator> decorator = decorators.select(new ReconciliationScopeLiteral(StackGresBackup.class, resource.getKind()));
if (decorator.isResolvable()) {
decorator.get().decorate(resource);
}
});
return deployedResources;
}
}
use of javax.enterprise.inject.Instance in project quarkus by quarkusio.
the class InstanceBean method get.
@SuppressWarnings("unchecked")
@Override
public Instance<?> get(CreationalContext<Instance<?>> creationalContext) {
// Obtain current IP to get the required type and qualifiers
InjectionPoint ip = InjectionPointProvider.get();
InstanceImpl<Instance<?>> instance = new InstanceImpl<Instance<?>>((InjectableBean<?>) ip.getBean(), ip.getType(), ip.getQualifiers(), (CreationalContextImpl<?>) creationalContext, Collections.EMPTY_SET, ip.getMember(), 0);
CreationalContextImpl.addDependencyToParent((InjectableBean<Instance<?>>) ip.getBean(), instance, creationalContext);
return instance;
}
use of javax.enterprise.inject.Instance in project quarkus by quarkusio.
the class BuiltInBeansAreResolvableTest method testInstanceBean.
@SuppressWarnings({ "serial", "unchecked" })
@Test
public void testInstanceBean() {
BeanManager bm = Arc.container().beanManager();
// verify all selections have a backing bean
Set<Bean<?>> instanceBeans = bm.getBeans(Instance.class);
assertEquals(1, instanceBeans.size());
Set<Bean<?>> typedInstanceBeans = bm.getBeans(new TypeLiteral<Instance<DummyBean>>() {
}.getType());
assertEquals(1, typedInstanceBeans.size());
Set<Bean<?>> typedQualifiedInstanceBean = bm.getBeans(new TypeLiteral<Instance<DummyBean>>() {
}.getType(), new DummyQualifier.Literal());
assertEquals(1, typedQualifiedInstanceBean.size());
InjectionPoint dummyIp = new InjectionPoint() {
@Override
public Type getType() {
return new TypeLiteral<Instance<DummyBean>>() {
}.getType();
}
@Override
public Set<Annotation> getQualifiers() {
return new HashSet<>();
}
@Override
public Bean<?> getBean() {
return null;
}
@Override
public Member getMember() {
return null;
}
@Override
public Annotated getAnnotated() {
return null;
}
@Override
public boolean isDelegate() {
return false;
}
@Override
public boolean isTransient() {
return false;
}
};
InjectionPoint dummyIpWithQualifiers = new InjectionPoint() {
@Override
public Type getType() {
return new TypeLiteral<Instance<DummyBean>>() {
}.getType();
}
@Override
public Set<Annotation> getQualifiers() {
return new HashSet<>(Arrays.asList(Any.Literal.INSTANCE, new DummyQualifier.Literal()));
}
@Override
public Bean<?> getBean() {
return null;
}
@Override
public Member getMember() {
return null;
}
@Override
public Annotated getAnnotated() {
return null;
}
@Override
public boolean isDelegate() {
return false;
}
@Override
public boolean isTransient() {
return false;
}
};
Instance<DummyBean> dummyInstance = (Instance<DummyBean>) bm.getInjectableReference(dummyIp, new CreationalContextImpl<>(null));
// not resolvable, no qualifier
assertFalse(dummyInstance.isResolvable());
dummyInstance.select(new DummyQualifier.Literal()).get().ping();
Instance<DummyBean> dummyInstanceWithQualifier = (Instance<DummyBean>) bm.getInjectableReference(dummyIpWithQualifiers, new CreationalContextImpl<>(null));
// resolvable, qualifier is present
assertTrue(dummyInstanceWithQualifier.isResolvable());
dummyInstanceWithQualifier.get().ping();
}
use of javax.enterprise.inject.Instance in project openwebbeans by apache.
the class InstanceProducer method produce.
@Override
protected Instance<T> produce(Map<Interceptor<?>, ?> interceptors, CreationalContextImpl<Instance<T>> creationalContext) {
CreationalContextImpl<Instance<T>> creationalContextImpl = null;
try {
InjectionPoint injectionPoint = null;
if (creationalContext instanceof CreationalContextImpl) {
creationalContextImpl = creationalContext;
} else {
InstanceBean<Object> instanceBean = webBeansContext.getWebBeansUtil().getInstanceBean();
creationalContextImpl = webBeansContext.getCreationalContextFactory().wrappedCreationalContext(creationalContext, instanceBean);
}
injectionPoint = creationalContextImpl.getInjectionPoint();
Set<Annotation> qualifiers;
Type type;
if (injectionPoint != null) {
ParameterizedType injectedType = (ParameterizedType) injectionPoint.getType();
qualifiers = injectionPoint.getQualifiers();
type = injectedType.getActualTypeArguments()[0];
} else {
// an 'empty' directly resolved Instance always is for Default qualified Objects
qualifiers = DefaultLiteral.SET;
type = Object.class;
}
return new InstanceImpl<>(type, injectionPoint, webBeansContext, qualifiers.toArray(new Annotation[qualifiers.size()]));
} finally {
if (creationalContextImpl != null) {
creationalContextImpl.removeInjectionPoint();
}
}
}
Aggregations