com.google.inject.Singleton Java Examples

The following examples show how to use com.google.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: arcusplatform   Author: arcus-smart-home   File: BridgeEventLoopModule.java    License: Apache License 2.0 6 votes vote down vote up
@Singleton @Provides @Named("bridgeEventLoopProvider")
public BridgeServerEventLoopProvider provideEventLoopProvider(BridgeServerConfig serverConfig) {
   switch (serverConfig.getEventLoopProvider()) {
   case BridgeServerConfig.EVENT_LOOP_PROVIDER_DEFAULT:
   case BridgeServerConfig.EVENT_LOOP_PROVIDER_NIO:
      logger.info("using nio event loop provider");
      return new BridgeServerNioEventLoopProvider();

   case BridgeServerConfig.EVENT_LOOP_PROVIDER_EPOLL:
      logger.info("using epoll event loop provider");
      return new BridgeServerEpollEventLoopProvider();

   default:
      throw new RuntimeException("unknown event loop provider: " + serverConfig.getEventLoopProvider());

   }
}
 
Example #2
Source Project: presto   Author: prestosql   File: AccessControlModule.java    License: Apache License 2.0 6 votes vote down vote up
@Provides
@Singleton
public AccessControl createAccessControl(AccessControlManager accessControlManager)
{
    Logger logger = Logger.get(AccessControl.class);

    AccessControl loggingInvocationsAccessControl = newProxy(
            AccessControl.class,
            new LoggingInvocationHandler(
                    accessControlManager,
                    new LoggingInvocationHandler.ReflectiveParameterNamesProvider(),
                    logger::debug));

    return ForwardingAccessControl.of(() -> {
        if (logger.isDebugEnabled()) {
            return loggingInvocationsAccessControl;
        }
        return accessControlManager;
    });
}
 
Example #3
Source Project: presto   Author: prestosql   File: AuthenticationModules.java    License: Apache License 2.0 6 votes vote down vote up
public static Module kerberosHdfsAuthenticationModule()
{
    return new Module()
    {
        @Override
        public void configure(Binder binder)
        {
            binder.bind(HdfsAuthentication.class)
                    .to(DirectHdfsAuthentication.class)
                    .in(SINGLETON);
            configBinder(binder).bindConfig(HdfsKerberosConfig.class);
        }

        @Inject
        @Provides
        @Singleton
        @ForHdfs
        HadoopAuthentication createHadoopAuthentication(HdfsKerberosConfig config, HdfsConfigurationInitializer updater)
        {
            String principal = config.getHdfsPrestoPrincipal();
            String keytabLocation = config.getHdfsPrestoKeytab();
            return createCachingKerberosHadoopAuthentication(principal, keytabLocation, updater);
        }
    };
}
 
Example #4
Source Project: presto   Author: prestosql   File: AuthenticationModules.java    License: Apache License 2.0 6 votes vote down vote up
public static Module kerberosImpersonatingHdfsAuthenticationModule()
{
    return new Module()
    {
        @Override
        public void configure(Binder binder)
        {
            binder.bind(HdfsAuthentication.class)
                    .to(ImpersonatingHdfsAuthentication.class)
                    .in(SINGLETON);
            configBinder(binder).bindConfig(HdfsKerberosConfig.class);
        }

        @Inject
        @Provides
        @Singleton
        @ForHdfs
        HadoopAuthentication createHadoopAuthentication(HdfsKerberosConfig config, HdfsConfigurationInitializer updater)
        {
            String principal = config.getHdfsPrestoPrincipal();
            String keytabLocation = config.getHdfsPrestoKeytab();
            return createCachingKerberosHadoopAuthentication(principal, keytabLocation, updater);
        }
    };
}
 
