Java Code Examples for javax.enterprise.inject.Instance#isUnsatisfied()
The following examples show how to use
javax.enterprise.inject.Instance#isUnsatisfied() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfiguredChannelFactory.java From smallrye-reactive-messaging with Apache License 2.0 | 6 votes |
ConfiguredChannelFactory(@Any Instance<IncomingConnectorFactory> incomingConnectorFactories, @Any Instance<OutgoingConnectorFactory> outgoingConnectorFactories, Instance<Config> config, @Any Instance<ChannelRegistry> registry, BeanManager beanManager, boolean logConnectors) { this.registry = registry.get(); if (config.isUnsatisfied()) { this.incomingConnectorFactories = null; this.outgoingConnectorFactories = null; this.config = null; } else { this.incomingConnectorFactories = incomingConnectorFactories; this.outgoingConnectorFactories = outgoingConnectorFactories; if (logConnectors) { log.foundIncomingConnectors(getConnectors(beanManager, IncomingConnectorFactory.class)); log.foundOutgoingConnectors(getConnectors(beanManager, OutgoingConnectorFactory.class)); } //TODO Should we try to merge all the config? // For now take the first one. this.config = config.stream().findFirst() .orElseThrow(() -> ex.illegalStateRetieveConfig()); } }
Example 2
Source File: Channels.java From quarkus with Apache License 2.0 | 6 votes |
private static List<ClientInterceptor> getSortedInterceptors(Instance<ClientInterceptor> interceptors) { if (interceptors.isUnsatisfied()) { return Collections.emptyList(); } return interceptors.stream().sorted(new Comparator<ClientInterceptor>() { // NOSONAR @Override public int compare(ClientInterceptor si1, ClientInterceptor si2) { int p1 = 0; int p2 = 0; if (si1 instanceof Prioritized) { p1 = ((Prioritized) si1).getPriority(); } if (si2 instanceof Prioritized) { p2 = ((Prioritized) si2).getPriority(); } if (si1.equals(si2)) { return 0; } return Integer.compare(p1, p2); } }).collect(Collectors.toList()); }
Example 3
Source File: KafkaStreamsTopologyManager.java From quarkus with Apache License 2.0 | 6 votes |
@Inject public KafkaStreamsTopologyManager(Instance<Topology> topology, Instance<KafkaClientSupplier> kafkaClientSupplier, Instance<StateListener> stateListener, Instance<StateRestoreListener> globalStateRestoreListener) { // No producer for Topology -> nothing to do if (topology.isUnsatisfied()) { LOGGER.debug("No Topology producer; Kafka Streams will not be started"); this.executor = null; return; } this.executor = Executors.newSingleThreadExecutor(); this.topology = topology; this.kafkaClientSupplier = kafkaClientSupplier; this.stateListener = stateListener; this.globalStateRestoreListener = globalStateRestoreListener; }
Example 4
Source File: AmqpClientHelper.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
static AmqpClient createClientFromClientOptionsBean(Vertx vertx, Instance<AmqpClientOptions> instance, String optionsBeanName) { Instance<AmqpClientOptions> options = instance.select(NamedLiteral.of(optionsBeanName)); if (options.isUnsatisfied()) { throw ex.illegalStateFindingBean(AmqpClientOptions.class.getName(), optionsBeanName); } log.createClientFromBean(optionsBeanName); return AmqpClient.create(vertx, options.get()); }
Example 5
Source File: ExecutionHolder.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
@Inject public ExecutionHolder(Instance<Vertx> instanceOfVertx) { if (instanceOfVertx == null || instanceOfVertx.isUnsatisfied()) { internalVertxInstance = true; this.vertx = Vertx.vertx(); log.vertXInstanceCreated(); } else { this.vertx = instanceOfVertx.get(); } }
Example 6
Source File: ShutdownReadinessListener.java From quarkus with Apache License 2.0 | 5 votes |
@Override public void preShutdown(ShutdownNotification notification) { Instance<ShutdownReadinessCheck> instance = CDI.current().select(ShutdownReadinessCheck.class, Readiness.Literal.INSTANCE); if (!instance.isUnsatisfied()) { instance.get().shutdown(); } notification.done(); }
Example 7
Source File: InfinispanCustomizer.java From thorntail with Apache License 2.0 | 5 votes |
private ServiceActivator createActivatorIfSatisfied(Instance instance, String cacheContainer, CacheActivator.Type type) { if (instance.isUnsatisfied()) { MESSAGES.skippingCacheActivation(cacheContainer); return null; } else { return new CacheActivator(cacheContainer, type); } }
Example 8
Source File: ServletContextInjectionTest.java From tomee with Apache License 2.0 | 5 votes |
@Context public void setApplication(final Application application) { final Instance<Loader> loader = CDI.current().select(Loader.class); if (!loader.isUnsatisfied()) { loader.iterator().next().useServletContext(); } }
Example 9
Source File: TomEEOpenAPIExtension.java From tomee with Apache License 2.0 | 5 votes |
private OpenAPI createOpenApi(final Class<?> application, final Stream<Class<?>> beans) { final CDI<Object> current = CDI.current(); final OpenAPI api = ofNullable(config.read(OASConfig.MODEL_READER, null)) .map(value -> newInstance(current, value)) .map(it -> OASModelReader.class.cast(it).buildModel()) .orElseGet(() -> current.select(DefaultLoader.class).get().loadDefaultApi()); final BeanManager beanManager = current.getBeanManager(); processor.processApplication(api, new ElementImpl(beanManager.createAnnotatedType(application))); if (skipScan) { return api.paths(new PathsImpl()); } // adds the context path to the base final Instance<ServletContext> servletContextInstance = current.select(ServletContext.class); final boolean appendContextPath = Boolean.valueOf(config.read("application.append-context-path", "true")); String contextPath = ""; if (appendContextPath && !servletContextInstance.isAmbiguous() && !servletContextInstance.isUnsatisfied()) { contextPath = servletContextInstance.get().getContextPath(); } final String base = contextPath + processor.getApplicationBinding(application); processor.beforeProcessing(); beans.filter(c -> (excludeClasses == null || !excludeClasses.contains(c.getName()))) .filter(c -> (excludePackages == null || excludePackages.stream().noneMatch(it -> c.getName().startsWith(it)))) .map(beanManager::createAnnotatedType) .forEach(at -> processor.processClass( base, api, new ElementImpl(at), at.getMethods().stream().map(MethodElementImpl::new))); return ofNullable(config.read(OASConfig.FILTER, null)) .map(it -> newInstance(current, it)) .map(i -> new FilterImpl(OASFilter.class.cast(i)).filter(api)) .orElse(api); }
Example 10
Source File: ExpectedBeansUnitTest.java From quarkus with Apache License 2.0 | 4 votes |
private boolean isUnique(Instance<?> instances) { return !(instances.isAmbiguous() || instances.isUnsatisfied()); }
Example 11
Source File: GrpcServerRecorder.java From quarkus with Apache License 2.0 | 4 votes |
private static boolean hasNoServices(Instance<BindableService> services) { return services.isUnsatisfied() || services.stream().count() == 1 && services.get().bindService().getServiceDescriptor().getName().equals("grpc.health.v1.Health"); }
Example 12
Source File: PackageValidator.java From microprofile-starter with Apache License 2.0 | 3 votes |
/** * Retrieve the single CDI instance which has the classType in the bean definition. It throws the standard CDI exceptions * in case when there are no or multiple beans which are a candidate for the type. * * @param classType a {@link java.lang.Class} representing the required type * @param <T> Generic Type argument * @return CDI instance matching the class type and qualifiers (if specified). * @throws javax.enterprise.inject.AmbiguousResolutionException When more then 1 bean is found in the match * @throws UnsatisfiedResolutionException When no bean is found in the match. */ public static <T> T retrieveInstance(Class<T> classType) { Instance<T> instance = CDI.current().select(classType); if (instance.isUnsatisfied()) { throw new UnsatisfiedResolutionException(String.format("No bean found for class %s", classType.getName())); } return instance.get(); }