javax.enterprise.inject.literal.NamedLiteral Java Examples

The following examples show how to use javax.enterprise.inject.literal.NamedLiteral. 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: JmsConnector.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
private ConnectionFactory pickTheFactory(String factoryName) {
    if (factories.isUnsatisfied()) {
        if (factoryName == null) {
            throw ex.illegalStateCannotFindFactory();
        } else {
            throw ex.illegalStateCannotFindNamedFactory(factoryName);
        }
    }

    Iterator<ConnectionFactory> iterator;
    if (factoryName == null) {
        iterator = factories.iterator();
    } else {
        iterator = factories.select(NamedLiteral.of(factoryName)).iterator();
    }

    if (!iterator.hasNext()) {
        if (factoryName == null) {
            throw ex.illegalStateCannotFindFactory();
        } else {
            throw ex.illegalStateCannotFindNamedFactory(factoryName);
        }
    }

    return iterator.next();
}
 
Example #2
Source File: AmqpClientHelper.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
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 #3
Source File: KafkaSourceTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
private ConsumptionConsumerRebalanceListener getConsumptionConsumerRebalanceListener() {
    return getBeanManager()
            .createInstance()
            .select(ConsumptionConsumerRebalanceListener.class)
            .select(NamedLiteral.of(ConsumptionConsumerRebalanceListener.class.getSimpleName()))
            .get();

}
 
Example #4
Source File: KafkaSourceTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
private StartFromFifthOffsetFromLatestConsumerRebalanceListener getStartFromFifthOffsetFromLatestConsumerRebalanceListener(
        String name) {
    return getBeanManager()
            .createInstance()
            .select(StartFromFifthOffsetFromLatestConsumerRebalanceListener.class)
            .select(NamedLiteral.of(name))
            .get();

}
 
Example #5
Source File: SyntheticObserverTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testSyntheticObserver() {
    MyObserver.EVENTS.clear();
    Arc.container().beanManager().fireEvent("foo");
    assertEquals(2, MyObserver.EVENTS.size(), "Events: " + MyObserver.EVENTS);
    assertTrue(MyObserver.EVENTS.contains("foo"));
    assertTrue(MyObserver.EVENTS.contains("foo_MyObserver"));

    MyObserver.EVENTS.clear();
    Arc.container().beanManager().fireEvent("foo", NamedLiteral.of("bla"));
    assertEquals(3, MyObserver.EVENTS.size(), "Events: " + MyObserver.EVENTS);
    assertTrue(MyObserver.EVENTS.contains("foo"));
    assertTrue(MyObserver.EVENTS.contains("foo_MyObserver"));
    assertTrue(MyObserver.EVENTS.contains("synthetic2"));
}
 
Example #6
Source File: MongoClientRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private AnnotationLiteral literal(String name) {
    if (name.startsWith(MongoClientBeanUtil.DEFAULT_MONGOCLIENT_NAME)) {
        return Default.Literal.INSTANCE;
    }
    return NamedLiteral.of(name);
}
 
Example #7
Source File: DefaultPicocliCommandLineFactory.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public CommandLine create() {
    String topCommandName = picocliConfiguration.topCommand.orElse(null);
    if (topCommandName != null) {
        Instance<Object> namedTopCommand = topCommand.select(NamedLiteral.of(topCommandName));
        if (namedTopCommand.isResolvable()) {
            return new CommandLine(namedTopCommand.get(), picocliFactory);
        }
        return new CommandLine(classForName(topCommandName), picocliFactory);
    }
    return new CommandLine(topCommand.get(), picocliFactory);
}
 
Example #8
Source File: SocketBindingGroupExtension.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {

    List<SimpleKey> configuredGroups = this.configView.simpleSubkeys(ROOT);
    for (SimpleKey groupName : configuredGroups) {
        Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, Any.Literal.INSTANCE);
        AtomicBoolean producerRequired = new AtomicBoolean(false);
        if (groups
                .stream()
                .noneMatch(e -> e.getQualifiers()
                        .stream()
                        .anyMatch(anno -> anno instanceof Named && ((Named) anno).value().equals(groupName)))) {

            SocketBindingGroup group = new SocketBindingGroup(groupName.name(), null, "0");

            applyConfiguration(group);

            if (producerRequired.get()) {
                CommonBean<SocketBindingGroup> interfaceBean = CommonBeanBuilder.newBuilder(SocketBindingGroup.class)
                        .beanClass(SocketBindingGroupExtension.class)
                        .scope(ApplicationScoped.class)
                        .addQualifier(Any.Literal.INSTANCE)
                        .addQualifier(NamedLiteral.of(group.name()))
                        .createSupplier(() -> group)
                        .addType(SocketBindingGroup.class)
                        .addType(Object.class)
                        .build();

                abd.addBean(interfaceBean);
            }
        }
    }
}
 
Example #9
Source File: InterfaceExtension.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {

    List<SimpleKey> configuredInterfaces = this.configView.simpleSubkeys(ROOT);

    for (SimpleKey interfaceName : configuredInterfaces) {

        Set<Bean<?>> ifaces = beanManager.getBeans(Interface.class, Any.Literal.INSTANCE);

        if (ifaces
                .stream()
                .noneMatch(e -> e.getQualifiers()
                        .stream()
                        .anyMatch(anno -> anno instanceof Named && ((Named) anno).value().equals(interfaceName + "-interface")))) {

            Interface iface = new Interface(interfaceName.name(), "0.0.0.0");
            applyConfiguration(iface);
            CommonBean<Interface> interfaceBean = CommonBeanBuilder.newBuilder(Interface.class)
                        .beanClass(InterfaceExtension.class)
                        .scope(ApplicationScoped.class)
                        .addQualifier(Any.Literal.INSTANCE)
                        .addQualifier(NamedLiteral.of(interfaceName.name() + "-interface"))
                        .createSupplier(() -> iface)
                        .addType(Interface.class)
                        .addType(Object.class)
                        .build();

            abd.addBean(interfaceBean);
        }
    }
}