Example #5
Source Project: arcusplatform   Author: arcus-smart-home   File: IrisHalImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
      protected void configure() {
         String disable = System.getenv("ZWAVE_DISABLE");
         if (disable != null) {
             bind(ZWaveLocalProcessing.class).to(ZWaveLocalProcessingNoop.class).asEagerSingleton();
            return;
         }

         String port = System.getenv("ZWAVE_PORT");
         if (port == null) {
            bind(String.class).annotatedWith(Names.named("iris.zwave.port")).toInstance("/dev/ttyO1");
         } else {
            bind(String.class).annotatedWith(Names.named("iris.zwave.port")).toInstance(port);
         }

//         bind(ZWaveDriverFactory.class).in(Singleton.class);
         bind(ZWaveController.class).in(Singleton.class);
         bind(ZWaveLocalProcessing.class).to(ZWaveLocalProcessingDefault.class).asEagerSingleton();
      }
 
Example #6
Source Project: arcusplatform   Author: arcus-smart-home   File: GoogleBridgeModule.java    License: Apache License 2.0 6 votes vote down vote up
@Provides
@Named(GoogleHomeHandler.BEARER_AUTH_NAME)
@Singleton
public RequestAuthorizer bearerAuth(
   OAuthDAO oauthDao,
   BridgeMetrics metrics,
   GoogleBridgeConfig config
) {
   return new BearerAuth(oauthDao, metrics, config.getOauthAppId(), (req) -> {
      Request request = Transformers.GSON.fromJson(req.content().toString(StandardCharsets.UTF_8), Request.class);
      Response res = new Response();
      res.setRequestId(request.getRequestId());
      res.setPayload(ImmutableMap.of(Constants.Response.ERROR_CODE, Constants.Error.AUTH_EXPIRED));
      DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
      response.content().writeBytes(Transformers.GSON.toJson(res).getBytes(StandardCharsets.UTF_8));
      return response;
   });
}
 
Example #7
Source Project: hadoop-ozone   Author: apache   File: JooqPersistenceModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
Configuration getConfiguration(DefaultDataSourceProvider provider) {
  DataSource dataSource = provider.get();

  return new DefaultConfiguration()
      .set(dataSource)
      .set(new SpringConnectionProvider(dataSource))
      .set(SQLDialect.valueOf(configurationProvider.get().getSqlDialect()));
}
 
Example #8
Source Project: hadoop-ozone   Author: apache   File: JooqPersistenceModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
DataSourceTransactionManager provideDataSourceTransactionManager(
    DataSource dataSource) {
  return new DataSourceTransactionManager(
      new TransactionAwareDataSourceProxy(dataSource));
}
 
Example #9
Source Project: hadoop-ozone   Author: apache   File: ReconControllerModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
  bind(OzoneConfiguration.class).toProvider(ConfigurationProvider.class);
  bind(ReconHttpServer.class).in(Singleton.class);
  bind(DBStore.class)
      .toProvider(ReconContainerDBProvider.class).in(Singleton.class);
  bind(ReconOMMetadataManager.class)
      .to(ReconOmMetadataManagerImpl.class);
  bind(OMMetadataManager.class).to(ReconOmMetadataManagerImpl.class);

  bind(ContainerSchemaManager.class).in(Singleton.class);
  bind(ContainerDBServiceProvider.class)
      .to(ContainerDBServiceProviderImpl.class).in(Singleton.class);
  bind(OzoneManagerServiceProvider.class)
      .to(OzoneManagerServiceProviderImpl.class).in(Singleton.class);
  bind(ReconUtils.class).in(Singleton.class);
  // Persistence - inject configuration provider
  install(new JooqPersistenceModule(
      getProvider(DataSourceConfiguration.class)));

  install(new ReconOmTaskBindingModule());
  install(new ReconDaoBindingModule());

  bind(ReconTaskController.class)
      .to(ReconTaskControllerImpl.class).in(Singleton.class);
  bind(StorageContainerServiceProvider.class)
      .to(StorageContainerServiceProviderImpl.class).in(Singleton.class);
  bind(OzoneStorageContainerManager.class)
      .to(ReconStorageContainerManagerFacade.class).in(Singleton.class);
}
 
