Search in sources :

Example 1 with NonNull

use of io.micronaut.core.annotation.NonNull in project micronaut-kafka by micronaut-projects.

the class KafkaConsumerProcessor method getConsumer.

@NonNull
@Override
public <K, V> Consumer<K, V> getConsumer(@NonNull String id) {
    ArgumentUtils.requireNonNull("id", id);
    final Consumer consumer = getConsumerState(id).kafkaConsumer;
    if (consumer == null) {
        throw new IllegalArgumentException("No consumer found for ID: " + id);
    }
    return consumer;
}
Also used : Consumer(org.apache.kafka.clients.consumer.Consumer) NonNull(io.micronaut.core.annotation.NonNull)

Example 2 with NonNull

use of io.micronaut.core.annotation.NonNull in project micronaut-gcp by micronaut-projects.

the class DefaultPublisherFactory method createPublisher.

/**
 * Creates a publisher for a given topic.
 *
 * @param config {@link PublisherFactoryConfig} object containing all required properties.
 * @return An instance of {@link Publisher} configured using the config and environment properties from `gcp.pubsub.publisher.&gt;config_name&lt;`
 */
@Override
public Publisher createPublisher(@NonNull PublisherFactoryConfig config) {
    try {
        Publisher.Builder publisherBuilder = Publisher.newBuilder(config.getTopicState().getProjectTopicName());
        Optional<PublisherConfigurationProperties> publisherConfiguration = beanContext.findBean(PublisherConfigurationProperties.class, Qualifiers.byName(config.getTopicState().getConfigurationName()));
        String executor = publisherConfiguration.map(p -> p.getExecutor()).orElse(config.getDefaultExecutor());
        ExecutorService executorService = beanContext.getBean(ExecutorService.class, Qualifiers.byName(executor));
        publisherBuilder.setEnableMessageOrdering(config.getTopicState().getOrdered());
        if (!StringUtils.isEmpty(config.getTopicState().getEndpoint())) {
            publisherBuilder.setEndpoint(config.getTopicState().getEndpoint());
        }
        if (publisherConfiguration.isPresent()) {
            publisherBuilder.setRetrySettings(publisherConfiguration.get().getRetrySettings().build());
            // FlowControl had to be flatten in order to be parsed
            BatchingSettings batchSettings = publisherConfiguration.get().getBatchingSettings().build();
            publisherBuilder.setBatchingSettings(BatchingSettings.newBuilder().setDelayThreshold(batchSettings.getDelayThreshold()).setElementCountThreshold(batchSettings.getElementCountThreshold()).setIsEnabled(batchSettings.getIsEnabled()).setRequestByteThreshold(batchSettings.getRequestByteThreshold()).setFlowControlSettings(publisherConfiguration.get().getFlowControlSettings().build()).build());
        }
        if (!(executorService instanceof ScheduledExecutorService)) {
            throw new IllegalStateException("Invalid Executor type provided, please make sure you have a ScheduledExecutorService configured for Publisher: " + config.getTopicState().getProjectTopicName().getTopic());
        }
        publisherBuilder.setExecutorProvider(FixedExecutorProvider.create((ScheduledExecutorService) executorService));
        publisherBuilder.setChannelProvider(this.transportChannelProvider);
        publisherBuilder.setCredentialsProvider(this.credentialsProvider);
        return publisherBuilder.build();
    } catch (Exception ex) {
        throw new PubSubClientException("Failed to create subscriber", ex);
    }
}
Also used : BeanContext(io.micronaut.context.BeanContext) BatchingSettings(com.google.api.gax.batching.BatchingSettings) PublisherConfigurationProperties(io.micronaut.gcp.pubsub.configuration.PublisherConfigurationProperties) Qualifiers(io.micronaut.inject.qualifiers.Qualifiers) Singleton(jakarta.inject.Singleton) StringUtils(io.micronaut.core.util.StringUtils) NonNull(io.micronaut.core.annotation.NonNull) Publisher(com.google.cloud.pubsub.v1.Publisher) PubSubClientException(io.micronaut.gcp.pubsub.exception.PubSubClientException) Modules(io.micronaut.gcp.Modules) TransportChannelProvider(com.google.api.gax.rpc.TransportChannelProvider) CredentialsProvider(com.google.api.gax.core.CredentialsProvider) FixedExecutorProvider(com.google.api.gax.core.FixedExecutorProvider) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Optional(java.util.Optional) ExecutorService(java.util.concurrent.ExecutorService) Named(jakarta.inject.Named) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) PubSubClientException(io.micronaut.gcp.pubsub.exception.PubSubClientException) PublisherConfigurationProperties(io.micronaut.gcp.pubsub.configuration.PublisherConfigurationProperties) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Publisher(com.google.cloud.pubsub.v1.Publisher) BatchingSettings(com.google.api.gax.batching.BatchingSettings) PubSubClientException(io.micronaut.gcp.pubsub.exception.PubSubClientException)

