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 Project: hivemq-community-edition   Author: hivemq   File: PersistenceMigrationModule.java    License: 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 #2
Source Project: openAGV   Author: tcrct   File: ComponentsInjectionModule.java    License: 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 #3
Source Project: micronaut-kafka   Author: micronaut-projects   File: WordCountStream.java    License: 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 #4
Source Project: presto   Author: prestosql   File: KuduModule.java    License: 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 #5
Source Project: hivemq-community-edition   Author: hivemq   File: LocalPersistenceFileModule.java    License: 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 #6
Source Project: openAGV   Author: tcrct   File: DefaultKernelControlCenterExtensionsModule.java    License: 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 #7
Source Project: micronaut-kafka   Author: micronaut-projects   File: WordCountStream.java    License: 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 Project: micronaut-gcp   Author: micronaut-projects   File: StackdriverSenderFactory.java    License: 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 Project: micronaut-aws   Author: micronaut-projects   File: CredentialsAndRegionFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param environment The {@link Environment}
 * @return An {@link AwsCredentialsProviderChain} that attempts to read the values from the Micronaut environment
 * first, then delegates to {@link DefaultCredentialsProvider}.
 */
@Bean(preDestroy = "close")
@Singleton
public AwsCredentialsProviderChain awsCredentialsProvider(Environment environment) {
    return AwsCredentialsProviderChain.of(
            EnvironmentAwsCredentialsProvider.create(environment),
            DefaultCredentialsProvider.create()
    );
}
 
Example #10
Source Project: micronaut-sql   Author: micronaut-projects   File: MySQLClientFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return client A pool of connections.
 */
@Singleton
@Bean(preDestroy = "close")
public MySQLPool client() {
    if (this.vertx == null) {
        return createClient();
    } else {
        return createClient(vertx);
    }
}
 
Example #11
Source Project: micronaut-grpc   Author: micronaut-projects   File: GrpcServerTracingInterceptorFactory.java    License: 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 #12
Source Project: besu   Author: hyperledger   File: GenesisFileModule.java    License: Apache License 2.0 5 votes vote down vote up
@Singleton
@Provides
ProtocolSchedule provideProtocolSchedule(
    final GenesisConfigOptions configOptions,
    @Named("RevertReasonEnabled") final boolean revertReasonEnabled) {
  throw new RuntimeException("Abstract");
}
 
Example #13
Source Project: v9porn   Author: ForLovelj   File: ApiServiceModule.java    License: MIT License 5 votes vote down vote up
@Singleton
@Provides
HttpLoggingInterceptor providesHttpLoggingInterceptor() {
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
        @Override
        public void log(@NonNull String message) {
            Logger.t("OkHttp").d(message);
        }
    });
    logging.setLevel(HttpLoggingInterceptor.Level.HEADERS);
    return logging;
}
 
Example #14
Source Project: besu   Author: hyperledger   File: DataStoreModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@Named("worldState")
KeyValueStorage provideWorldStateKeyValueStorage(
    @Named("KeyValueStorageName") final String keyValueStorageName,
    final BesuConfiguration commonConfiguration,
    final MetricsSystem metricsSystem) {
  return constructKeyValueStorage(
      keyValueStorageName,
      commonConfiguration,
      metricsSystem,
      KeyValueSegmentIdentifier.WORLD_STATE);
}
 
Example #15
Source Project: micronaut-aws   Author: micronaut-projects   File: AWSLambdaAsyncClientFactory.java    License: 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 #16
Source Project: presto   Author: prestosql   File: H2ResourceGroupsModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@ForEnvironment
public String getEnvironment(ResourceGroupConfigurationManagerContext context)
{
    return context.getEnvironment();
}
 
Example #17
Source Project: presto   Author: prestosql   File: CredentialProviderModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@ForExtraCredentialProvider
public CredentialProvider getCredentialProvider(ConfigFileBasedCredentialProviderConfig fileConfig)
        throws IOException
{
    Map<String, String> properties = loadPropertiesFrom(fileConfig.getCredentialFile());
    CredentialConfig config = new ConfigurationFactory(properties).build(CredentialConfig.class);
    return new StaticCredentialProvider(config.getConnectionUser(), config.getConnectionPassword());
}
 
Example #18
Source Project: presto   Author: prestosql   File: CredentialProviderModule.java    License: 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 #19
Source Project: micronaut-kafka   Author: micronaut-projects   File: OptimizationStream.java    License: 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 #20
Source Project: presto   Author: prestosql   File: CoordinatorModule.java    License: 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 #21
Source Project: presto   Author: prestosql   File: CoordinatorModule.java    License: 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 #22
Source Project: micronaut-aws   Author: micronaut-projects   File: NettyClientFactory.java    License: 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 #23
Source Project: micronaut-aws   Author: micronaut-projects   File: MissingAlexaSkillConfigurationSkillFactory.java    License: 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 Project: hivemq-community-edition   Author: hivemq   File: LocalPersistenceMemoryModule.java    License: 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 Project: presto   Author: prestosql   File: ServerMainModule.java    License: 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 Project: presto   Author: prestosql   File: ServerMainModule.java    License: 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 Project: micronaut-grpc   Author: micronaut-projects   File: GrpcNameResolverFactory.java    License: 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 Project: micronaut-kafka   Author: micronaut-projects   File: ConsumerExecutorServiceConfig.java    License: 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);
}
 
Example #29
Source Project: micronaut-aws   Author: micronaut-projects   File: SesClientFactory.java    License: 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 Project: presto   Author: prestosql   File: DatabaseMetadataModule.java    License: 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);
}