com.google.inject.Provides Java Examples

The following examples show how to use com.google.inject.Provides. 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: BackupModule.java    From presto with Apache License 2.0 6 votes vote down vote up
@Provides
@Singleton
private static Optional<BackupStore> createBackupStore(
        @Nullable BackupStore store,
        LifeCycleManager lifeCycleManager,
        MBeanExporter exporter,
        RaptorConnectorId connectorId,
        BackupConfig config)
{
    if (store == null) {
        return Optional.empty();
    }

    BackupStore proxy = new TimeoutBackupStore(
            store,
            connectorId.toString(),
            config.getTimeout(),
            config.getTimeoutThreads());

    lifeCycleManager.addInstance(proxy);

    BackupStore managed = new ManagedBackupStore(proxy);
    exporter.exportWithGeneratedName(managed, BackupStore.class, connectorId.toString());

    return Optional.of(managed);
}
 
Example #2
Source File: AuthenticationModules.java    From presto with 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 #3
Source File: SchedulerModule.java    From dynein with Apache License 2.0 6 votes vote down vote up
@Provides
@Singleton
public HeartbeatManager provideHeartBeat(EventBus eventBus, Clock clock) {
  HeartbeatManager heartbeatManager =
      new HeartbeatManager(
          new ConcurrentHashMap<>(),
          MoreExecutors.getExitingScheduledExecutorService(
              (ScheduledThreadPoolExecutor)
                  Executors.newScheduledThreadPool(
                      1,
                      new ThreadFactoryBuilder().setNameFormat("heartbeat-manager-%d").build())),
          eventBus,
          clock,
          heartbeatConfiguration);
  eventBus.register(heartbeatManager);
  return heartbeatManager;
}
 
Example #4
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 #5
Source File: HiveModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@ForHiveTransactionHeartbeats
@Singleton
@Provides
public ScheduledExecutorService createHiveTransactionHeartbeatExecutor(CatalogName catalogName, HiveConfig hiveConfig)
{
    return newScheduledThreadPool(
            hiveConfig.getHiveTransactionHeartbeatThreads(),
            daemonThreadsNamed("hive-heartbeat-" + catalogName + "-%s"));
}
 
Example #6
Source File: Module.java    From reactor-guice with Apache License 2.0 5 votes vote down vote up
@Singleton
@Provides
public Gson gson () {
    return new GsonBuilder()
        .serializeNulls()
        .setDateFormat("yyyy-MM-dd HH:mm:ss")
        .setLongSerializationPolicy(LongSerializationPolicy.STRING)
        .create();
}
 
Example #7
Source File: MongoClientModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@Singleton
@Provides
public static MongoSession createMongoSession(TypeManager typeManager, MongoClientConfig config)
{
    requireNonNull(config, "config is null");

    MongoClientOptions.Builder options = MongoClientOptions.builder();

    options.connectionsPerHost(config.getConnectionsPerHost())
            .connectTimeout(config.getConnectionTimeout())
            .socketTimeout(config.getSocketTimeout())
            .socketKeepAlive(config.getSocketKeepAlive())
            .sslEnabled(config.getSslEnabled())
            .maxWaitTime(config.getMaxWaitTime())
            .minConnectionsPerHost(config.getMinConnectionsPerHost())
            .readPreference(config.getReadPreference().getReadPreference())
            .writeConcern(config.getWriteConcern().getWriteConcern());

    if (config.getRequiredReplicaSetName() != null) {
        options.requiredReplicaSetName(config.getRequiredReplicaSetName());
    }

    MongoClient client = new MongoClient(config.getSeeds(), config.getCredentials(), options.build());

    return new MongoSession(
            typeManager,
            client,
            config);
}
 
