Java Code Examples for javax.enterprise.inject.Produces

The following examples show how to use javax.enterprise.inject.Produces. These examples are extracted from open source projects. 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 Project: apicurio-registry   Source File: RegistryStorageProducer.java    License: Apache License 2.0 6 votes vote down vote up
@Produces
@ApplicationScoped
@Current
public RegistryStorage realImpl() {
    List<RegistryStorage> list = storages.stream().collect(Collectors.toList());
    RegistryStorage impl = null;
    if (list.size() == 1) {
        impl = list.get(0);
    } else {
        for (RegistryStorage rs : list) {
            if (rs instanceof InMemoryRegistryStorage == false) {
                impl = rs;
                break;
            }
        }
    }
    if (impl != null) {
        log.info(String.format("Using RegistryStore: %s", impl.getClass().getName()));
        return impl;
    }
    throw new IllegalStateException("Should not be here ... ?!");
}
 
Example 2
@Produces
@ApplicationScoped
public ReadOnlyKeyValueStore<Long, Str.TupleValue> globalIdKeyValueStore(
    KafkaStreams streams,
    HostInfo storageLocalHost,
    StreamsProperties properties
) {
    return new DistributedReadOnlyKeyValueStore<>(
        streams,
        storageLocalHost,
        properties.getGlobalIdStoreName(),
        Serdes.Long(), ProtoSerde.parsedWith(Str.TupleValue.parser()),
        new DefaultGrpcChannelProvider(),
        true,
        (filter, over, id, tuple) -> true
    );
}
 
Example 3
@Produces
@ApplicationScoped
public CloseableSupplier<Boolean> livenessCheck(
    @RegistryProperties(
            value = {"registry.kafka.common", "registry.kafka.liveness-check"},
            empties = {"ssl.endpoint.identification.algorithm="}
    ) Properties properties
) {
    AdminClient admin = AdminClient.create(properties);
    return new CloseableSupplier<Boolean>() {
        @Override
        public void close() {
            admin.close();
        }

        @Override
        public Boolean get() {
            return (admin.listTopics() != null);
        }
    };
}
 
Example 4
@Produces
@Named("my-named-options")
public AmqpClientOptions getNamedOptions() {
    // You can use the produced options to configure the TLS connection
    PemKeyCertOptions keycert = new PemKeyCertOptions()
        .addCertPath("./tls/tls.crt")
        .addKeyPath("./tls/tls.key");
    PemTrustOptions trust =
        new PemTrustOptions().addCertPath("./tlc/ca.crt");

    return new AmqpClientOptions()
        .setSsl(true)
        .setPemKeyCertOptions(keycert)
        .setPemTrustOptions(trust)
        .addEnabledSaslMechanism("EXTERNAL")
        .setHostnameVerificationAlgorithm("")
        .setConnectTimeout(30000)
        .setReconnectInterval(5000)
        .setContainerId("my-container");
}
 
Example 5
Source Project: datawave   Source File: DatawaveConfigPropertyProducer.java    License: Apache License 2.0 6 votes vote down vote up
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public List<Float> produceFloatListConfiguration(InjectionPoint injectionPoint) {
    String propertyValue = getStringPropertyValue(injectionPoint);
    String[] values = StringUtils.split(propertyValue, ",");
    
    ArrayList<Float> list = new ArrayList<>();
    if (values != null) {
        for (String value : values) {
            try {
                list.add(Float.parseFloat(value));
            } catch (NumberFormatException nfe) {
                ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class);
                throw new RuntimeException("Error while converting Float property '" + configProperty.name() + "' value: " + value + " of " + propertyValue
                                + " happening in bean " + injectionPoint.getBean(), nfe);
            }
            
        }
    }
    return list;
}
 
Example 6
Source Project: datawave   Source File: DatawaveConfigPropertyProducer.java    License: Apache License 2.0 6 votes vote down vote up
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public List<Long> produceLongListConfiguration(InjectionPoint injectionPoint) {
    String propertyValue = getStringPropertyValue(injectionPoint);
    String[] values = StringUtils.split(propertyValue, ",");
    
    ArrayList<Long> list = new ArrayList<>();
    if (values != null) {
        for (String value : values) {
            try {
                list.add(Long.parseLong(value));
            } catch (NumberFormatException nfe) {
                ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class);
                throw new RuntimeException("Error while converting Long property '" + configProperty.name() + "' value: " + value + " of " + propertyValue
                                + " happening in bean " + injectionPoint.getBean(), nfe);
            }
            
        }
    }
    return list;
}
 