Example #10
Source Project: hadoop-ozone   Author: apache   File: TestReconContainerDBProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws IOException {
  tempFolder.create();
  injector = Guice.createInjector(new AbstractModule() {
    @Override
    protected void configure() {
      File dbDir = tempFolder.getRoot();
      OzoneConfiguration configuration = new OzoneConfiguration();
      configuration.set(OZONE_RECON_DB_DIR, dbDir.getAbsolutePath());
      bind(OzoneConfiguration.class).toInstance(configuration);
      bind(DBStore.class).toProvider(ReconContainerDBProvider.class).in(
          Singleton.class);
    }
  });
}
 
Example #11
Source Project: arcusplatform   Author: arcus-smart-home   File: VoiceModule.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Executor for sending report state after SYNC responses.  Report State is delayed to ensure the SYNC
 * reaches google.
 */
@Provides
@Named(HomeGraphAPI.EXECUTOR_NAME)
@Singleton
public HashedWheelTimer googleReportStateExecutor(ProactiveReportingConfig config) {
   return new HashedWheelTimer(new ThreadFactoryBuilder()
         .setDaemon(true)
         .setNameFormat("voice-service-google-report-state-%d")
         .setUncaughtExceptionHandler(new LoggingUncaughtExceptionHandler(LoggerFactory.getLogger(CommandExecutor.class)))
         .build());
}
 
Example #12
Source Project: presto   Author: prestosql   File: DruidJdbcClientModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@ForBaseJdbc
public static ConnectionFactory createConnectionFactory(BaseJdbcConfig config, CredentialProvider credentialProvider)
{
    Properties connectionProperties = new Properties();
    return new DriverConnectionFactory(
            new Driver(),
            config.getConnectionUrl(),
            connectionProperties,
            credentialProvider);
}
 
Example #13
Source Project: presto   Author: prestosql   File: SqlServerClientModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@ForBaseJdbc
public ConnectionFactory getConnectionFactory(BaseJdbcConfig config, CredentialProvider credentialProvider)
{
    return new DriverConnectionFactory(new SQLServerDriver(), config, credentialProvider);
}
 
Example #14
Source Project: arcusplatform   Author: arcus-smart-home   File: ClientServerModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
public RESTHandlerConfig provideRestHandlerConfig() {
 RESTHandlerConfig restHandlerConfig = new RESTHandlerConfig();
 restHandlerConfig.setSendChunked(false);
 return restHandlerConfig;
}
 
Example #15
Source Project: arcusplatform   Author: arcus-smart-home   File: VoiceModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Named(VoiceConfig.NAME_EXECUTOR)
@Singleton
public ExecutorService voiceServiceExecutor(VoiceConfig config) {
   return new ThreadPoolBuilder()
      .withBlockingBacklog()
      .withMaxPoolSize(config.getServiceMaxThreads())
      .withKeepAliveMs(config.getServiceThreadKeepAliveMs())
      .withNameFormat("voice-service-%d")
      .withMetrics("voice.service")
      .build();
}
 
Example #16
Source Project: presto   Author: prestosql   File: PhoenixClientModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
public ConnectionFactory getConnectionFactory(PhoenixConfig config)
        throws SQLException
{
    return new StatisticsAwareConnectionFactory(
            new DriverConnectionFactory(
                    DriverManager.getDriver(config.getConnectionUrl()),
                    config.getConnectionUrl(),
                    getConnectionProperties(config),
                    new EmptyCredentialProvider()));
}
 
Example #17
Source Project: arcusplatform   Author: arcus-smart-home   File: IrisHalImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
   String disable = System.getenv("REFLEX_DISABLE");
   if (disable != null) {
      return;
   }

   bind(ReflexLocalProcessing.class).in(Singleton.class);
   bind(ReflexController.class).in(Singleton.class);
}
 