Example #8
Source File: PreviewModule.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
public ExecutorService previewImageExecutor(PreviewConfig config) {
   return new ThreadPoolBuilder()
      .withBlockingBacklog()
      .withMaxPoolSize(config.getStorageAzureMaxThreads())
      .withKeepAliveMs(config.getStorageAzureKeepAliveMs())
      .withNameFormat("preview-image-writer-%d")
      .withMetrics("preview.azure")
      .build();
}
 
Example #9
Source File: TestingH2JdbcModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@ForBaseJdbc
public ConnectionFactory getConnectionFactory(BaseJdbcConfig config, CredentialProvider credentialProvider)
{
    return new DriverConnectionFactory(new Driver(), config, credentialProvider);
}
 
Example #10
Source File: DriverServicesModule.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Provides
@Named(GroovyDriverModule.NAME_GROOVY_DRIVER_DIRECTORIES)
public Set<URL> groovyDriverUrls(DriverConfig config) throws MalformedURLException {
   Set<URL> urls = new LinkedHashSet<>();
   urls.add(new File(config.evaluateAbsoluteDriverDirectory()).toURI().toURL());
   return urls;
}
 
Example #11
Source File: ApplicationModule.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@Singleton
@Inject
@Provides
SsmParameterCachingClient ssmParameterCachingClient() {
  String path = String.format("/applications/apprepo/%s/", System.getProperty("integtests.stage"));
  return new SsmParameterCachingClient(SsmClient.builder()
        .httpClientBuilder(UrlConnectionHttpClient.builder())
        .build(),
        Duration.ofMinutes(5), path);
}
 
Example #12
Source File: ApplicationModule.java    From realworld-serverless-application with 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 #13
Source File: H2ResourceGroupsModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@ForEnvironment
public String getEnvironment(ResourceGroupConfigurationManagerContext context)
{
    return context.getEnvironment();
}
 
Example #14
Source File: SubsystemModule.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Provides
public Scheduler scheduler(SubsystemConfig config) {
   ScheduledExecutorService executor =
         Executors
            .newScheduledThreadPool(
                  config.getSchedulerThreads(),
                  ThreadPoolBuilder
                     .defaultFactoryBuilder()
                     .setNameFormat("subsystem-scheduler-%d")
                     .build()
            );
   return new ExecutorScheduler(executor);
}
 
Example #15
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 #16
Source File: BridgeConfigModule.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Provides @Named("tcpChannelOptions")
public Map<ChannelOption<?>, Object> provideTcpChannelOptions(BridgeServerConfig serverConfig) {
   return ImmutableMap.of(
      ChannelOption.TCP_NODELAY, true,
      ChannelOption.AUTO_CLOSE, true,
      ChannelOption.SO_KEEPALIVE, serverConfig.isSoKeepAlive()
   );
}
 
Example #17
Source File: PreviewModule.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Provides @Singleton
public PreviewStorage provideSnapshotStorage(PreviewConfig config) {
   switch (config.getStorageType()) {
   case PreviewConfig.PREVIEWS_STORAGE_TYPE_FS:
      return new PreviewStorageFile(config.getStorageFsBasePath());
   case PreviewConfig.PREVIEWS_STORAGE_TYPE_AZURE:
       return new PreviewStorageAzure(config.getStorageAzureAccounts(),config.getStorageAzureContainer(),previewImageExecutor(config));
   case PreviewConfig.PREVIEWS_STORAGE_TYPE_NULL:
      return new PreviewStorageNull();
   default:
      throw new RuntimeException("unknown video storage type: " + config.getStorageType());
   }
}
 
Example #18
Source File: ApplicationModule.java    From realworld-serverless-application with Apache License 2.0 5 votes vote down vote up
@Singleton
@Inject
@Provides
SsmParameterCachingClient ssmParameterCachingClient() {
  String path = String.format("/applications/apprepo/%s/", System.getProperty("integtests.stage"));
  return new SsmParameterCachingClient(SsmClient.builder()
      .httpClientBuilder(UrlConnectionHttpClient.builder())
      .build(),
      Duration.ofMinutes(5), path);
}
 
