Search in sources :

Example 71 with Singleton

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));
}
Also used : Injector(com.google.inject.Injector) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 72 with Singleton

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;
}
Also used : JooqHealthCheck(keywhiz.JooqHealthCheck) DataSourceFactory(io.dropwizard.db.DataSourceFactory) ManagedDataSource(io.dropwizard.db.ManagedDataSource) Readonly(keywhiz.service.config.Readonly) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 73 with Singleton

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;
}
Also used : JooqHealthCheck(keywhiz.JooqHealthCheck) DataSourceFactory(io.dropwizard.db.DataSourceFactory) ManagedDataSource(io.dropwizard.db.ManagedDataSource) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 74 with Singleton

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);
}
Also used : Ini(org.apache.shiro.config.Ini) KillBillJdbcRealm(org.killbill.billing.util.security.shiro.realm.KillBillJdbcRealm) IniRealm(org.apache.shiro.realm.text.IniRealm) IniRealm(org.apache.shiro.realm.text.IniRealm) KillBillJdbcRealm(org.killbill.billing.util.security.shiro.realm.KillBillJdbcRealm) Realm(org.apache.shiro.realm.Realm) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 75 with Singleton

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);
}
Also used : S3GroupConfiguration(com.hubspot.singularity.config.S3GroupConfiguration) SingularityS3Service(com.hubspot.singularity.helpers.SingularityS3Service) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) ImmutableList(com.google.common.collect.ImmutableList) SingularityS3Services(com.hubspot.singularity.helpers.SingularityS3Services) Map(java.util.Map) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Aggregations

Singleton (com.google.inject.Singleton)81 Provides (com.google.inject.Provides)78 AbstractModule (com.google.inject.AbstractModule)8 Injector (com.google.inject.Injector)8 Named (com.google.inject.name.Named)7 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)7 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)7 Model (org.ovirt.engine.ui.uicommonweb.models.Model)7 File (java.io.File)5 IOException (java.io.IOException)5 SearchableDetailTabModelProvider (org.ovirt.engine.ui.common.uicommon.model.SearchableDetailTabModelProvider)5 PermissionListModel (org.ovirt.engine.ui.uicommonweb.models.configure.PermissionListModel)5 DataSourceFactory (io.dropwizard.db.DataSourceFactory)4 ManagedDataSource (io.dropwizard.db.ManagedDataSource)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 InetSocketAddress (java.net.InetSocketAddress)3 SocketAddress (java.net.SocketAddress)3 Properties (java.util.Properties)3 Test (org.junit.Test)3 ConfigModule (co.cask.cdap.common.guice.ConfigModule)2