Example #18
Source Project: presto   Author: prestosql   File: BigQueryConnectorModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
public BigQueryClient provideBigQueryClient(BigQueryConfig config, HeaderProvider headerProvider, BigQueryCredentialsSupplier bigQueryCredentialsSupplier)
{
    String billingProjectId = calculateBillingProjectId(config.getParentProjectId(), bigQueryCredentialsSupplier.getCredentials());
    BigQueryOptions.Builder options = BigQueryOptions.newBuilder()
            .setHeaderProvider(headerProvider)
            .setProjectId(billingProjectId);
    // set credentials of provided
    bigQueryCredentialsSupplier.getCredentials().ifPresent(options::setCredentials);
    return new BigQueryClient(options.build().getService(), config);
}
 
Example #19
Source Project: arcusplatform   Author: arcus-smart-home   File: TestCompositeDriverRegistry.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
public CompositeDriverRegistry provideDriverRegistry(Driver1 driver1, Driver1V1 driver1v1, Driver1V2 driver1v2, Driver2 driver2) {
   Map<DriverId, DeviceDriver> map0 = new HashMap<>();
   map0.put(driver1.getDriverId(), driver1);
   Map<DriverId, DeviceDriver> map1 = new HashMap<>();
   map1.put(driver1v1.getDriverId(), driver1v1);
   Map<DriverId, DeviceDriver> map2 = new HashMap<>();
   map2.put(driver1v2.getDriverId(), driver1v2);
   Map<DriverId, DeviceDriver> map3 = new HashMap<>();
   map3.put(driver2.getDriverId(), driver2);

   return new CompositeDriverRegistry(new MapDriverRegistry(map0), new MapDriverRegistry(map1), new MapDriverRegistry(map2), new MapDriverRegistry(map3));
}
 
Example #20
Source Project: presto   Author: prestosql   File: ThriftMetastoreAuthenticationModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@ForHiveMetastore
public HadoopAuthentication createHadoopAuthentication(MetastoreKerberosConfig config, HdfsConfigurationInitializer updater)
{
    String principal = config.getHiveMetastoreClientPrincipal();
    String keytabLocation = config.getHiveMetastoreClientKeytab();
    return createCachingKerberosHadoopAuthentication(principal, keytabLocation, updater);
}
 
Example #21
Source Project: aquality-selenium-java   Author: aquality-automation   File: BrowserModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    super.configure();
    bind(ITimeoutConfiguration.class).to(getTimeoutConfigurationImplementation()).in(Singleton.class);
    bind(IBrowserProfile.class).to(getBrowserProfileImplementation()).in(Singleton.class);
    bind(IElementFactory.class).to(getElementFactoryImplementation());
    bind(IConfiguration.class).to(getConfigurationImplementation());
}
 
Example #22
Source Project: arcusplatform   Author: arcus-smart-home   File: TestSimplePartitioner.java    License: Apache License 2.0 5 votes vote down vote up
@Provides @Singleton
public Optional<Set<PartitionListener>> getPartitionListeners() {
   partitionRef = Capture.newInstance();
   PartitionListener partitionListener = EasyMock.createMock(PartitionListener.class);
   partitionListener.onPartitionsChanged(EasyMock.capture(partitionRef));
   EasyMock.expectLastCall().once();
   EasyMock.replay(partitionListener);
   
   return Optional.of(ImmutableSet.of(partitionListener));
}
 
Example #23
Source Project: realworld-serverless-application   Author: awslabs   File: ApplicationModule.java    License: Apache License 2.0 5 votes vote down vote up
@Singleton
@Inject
@Provides
CognitoUserManager cognitoUserManager(final SsmParameterCachingClient ssm) {
  String clientId = ssm.getAsString("cognito/userpoolclient/IntegTest/Id");
  String userPoolId = ssm.getAsString("cognito/userpool/ApplicationsApi/Id");
  return new CognitoUserManager(CognitoIdentityProviderClient.builder()
      .httpClientBuilder(UrlConnectionHttpClient.builder())
      .build(), clientId, userPoolId);
}
 
