javax.inject.Singleton Java Examples

The following examples show how to use javax.inject.Singleton. 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: KuduModule.java    From presto with Apache License 2.0 6 votes vote down vote up
@Singleton
@Provides
KuduClientSession createKuduClientSession(KuduClientConfig config)
{
    requireNonNull(config, "config is null");

    KuduClient.KuduClientBuilder builder = new KuduClient.KuduClientBuilder(config.getMasterAddresses());
    builder.defaultAdminOperationTimeoutMs(config.getDefaultAdminOperationTimeout().toMillis());
    builder.defaultOperationTimeoutMs(config.getDefaultOperationTimeout().toMillis());
    builder.defaultSocketReadTimeoutMs(config.getDefaultSocketReadTimeout().toMillis());
    if (config.isDisableStatistics()) {
        builder.disableStatistics();
    }
    KuduClient client = builder.build();

    SchemaEmulation strategy;
    if (config.isSchemaEmulationEnabled()) {
        strategy = new SchemaEmulationByTableNameConvention(config.getSchemaEmulationPrefix());
    }
    else {
        strategy = new NoSchemaEmulation();
    }
    return new KuduClientSession(client, strategy);
}
 
Example #2
Source File: WordCountStream.java    From micronaut-kafka with Apache License 2.0 6 votes vote down vote up
@Singleton
@Named(MY_STREAM)
KStream<String, String> myStream(
        @Named(MY_STREAM) ConfiguredStreamBuilder builder) {

    // end::namedStream[]
    // set default serdes
    Properties props = builder.getConfiguration();
    props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
    props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
    props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

    KStream<String, String> source = builder.stream(NAMED_WORD_COUNT_INPUT);
    KTable<String, Long> counts = source
            .flatMapValues(value -> Arrays.asList(value.toLowerCase(Locale.getDefault()).split(" ")))
            .groupBy((key, value) -> value)
            .count();

    // need to override value serde to Long type
    counts.toStream().to(NAMED_WORD_COUNT_OUTPUT, Produced.with(Serdes.String(), Serdes.Long()));
    return source;
}
 
Example #3
Source File: DefaultKernelControlCenterExtensionsModule.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private void configureControlCenterDependencies() {
  KernelControlCenterConfiguration configuration
      = getConfigBindingProvider().get(KernelControlCenterConfiguration.PREFIX,
                                       KernelControlCenterConfiguration.class);
  bind(KernelControlCenterConfiguration.class).toInstance(configuration);

  Multibinder<org.opentcs.components.kernel.ControlCenterPanel> modellingBinder
      = controlCenterPanelBinderModelling();
  // No extensions for modelling mode, yet.

  Multibinder<org.opentcs.components.kernel.ControlCenterPanel> operatingBinder
      = controlCenterPanelBinderOperating();
  operatingBinder.addBinding().to(DriverGUI.class);

  install(new FactoryModuleBuilder().build(ControlCenterInfoHandlerFactory.class));

  bind(KernelControlCenter.class).in(Singleton.class);
}
 
Example #4
Source File: LocalPersistenceFileModule.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
private void bindLocalPersistence(
        final @NotNull Class localPersistenceClass,
        final @NotNull Class localPersistenceImplClass,
        final @Nullable Class localPersistenceProviderClass) {

    final Object instance = persistenceInjector.getInstance(localPersistenceImplClass);
    if (instance != null) {
        bind(localPersistenceImplClass).toInstance(instance);
        bind(localPersistenceClass).toInstance(instance);
    } else {
        if (localPersistenceProviderClass != null) {
            bind(localPersistenceClass).toProvider(localPersistenceProviderClass).in(Singleton.class);
        } else {
            bind(localPersistenceClass).to(localPersistenceImplClass).in(Singleton.class);
        }
    }
}
 
Example #5
Source File: ComponentsInjectionModule.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {
  // Within this (private) module, there should only be a single tree panel.
  bind(BlocksTreeViewPanel.class)
      .in(Singleton.class);

  // Bind the tree panel annotated with the given annotation to our single
  // instance and expose only this annotated version.
  bind(AbstractTreeViewPanel.class)
      .to(BlocksTreeViewPanel.class);
  expose(BlocksTreeViewPanel.class);

  // Bind TreeView to the single tree panel, too.
  bind(TreeView.class)
      .to(BlocksTreeViewPanel.class);

  // Bind and expose a single manager for the single tree view/panel.
  bind(BlocksTreeViewManager.class)
      .in(Singleton.class);
  expose(BlocksTreeViewManager.class);

  bind(MouseListener.class)
      .to(BlockMouseListener.class);
}
 
