use of com.google.inject.Singleton in project ninja by ninjaframework.
the class LifecycleSupportTest method providedSingletonStartableShouldBeStarted.
@Test
public void providedSingletonStartableShouldBeStarted() {
Injector injector = createInjector(new AbstractModule() {
@Override
protected void configure() {
}
@Provides
@Singleton
public MockSingletonService provide() {
return new MockSingletonService();
}
});
start(injector);
assertThat(MockSingletonService.started, equalTo(1));
}
use of com.google.inject.Singleton in project keywhiz by square.
the class ServiceDataSourceModule method readonlyDataSource.
@Provides
@Singleton
@Readonly
ManagedDataSource readonlyDataSource(Environment environment, KeywhizConfig config) {
DataSourceFactory dataSourceFactory = config.getReadonlyDataSourceFactory();
ManagedDataSource dataSource = dataSourceFactory.build(environment.metrics(), "db-readonly");
environment.lifecycle().manage(dataSource);
environment.healthChecks().register("db-readonly-health", new JooqHealthCheck(dataSource, RETURN_UNHEALTHY));
return dataSource;
}
use of com.google.inject.Singleton in project keywhiz by square.
the class ServiceDataSourceModule method dataSource.
@Provides
@Singleton
ManagedDataSource dataSource(Environment environment, KeywhizConfig config) {
DataSourceFactory dataSourceFactory = config.getDataSourceFactory();
ManagedDataSource dataSource = dataSourceFactory.build(environment.metrics(), "db-writable");
environment.lifecycle().manage(dataSource);
environment.healthChecks().register("db-read-write-health", new JooqHealthCheck(dataSource, LOG_ONLY));
return dataSource;
}
use of com.google.inject.Singleton in project killbill by killbill.
the class TestUtilModuleWithEmbeddedDB method provideRealms.
@Provides
@Singleton
protected Set<Realm> provideRealms(final EmbeddedDB embeddedDB, final SecurityConfig securityConfig) throws IOException {
final Ini ini = new Ini();
ini.load("[users]\n" + "tester = tester, creditor\n" + "[roles]\n" + "creditor = invoice:credit, customx:customy\n");
final Realm iniRealm = new IniRealm(ini);
final Realm killBillJdbcRealm = new KillBillJdbcRealm(embeddedDB.getDataSource(), securityConfig);
return ImmutableSet.<Realm>of(iniRealm, killBillJdbcRealm);
}
use of com.google.inject.Singleton in project Singularity by HubSpot.
the class SingularityMainModule method provideS3Services.
@Provides
@Singleton
public SingularityS3Services provideS3Services(Optional<S3Configuration> config) {
if (!config.isPresent()) {
return new SingularityS3Services();
}
final ImmutableList.Builder<SingularityS3Service> s3ServiceBuilder = ImmutableList.builder();
for (Map.Entry<String, S3GroupConfiguration> entry : config.get().getGroupOverrides().entrySet()) {
s3ServiceBuilder.add(new SingularityS3Service(entry.getKey(), entry.getValue().getS3Bucket(), new AmazonS3Client(new BasicAWSCredentials(entry.getValue().getS3AccessKey(), entry.getValue().getS3SecretKey()))));
}
for (Map.Entry<String, S3GroupConfiguration> entry : config.get().getGroupS3SearchConfigs().entrySet()) {
s3ServiceBuilder.add(new SingularityS3Service(entry.getKey(), entry.getValue().getS3Bucket(), new AmazonS3Client(new BasicAWSCredentials(entry.getValue().getS3AccessKey(), entry.getValue().getS3SecretKey()))));
}
SingularityS3Service defaultService = new SingularityS3Service(SingularityS3FormatHelper.DEFAULT_GROUP_NAME, config.get().getS3Bucket(), new AmazonS3Client(new BasicAWSCredentials(config.get().getS3AccessKey(), config.get().getS3SecretKey())));
return new SingularityS3Services(s3ServiceBuilder.build(), defaultService);
}
Aggregations