Example 7
Source Project: datawave   Source File: DatawaveConfigPropertyProducer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Alternative
@Specializes
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public Boolean produceBooleanConfiguration(InjectionPoint injectionPoint) {
    return super.produceBooleanConfiguration(injectionPoint);
}
 
Example 8
Source Project: quarkus   Source File: UnlessBuildProfileTest.java    License: Apache License 2.0 5 votes vote down vote up
@Produces
@UnlessBuildProfile("test")
PingBean notTestPingBean() {
    return new PingBean() {

        @Override
        String ping() {
            return "ping not test";
        }

    };
}
 
Example 9
Source Project: quarkus   Source File: IfBuildProfileTest.java    License: Apache License 2.0 5 votes vote down vote up
@Produces
FooBean testFooBean() {
    return new FooBean() {
        @Override
        public String foo() {
            return "foo from test";
        }
    };
}
 
Example 10
@Produces
@Singleton
public KafkaStreams storageStreams(
    StreamsProperties properties,
    ForeachAction<? super String, ? super Str.Data> dataDispatcher,
    ArtifactTypeUtilProviderFactory factory
) {
    Topology topology = new StreamsTopologyProvider(properties, dataDispatcher, factory).get();

    KafkaStreams streams = new KafkaStreams(topology, properties.getProperties());
    streams.setGlobalStateRestoreListener(new LoggingStateRestoreListener());

    return streams;
}
 
Example 11
@Produces
@Singleton
public HostInfo storageLocalHost(StreamsProperties props) {
    String appServer = props.getApplicationServer();
    String[] hostPort = appServer.split(":");
    log.info("Application server gRPC: '{}'", appServer);
    return new HostInfo(hostPort[0], Integer.parseInt(hostPort[1]));
}
 
Example 12
@Produces
@Singleton
public WaitForDataService waitForDataServiceImpl(
    ReadOnlyKeyValueStore<String, Str.Data> storageKeyValueStore,
    ForeachActionDispatcher<String, Str.Data> storageDispatcher
) {
    return new WaitForDataService(storageKeyValueStore, storageDispatcher);
}
 
Example 13
Source Project: datawave   Source File: ServerSecurityProducer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Produces a {@link DatawavePrincipal} that is {@link RequestScoped}. This is the principal of the calling user--that is, the principal that is available
 * from the {@link javax.ejb.EJBContext} of an EJB.
 */
@Produces
@CallerPrincipal
@RequestScoped
public DatawavePrincipal produceCallerPrincipal() throws Exception {
    DatawavePrincipal dp = userOperationsBean.getCurrentPrincipal();
    return dp == null ? DatawavePrincipal.anonymousPrincipal() : dp;
}
 
Example 14
@Produces
@Singleton
public LocalService<AsyncBiFunctionService.WithSerdes<Void, Void, KafkaStreams.State>> localStateService(
    StateService localService
) {
    return new LocalService<>(
        StateService.NAME,
        localService
    );
}
 
Example 15
@Produces
@IfBuildProperty(name = "some.prop1", stringValue = "v1")
@IfBuildProfile("test")
GreetingBean matchingValueGreetingBean(FooBean fooBean) {
    return new GreetingBean() {

        @Override
        String greet() {
            return "hello from matching prop. Foo is: " + fooBean.foo();
        }

    };
}
 
Example 16
@Produces
@Named("my-topic-config2")
public AmqpClientOptions options2() {
    return new AmqpClientOptions()
            .setHost("localhost")
            .setPort(5672)
            .setUsername("smallrye")
            .setPassword("smallrye");
}
 
Example 17
Source Project: smallrye-metrics   Source File: MetricProducer.java    License: Apache License 2.0 5 votes vote down vote up
@Produces
<T extends Number> Gauge<T> getGauge(InjectionPoint ip) {
    // A forwarding Gauge must be returned as the Gauge creation happens when the declaring bean gets instantiated and the corresponding Gauge can be injected before which leads to producing a null value
    return () -> {
        // TODO: better error report when the gauge doesn't exist
        SortedMap<MetricID, Gauge> gauges = applicationRegistry.getGauges();
        String name = metricName.of(ip);
        MetricID gaugeId = new MetricID(name);
        return ((Gauge<T>) gauges.get(gaugeId)).getValue();
    };
}
 