Example #6
Source File: PersistenceMigrationModule.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {

    bind(ShutdownHooks.class).asEagerSingleton();
    bind(PersistenceStartup.class).asEagerSingleton();
    bind(PersistenceStartupShutdownHookInstaller.class).asEagerSingleton();

    if (persistenceConfigurationService.getMode() == PersistenceConfigurationService.PersistenceMode.FILE) {
        install(new PersistenceMigrationFileModule());
    } else {
        install(new LocalPersistenceMemoryModule(null));
    }

    bind(PublishPayloadPersistence.class).to(PublishPayloadPersistenceImpl.class).in(Singleton.class);

    bind(MetricRegistry.class).toInstance(metricRegistry);
    bind(MetricsHolder.class).toProvider(MetricsHolderProvider.class).asEagerSingleton();

    bind(ListeningScheduledExecutorService.class).annotatedWith(PayloadPersistence.class)
            .toProvider(PayloadPersistenceScheduledExecutorProvider.class)
            .in(LazySingleton.class);

    bind(MessageDroppedService.class).toProvider(MessageDroppedServiceProvider.class).in(Singleton.class);

}
 
Example #7
Source File: WordCountStream.java    From micronaut-kafka with Apache License 2.0 6 votes vote down vote up
@Singleton
@Named(STREAM_WORD_COUNT)
KStream<String, String> wordCountStream(ConfiguredStreamBuilder builder) { // <3>
    // set default serdes
    Properties props = builder.getConfiguration();
    props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
    props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
    props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

    KStream<String, String> source = builder
            .stream(INPUT);

    KTable<String, Long> groupedByWord = source
            .flatMapValues(value -> Arrays.asList(value.toLowerCase().split("\\W+")))
            .groupBy((key, word) -> word, Grouped.with(Serdes.String(), Serdes.String()))
            //Store the result in a store for lookup later
            .count(Materialized.as(WORD_COUNT_STORE)); // <4>

    groupedByWord
            //convert to stream
            .toStream()
            //send to output using specific serdes
            .to(OUTPUT, Produced.with(Serdes.String(), Serdes.Long()));

    return source;
}
 
Example #8
Source File: StackdriverSenderFactory.java    From micronaut-gcp with Apache License 2.0 6 votes vote down vote up
/**
 * The {@link StackdriverSender} bean.
 * @param cloudConfiguration The google cloud configuration
 * @param credentials The credentials
 * @param channel The channel to use
 * @return The sender
 */
@RequiresGoogleProjectId
@Requires(classes = StackdriverSender.class)
@Singleton
protected @Nonnull Sender stackdriverSender(
        @Nonnull GoogleCloudConfiguration cloudConfiguration,
        @Nonnull GoogleCredentials credentials,
        @Nonnull @Named("stackdriverTraceSenderChannel") ManagedChannel channel) {

    GoogleCredentials traceCredentials = credentials.createScoped(Arrays.asList(TRACE_SCOPE.toString()));

    return StackdriverSender.newBuilder(channel)
            .projectId(cloudConfiguration.getProjectId())
            .callOptions(CallOptions.DEFAULT
                    .withCallCredentials(MoreCallCredentials.from(traceCredentials)))
            .build();
}
 
Example #9
Source File: CachingHiveMetastoreModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
public HiveMetastore createCachingHiveMetastore(
        @ForCachingHiveMetastore HiveMetastore delegate,
        @ForCachingHiveMetastore Executor executor,
        CachingHiveMetastoreConfig config,
        Optional<HiveMetastoreDecorator> hiveMetastoreDecorator)
{
    HiveMetastore decoratedDelegate = hiveMetastoreDecorator.map(decorator -> decorator.decorate(delegate))
            .orElse(delegate);
    return cachingHiveMetastore(decoratedDelegate, executor, config);
}
 
Example #10
Source File: TestHttpBackupStore.java    From presto with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@ForHttpBackup
public Supplier<URI> createBackupUriSupplier(HttpServerInfo serverInfo)
{
    return serverInfo::getHttpUri;
}
 