Example 3 with NonNull

use of io.micronaut.core.annotation.NonNull in project micronaut-gcp by micronaut-projects.

the class GoogleFunctionHttpRequest method getCookies.

@NonNull
@Override
public Cookies getCookies() {
    ServletCookies cookies = this.cookies;
    if (cookies == null) {
        synchronized (this) {
            // double check
            cookies = this.cookies;
            if (cookies == null) {
                cookies = new ServletCookies(getPath(), getHeaders(), ConversionService.SHARED);
                this.cookies = cookies;
            }
        }
    }
    return cookies;
}
Also used : ServletCookies(io.micronaut.servlet.http.ServletCookies) NonNull(io.micronaut.core.annotation.NonNull)

Example 4 with NonNull

use of io.micronaut.core.annotation.NonNull in project micronaut-gcp by micronaut-projects.

the class HttpFunction method newApplicationContextBuilder.

@NonNull
@Override
protected ApplicationContextBuilder newApplicationContextBuilder() {
    final ApplicationContextBuilder builder = super.newApplicationContextBuilder();
    builder.deduceEnvironment(false);
    builder.environments(Environment.FUNCTION, Environment.GOOGLE_COMPUTE);
    return builder;
}
Also used : ApplicationContextBuilder(io.micronaut.context.ApplicationContextBuilder) NonNull(io.micronaut.core.annotation.NonNull)

Example 5 with NonNull

use of io.micronaut.core.annotation.NonNull in project micronaut-security by micronaut-projects.

the class EndSessionEndpointResolver method oktaEndSessionEndpoint.

@NonNull
private Optional<EndSessionEndpoint> oktaEndSessionEndpoint(OauthClientConfiguration oauthClientConfiguration, Supplier<OpenIdProviderMetadata> openIdProviderMetadata, EndSessionCallbackUrlBuilder endSessionCallbackUrlBuilder) {
    SecurityConfiguration securityConfiguration = beanContext.getBean(SecurityConfiguration.class);
    TokenResolver tokenResolver = beanContext.getBean(TokenResolver.class);
    return Optional.of(new OktaEndSessionEndpoint(endSessionCallbackUrlBuilder, oauthClientConfiguration, openIdProviderMetadata, securityConfiguration, tokenResolver));
}
Also used : TokenResolver(io.micronaut.security.token.reader.TokenResolver) SecurityConfiguration(io.micronaut.security.config.SecurityConfiguration) NonNull(io.micronaut.core.annotation.NonNull)

Aggregations

NonNull (io.micronaut.core.annotation.NonNull)19 Singleton (jakarta.inject.Singleton)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 ApplicationContextBuilder (io.micronaut.context.ApplicationContextBuilder)2 BeanContext (io.micronaut.context.BeanContext)2 StringUtils (io.micronaut.core.util.StringUtils)2 MediaType (io.micronaut.http.MediaType)2 Qualifiers (io.micronaut.inject.qualifiers.Qualifiers)2 OauthClientConfiguration (io.micronaut.security.oauth2.configuration.OauthClientConfiguration)2 AccessTokenGeneratedEvent (io.micronaut.security.token.event.AccessTokenGeneratedEvent)2 IOException (java.io.IOException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 BindableRockerModel (com.fizzed.rocker.BindableRockerModel)1 BatchingSettings (com.google.api.gax.batching.BatchingSettings)1 CredentialsProvider (com.google.api.gax.core.CredentialsProvider)1 FixedExecutorProvider (com.google.api.gax.core.FixedExecutorProvider)1 TransportChannelProvider (com.google.api.gax.rpc.TransportChannelProvider)1