Example 18
@Produces
@ApplicationScoped
public ProducerActions<Cmmn.UUID, Str.StorageValue> storageProducer(
    @RegistryProperties(
            value = {"registry.kafka.common", "registry.kafka.storage-producer"},
            empties = {"ssl.endpoint.identification.algorithm="}
    ) Properties properties
) {
    return new AsyncProducer<>(
        properties,
        ProtoSerde.parsedWith(Cmmn.UUID.parser()),
        ProtoSerde.parsedWith(Str.StorageValue.parser())
    );
}
 
Example 19
Source Project: quarkus   Source File: InfinispanClientProducer.java    License: Apache License 2.0 5 votes vote down vote up
@io.quarkus.infinispan.client.Remote
@Produces
public <K, V> RemoteCache<K, V> getRemoteCache(InjectionPoint injectionPoint, RemoteCacheManager cacheManager) {
    Set<Annotation> annotationSet = injectionPoint.getQualifiers();

    final io.quarkus.infinispan.client.Remote remote = getRemoteAnnotation(annotationSet);

    if (remote != null && !remote.value().isEmpty()) {
        return cacheManager.getCache(remote.value());
    }

    return cacheManager.getCache();
}
 
Example 20
Source Project: camel-quarkus   Source File: CamelRouteProducer.java    License: Apache License 2.0 5 votes vote down vote up
@Produces
RoutesBuilder producedRoute() {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:produced")
                    .id("produced")
                    .to("log:produced");
        }
    };
}
 