Example #11
Source File: CredentialProviderModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@ForExtraCredentialProvider
public CredentialProvider getCredentialProvider(KeyStoreBasedCredentialProviderConfig config)
        throws IOException, GeneralSecurityException
{
    KeyStore keyStore = loadKeyStore(config.getKeyStoreType(), config.getKeyStoreFilePath(), config.getKeyStorePassword());
    String user = readEntity(keyStore, config.getUserCredentialName(), config.getPasswordForUserCredentialName());
    String password = readEntity(keyStore, config.getPasswordCredentialName(), config.getPasswordForPasswordCredentialName());
    return new StaticCredentialProvider(Optional.of(user), Optional.of(password));
}
 
Example #12
Source File: GrpcServerTracingInterceptorFactory.java    From micronaut-grpc with Apache License 2.0 5 votes vote down vote up
/**
 * The server interceptor.
 * @param configuration The configuration
 * @return The server interceptor
 */
@Requires(beans = GrpcServerTracingInterceptorConfiguration.class)
@Singleton
@Bean
protected @Nonnull ServerInterceptor serverTracingInterceptor(@Nonnull GrpcServerTracingInterceptorConfiguration configuration) {
    return configuration.getBuilder().build();
}
 
Example #13
Source File: ServerConfig.java    From festival with Apache License 2.0 5 votes vote down vote up
@Singleton
@Named
public Vertx vertx() {
    return Vertx.vertx(new VertxOptions()
            .setEventLoopPoolSize(20)
            .setWorkerPoolSize(50));
}
 
Example #14
Source File: DefaultSchedulerModule.java    From openAGV with Apache License 2.0 5 votes vote down vote up
private void configureSchedulerDependencies() {
  bind(ReservationPool.class).in(Singleton.class);

  Multibinder<Scheduler.Module> moduleBinder = Multibinder.newSetBinder(binder(),
                                                                        Scheduler.Module.class);
  moduleBinder.addBinding().to(SingleVehicleBlockModule.class);
  moduleBinder.addBinding().to(SameDirectionBlockModule.class);
}
 
Example #15
Source File: OptimizationStream.java    From micronaut-kafka with Apache License 2.0 5 votes vote down vote up
@Singleton
@Named(STREAM_OPTIMIZATION_ON)
KStream<String, String> optimizationOn(
        @Named(STREAM_OPTIMIZATION_ON) ConfiguredStreamBuilder builder) {
    // set default serdes
    Properties props = builder.getConfiguration();
    props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
    props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
    props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

    KTable<String, String> table = builder
            .table(OPTIMIZATION_ON_INPUT, Materialized.as(OPTIMIZATION_ON_STORE));

    return table.toStream();
}
 
Example #16
Source File: SqsClientFactory.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
@Override
@Bean(preDestroy = "close")
@Singleton
@Requires(beans = SdkAsyncHttpClient.class)
public SqsAsyncClient asyncClient(SqsAsyncClientBuilder builder) {
    return super.asyncClient(builder);
}
 
Example #17
Source File: CoordinatorModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@ForStatementResource
public static BoundedExecutor createStatementResponseExecutor(@ForStatementResource ExecutorService coreExecutor, TaskManagerConfig config)
{
    return new BoundedExecutor(coreExecutor, config.getHttpResponseThreads());
}
 
Example #18
Source File: CoordinatorModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@ForStatementResource
public static ScheduledExecutorService createStatementTimeoutExecutor(TaskManagerConfig config)
{
    return newScheduledThreadPool(config.getHttpTimeoutThreads(), daemonThreadsNamed("statement-timeout-%s"));
}
 
Example #19
Source File: AWSLambdaAsyncClientFactory.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
/**
 * The client returned from a builder.
 * @return client object
 */
@Requires(beans = AWSLambdaConfiguration.class)
@Singleton
AWSLambdaAsync awsLambdaAsyncClient() {
    AWSLambdaAsyncClientBuilder builder = configuration.getBuilder();
    return builder.build();
}
 
Example #20
Source File: ServerConfig.java    From festival with Apache License 2.0 5 votes vote down vote up
@Singleton
@Named("route2")
public RouteAttribute customRoute2() {
    return RouteAttribute.builder()
            .httpMethod(HttpMethod.GET)
            .url("/custom2")
            .auth(true)
            .rolesAllowed(new PermitHolder(LogicType.OR, "role:administrator", "role:hispassword"))
            .contextHandler(routingContext -> {
                routingContext.response().end("test custom2!");
            })
            .build();
}
 
Example #21
Source File: NettyClientFactory.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
/**
 * @param configuration The Netty client configuration
 * @return an instance of {@link SdkAsyncHttpClient}
 */