Example #19
Source File: RaptorModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@ForMetadata
@Singleton
@Provides
public IDBI createDBI(@ForMetadata ConnectionFactory connectionFactory, TypeManager typeManager)
{
    DBI dbi = new DBI(connectionFactory);
    dbi.registerMapper(new TableColumn.Mapper(typeManager));
    dbi.registerMapper(new Distribution.Mapper(typeManager));
    createTablesWithRetry(dbi);
    return dbi;
}
 
Example #20
Source File: VoiceModule.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Provides
@Named(VoiceConfig.NAME_TIMEOUT_TIMER)
@Singleton
public HashedWheelTimer timeoutTimer() {
   return new HashedWheelTimer(new ThreadFactoryBuilder()
      .setDaemon(true)
      .setNameFormat("voice-execute-timeout-%d")
      .setUncaughtExceptionHandler(new LoggingUncaughtExceptionHandler(LoggerFactory.getLogger(CommandExecutor.class)))
      .build());
}
 
Example #21
Source File: BigQueryConnectorModule.java    From presto with 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 #22
Source File: ServerSecurityModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@Provides
public List<Authenticator> getAuthenticatorList(SecurityConfig config, Map<String, Authenticator> authenticators)
{
    return authenticationTypes(config).stream()
            .map(type -> {
                Authenticator authenticator = authenticators.get(type);
                if (authenticator == null) {
                    throw new RuntimeException("Unknown authenticator type: " + type);
                }
                return authenticator;
            })
            .collect(toImmutableList());
}
 
Example #23
Source File: TemplateModule.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Provides @Singleton TemplateService templateService(){
	HandlebarsTemplateService hbTemplateService = new HandlebarsTemplateService(templatePath, cacheSize);
	if(helpers!=null){
		hbTemplateService.registerHelpers(helpers);
	}
	return hbTemplateService;
}
 
Example #24
Source File: SandboxNotificationServicesModule.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Provides @Named("notifications.executor")
public ExecutorService getNotificationsExecutor(NotificationServiceConfig config) {
     return new ThreadPoolBuilder()
        .withMaxPoolSize(config.getMaxThreads())
        .withKeepAliveMs(config.getThreadKeepAliveMs())
        .withNameFormat("notification-dispatcher-%d")
        .withBlockingBacklog()
        .withMetrics("service.notifications")
        .build();
}
 
Example #25
Source File: GroovyDriverTestCase.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
public GroovyScriptEngine scriptEngine(Set<CompilationCustomizer> customizers) {
   GroovyScriptEngine engine = scriptEngine();
   for(CompilationCustomizer customizer: customizers) {
      engine.getConfig().addCompilationCustomizers(customizer);
   }
   engine.getConfig().setScriptExtensions(ImmutableSet.of("driver", "capability", "groovy"));
   return engine;
}
 
Example #26
Source File: WarningCollectorModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
public WarningCollectorFactory createWarningCollectorFactory(WarningCollectorConfig config)
{
    requireNonNull(config, "config is null");
    return () -> new DefaultWarningCollector(config);
}
 
Example #27
Source File: SchedulerModule.java    From dynein with Apache License 2.0 4 votes vote down vote up
@Provides
public DynamoDbAsyncClient providesDdbAsyncClient() {
  return DynamoDbAsyncClient.builder()
      .endpointOverride(dynamoDBConfiguration.getEndpoint())
      .build();
}
 
Example #28
Source File: BillingTestCase.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
public PlaceDAO providePlaceDao() {
   return placeDao;
}
 
Example #29
Source File: TestPlatformSubsystemContext.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Provides
Listener<ScheduledEvent> mockEventListener() {
   return EasyMock.createMock(Listener.class);
}
 
Example #30
Source File: SkyboxPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Provides
SkyboxPluginConfig provideConfig(ConfigManager configManager)
{
	return configManager.getConfig(SkyboxPluginConfig.class);
}