Example #24
Source Project: realworld-serverless-application   Author: awslabs   File: ApplicationModule.java    License: Apache License 2.0 5 votes vote down vote up
@Singleton
@Inject
@Provides
AthenaClient athenaClient(){
  return AthenaClient.builder()
      .httpClientBuilder(UrlConnectionHttpClient.builder())
      .build();
}
 
Example #25
Source Project: realworld-serverless-application   Author: awslabs   File: ApplicationModule.java    License: Apache License 2.0 5 votes vote down vote up
@Singleton
@Inject
@Provides
AWSServerlessApplicationRepository AWSServerlessApplicationRepository(final SsmParameterCachingClient ssm, final CognitoUserManager cognitoUserManager) {
  String endpoint = ssm.getAsString("apigateway/ApplicationsApi/Endpoint");
  return new AWSServerlessApplicationRepositoryRecordingClient(AWSServerlessApplicationRepository.builder()
        .endpoint(endpoint)
        .signer(new CognitoAuthorizerImpl(cognitoUserManager))
        .build());
}
 
Example #26
Source Project: arcusplatform   Author: arcus-smart-home   File: InMemoryMessageModuleWithoutResourceBundle.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
   bind(InMemoryPlatformMessageBus.class).in(Singleton.class);
   bind(InMemoryProtocolMessageBus.class).in(Singleton.class);
   bind(PlatformMessageBus.class).to(InMemoryPlatformMessageBus.class);
   bind(ProtocolMessageBus.class).to(InMemoryProtocolMessageBus.class);
}
 
Example #27
Source Project: realworld-serverless-application   Author: awslabs   File: ApplicationModule.java    License: Apache License 2.0 5 votes vote down vote up
@Singleton
@Inject
@Provides
CognitoUserManager cognitoUserManager(final SsmParameterCachingClient ssm) {
  String clientId = ssm.getAsString(String.format(
          "cognito/userpoolclient/IntegTest/realworld-serverless-application-backend-%s-env/Id",
          System.getProperty("integtests.stage")));
  String userPoolId = ssm.getAsString("cognito/userpool/ApplicationsApi/Id");
  return new CognitoUserManager(CognitoIdentityProviderClient.builder()
        .httpClientBuilder(UrlConnectionHttpClient.builder())
        .build(), clientId, userPoolId);
}
 
Example #28
Source Project: openAGV   Author: tcrct   File: DefaultPersistenceInjectionModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
  bind(ModelManager.class).to(OpenTCSModelManager.class).in(Singleton.class);

  bind(ModelFileReader.class).to(UnifiedModelReader.class);
  bind(ModelFilePersistor.class).to(UnifiedModelPersistor.class);
}
 
Example #29
Source Project: openAGV   Author: tcrct   File: KernelInjectionModule.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the recharge position supplier implementation to be used.
 *
 * @param clazz The implementation.
 * @deprecated Will be removed along with the deprecated supplier interface.
 */
@Deprecated
@ScheduledApiChange(when = "5.0")
protected void bindRechargePositionSupplier(
    Class<? extends org.opentcs.components.kernel.RechargePositionSupplier> clazz) {
  bind(org.opentcs.components.kernel.RechargePositionSupplier.class).to(clazz).in(Singleton.class);
}
 
Example #30
Source Project: arcusplatform   Author: arcus-smart-home   File: TestGroovyDriverRegistry.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
public GroovyScriptEngine provideGroovyScriptEngine(TestDriverConfig driverConfig, CapabilityRegistry registry) throws MalformedURLException {
   File driverDir = new File(driverConfig.getDriverDirectory());
   GroovyScriptEngine engine = new GroovyScriptEngine(new URL[] {
         driverDir.toURI().toURL(),
         new File("src/main/resources").toURI().toURL()
   } );
   engine.getConfig().addCompilationCustomizers(new DriverCompilationCustomizer(registry));
   return engine;
}