@Bean(preDestroy = "close")
@Singleton
@Requires(property = ASYNC_SERVICE_IMPL, value = NETTY_SDK_ASYNC_HTTP_SERVICE)
public SdkAsyncHttpClient systemPropertyClient(NettyClientConfiguration configuration) {
    return doCreateClient(configuration);
}
 
Example #22
Source File: ServerConfig.java    From festival with Apache License 2.0 5 votes vote down vote up
@Singleton
@Named("route1")
public RouteAttribute customRoute() {
    return RouteAttribute.builder()
            .httpMethod(HttpMethod.GET)
            .url("/custom")
            .contextHandler(routingContext -> {
                routingContext.response().end("test custom!");
            })
            .build();
}
 
Example #23
Source File: MissingAlexaSkillConfigurationSkillFactory.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @return An Skill using the {@link AlexaSkillBuilder} and the {@link SkillBuilderProvider} bean.
 */
@Singleton
public Skill createSkill() {
    AlexaSkill alexaSkill = alexaSkillBuilder.buildSkill(skillBuilderProvider.getSkillBuilder(), null);
    if (alexaSkill instanceof Skill) {
        return (Skill) alexaSkill;
    }
    return null;
}
 
Example #24
Source File: LocalPersistenceMemoryModule.java    From hivemq-community-edition with Apache License 2.0 5 votes vote down vote up
private void bindLocalPersistence(final @NotNull Class localPersistenceClass,
                                  final @NotNull Class localPersistenceImplClass) {

    final Object instance = injector == null ? null : injector.getInstance(localPersistenceImplClass);
    if (instance != null) {
        bind(localPersistenceImplClass).toInstance(instance);
        bind(localPersistenceClass).toInstance(instance);
    } else {
        bind(localPersistenceClass).to(localPersistenceImplClass).in(Singleton.class);
    }
}
 
Example #25
Source File: ServerMainModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@ForAsyncHttp
public static ExecutorService createAsyncHttpResponseCoreExecutor()
{
    return newCachedThreadPool(daemonThreadsNamed("async-http-response-%s"));
}
 
Example #26
Source File: ServerMainModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@ForAsyncHttp
public static BoundedExecutor createAsyncHttpResponseExecutor(@ForAsyncHttp ExecutorService coreExecutor, TaskManagerConfig config)
{
    return new BoundedExecutor(coreExecutor, config.getHttpResponseThreads());
}
 
Example #27
Source File: GrpcNameResolverFactory.java    From micronaut-grpc with Apache License 2.0 5 votes vote down vote up
/**
 * A GRPC name resolver factory that integrates with Micronaut's discovery client.
 * @param discoveryClient The discovery client
 * @param serviceInstanceLists The service instance list
 * @return The name resolver
 */
@Singleton
@Requires(beans = DiscoveryClient.class)
@Requires(property = ENABLED, value = StringUtils.TRUE, defaultValue = StringUtils.FALSE)
protected NameResolver.Factory nameResolverFactory(
        DiscoveryClient discoveryClient,
        List<ServiceInstanceList> serviceInstanceLists) {
    return new GrpcNameResolverProvider(discoveryClient, serviceInstanceLists);
}
 
Example #28
Source File: DatabaseMetadataModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@ForMetadata
@Singleton
@Provides
DataSource createDataSource(JdbcDatabaseConfig config, @ForMetadata MySqlDataSourceConfig mysqlConfig)
{
    ServiceDescriptor descriptor = serviceDescriptor("mysql")
            .addProperty("jdbc", config.getUrl())
            .build();
    return new MySqlDataSource(new StaticServiceSelector(descriptor), mysqlConfig);
}
 
Example #29
Source File: SesClientFactory.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
@Override
@Bean(preDestroy = "close")
@Singleton
@Requires(beans = SdkAsyncHttpClient.class)
public SesAsyncClient asyncClient(SesAsyncClientBuilder builder) {
    return super.asyncClient(builder);
}
 
Example #30
Source File: ConsumerExecutorServiceConfig.java    From micronaut-kafka with Apache License 2.0 5 votes vote down vote up
/**
 * @return The executor configurations
 */
@Singleton
@Bean
@Named(TaskExecutors.MESSAGE_CONSUMER)
ExecutorConfiguration configuration() {
    return UserExecutorConfiguration.of(ExecutorType.FIXED, 75);
}