Example 21
Source Project: quarkus   Source File: MySQLPoolProducer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Produces the RX MySQL Pool instance. The instance is created lazily.
 *
 * @return the RX MySQL pool instance
 * @deprecated The RX API is deprecated and will be removed in the future, use {@link #mutinyMySQLPool()} instead.
 */
@Singleton
@Produces
@Deprecated
public io.vertx.reactivex.mysqlclient.MySQLPool rxMySQLPool() {
    LOGGER.warn(
            "`io.vertx.reactivex.mysqlclient.MySQLPool` is deprecated and will be removed in a future version - it is "
                    + "recommended to switch to `io.vertx.mutiny.mysqlclient.MySQLPool`");
    return io.vertx.reactivex.mysqlclient.MySQLPool.newInstance(mysqlPool);
}
 
Example 22
Source Project: datawave   Source File: DatawaveConfigPropertyProducer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Alternative
@Specializes
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public Float produceFloatConfiguration(InjectionPoint injectionPoint) {
    return super.produceFloatConfiguration(injectionPoint);
}
 
Example 23
Source Project: krazo   Source File: DefaultTemplateEngineProducer.java    License: Apache License 2.0 5 votes vote down vote up
@Produces
@ViewEngineConfig
public TemplateEngine getTemplateEngine() {

    ITemplateResolver resolver = new ServletContextTemplateResolver(this.servletContext);

    TemplateEngine engine = new TemplateEngine();
    engine.setTemplateResolver(resolver);
    return engine;

}
 
Example 24
Source Project: camel-quarkus   Source File: CamelProducers.java    License: Apache License 2.0 5 votes vote down vote up
@Produces
FluentProducerTemplate camelFluentProducerTemplate(InjectionPoint injectionPoint) {
    final FluentProducerTemplate template = this.context.createFluentProducerTemplate();
    final Produce produce = injectionPoint.getAnnotated().getAnnotation(Produce.class);

    if (ObjectHelper.isNotEmpty(produce) && ObjectHelper.isNotEmpty(produce.value())) {
        template.setDefaultEndpointUri(produce.value());
    }

    return template;
}
 
Example 25
Source Project: quarkus   Source File: MailClientProducer.java    License: Apache License 2.0 5 votes vote down vote up
@Singleton
@Produces
@Deprecated
public io.vertx.reactivex.ext.mail.MailClient rxMailClient() {
    LOGGER.warn(
            "`io.vertx.reactivex.ext.mail.MailClient` is deprecated and will be removed in a future version - it is "
                    + "recommended to switch to `io.vertx.mutiny.ext.mail.MailClient`");
    return io.vertx.reactivex.ext.mail.MailClient.newInstance(client);
}
 
Example 26
Source Project: quarkus   Source File: IfBuildProfileTest.java    License: Apache License 2.0 5 votes vote down vote up
@Produces
@IfBuildProfile("dev")
GreetingBean devGreetingBean(BarBean barBean) {
    return new GreetingBean() {

        @Override
        String greet() {
            return "hello from dev";
        }

    };
}
 
Example 27
Source Project: cdi   Source File: AxonConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Produces the entity manager provider.
 *
 * @return entity manager provider.
 */
@Produces
@ApplicationScoped
public EntityManagerProvider entityManagerProvider(
        EntityManager entityManager) {
    return new SimpleEntityManagerProvider(entityManager);
}
 
Example 28
Source Project: quarkus   Source File: KafkaStreamsPipeline.java    License: Apache License 2.0 5 votes vote down vote up
@Produces
public Topology buildTopology() {
    StreamsBuilder builder = new StreamsBuilder();

    ObjectMapperSerde<Category> categorySerde = new ObjectMapperSerde<>(Category.class);
    ObjectMapperSerde<Customer> customerSerde = new ObjectMapperSerde<>(Customer.class);
    ObjectMapperSerde<EnrichedCustomer> enrichedCustomerSerde = new ObjectMapperSerde<>(EnrichedCustomer.class);

    KTable<Integer, Category> categories = builder.table(
            "streams-test-categories",
            Consumed.with(Serdes.Integer(), categorySerde));

    KStream<Integer, EnrichedCustomer> customers = builder
            .stream("streams-test-customers", Consumed.with(Serdes.Integer(), customerSerde))
            .selectKey((id, customer) -> customer.category)
            .join(
                    categories,
                    (customer, category) -> {
                        return new EnrichedCustomer(customer.id, customer.name, category);
                    },
                    Joined.with(Serdes.Integer(), customerSerde, categorySerde));

    KeyValueBytesStoreSupplier storeSupplier = Stores.inMemoryKeyValueStore("countstore");
    customers.groupByKey()
            .count(Materialized.<Integer, Long> as(storeSupplier));

    customers.selectKey((categoryId, customer) -> customer.id)
            .to("streams-test-customers-processed", Produced.with(Serdes.Integer(), enrichedCustomerSerde));

    return builder.build();
}
 
Example 29
Source Project: quarkus-quickstarts   Source File: TopologyProducer.java    License: Apache License 2.0 5 votes vote down vote up
@Produces
public Topology buildTopology() {
    StreamsBuilder builder = new StreamsBuilder();

    JsonbSerde<WeatherStation> weatherStationSerde = new JsonbSerde<>(WeatherStation.class);
    JsonbSerde<Aggregation> aggregationSerde = new JsonbSerde<>(Aggregation.class);

    KeyValueBytesStoreSupplier storeSupplier = Stores.persistentKeyValueStore(WEATHER_STATIONS_STORE);

    GlobalKTable<Integer, WeatherStation> stations = builder.globalTable(
            WEATHER_STATIONS_TOPIC,
            Consumed.with(Serdes.Integer(), weatherStationSerde));

    builder.stream(
            TEMPERATURE_VALUES_TOPIC,
            Consumed.with(Serdes.Integer(), Serdes.String()))
            .join(
                    stations,
                    (stationId, timestampAndValue) -> stationId,
                    (timestampAndValue, station) -> {
                        String[] parts = timestampAndValue.split(";");
                        return new TemperatureMeasurement(station.id, station.name, Instant.parse(parts[0]),
                                Double.valueOf(parts[1]));
                    })
            .groupByKey()
            .aggregate(
                    Aggregation::new,
                    (stationId, value, aggregation) -> aggregation.updateFrom(value),
                    Materialized.<Integer, Aggregation> as(storeSupplier)
                            .withKeySerde(Serdes.Integer())
                            .withValueSerde(aggregationSerde))
            .toStream()
            .to(
                    TEMPERATURES_AGGREGATED_TOPIC,
                    Produced.with(Serdes.Integer(), aggregationSerde));

    return builder.build();
}
 
Example 30
Source Project: smallrye-config   Source File: ConfigSourceProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Produces
@Name("")
public ConfigSource produceConfigSource(final InjectionPoint injectionPoint) {
    Set<Annotation> qualifiers = injectionPoint.getQualifiers();
    String name = getName(qualifiers);
    return configSourceMap.get(name);
}