Search in sources :

Example 46 with Singleton

use of com.google.inject.Singleton in project ratpack by ratpack.

the class ThymeleafModule method provideCacheManager.

@Provides
@Singleton
StandardCacheManager provideCacheManager(Config config) {
    int cacheSize = getCacheSizeSetting(config);
    StandardCacheManager cacheManager = new StandardCacheManager();
    cacheManager.setTemplateCacheMaxSize(cacheSize);
    return cacheManager;
}
Also used : StandardCacheManager(org.thymeleaf.cache.StandardCacheManager) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 47 with Singleton

use of com.google.inject.Singleton in project ratpack by ratpack.

the class HandlebarsModule method provideHandlebars.

@SuppressWarnings("UnusedDeclaration")
@Provides
@Singleton
Handlebars provideHandlebars(Config config, Injector injector, TemplateLoader templateLoader, TemplateCache templateCache) {
    final Handlebars handlebars = new Handlebars().with(templateLoader).with(templateCache).startDelimiter(config.getStartDelimiter()).endDelimiter(config.getEndDelimiter());
    GuiceUtil.eachOfType(injector, NAMED_HELPER_TYPE, helper -> handlebars.registerHelper(helper.getName(), helper));
    return handlebars;
}
Also used : Handlebars(com.github.jknack.handlebars.Handlebars) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 48 with Singleton

use of com.google.inject.Singleton in project gerrit by GerritCodeReview.

the class SshAddressesModule method getListenAddresses.

@Provides
@Singleton
@SshListenAddresses
public List<SocketAddress> getListenAddresses(@GerritServerConfig Config cfg) {
    List<SocketAddress> listen = Lists.newArrayListWithExpectedSize(2);
    String[] want = cfg.getStringList("sshd", null, "listenaddress");
    if (want == null || want.length == 0) {
        listen.add(new InetSocketAddress(DEFAULT_PORT));
        return listen;
    }
    if (want.length == 1 && isOff(want[0])) {
        return listen;
    }
    for (final String desc : want) {
        try {
            listen.add(SocketUtil.resolve(desc, DEFAULT_PORT));
        } catch (IllegalArgumentException e) {
            log.error("Bad sshd.listenaddress: " + desc + ": " + e.getMessage());
        }
    }
    return listen;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 49 with Singleton

use of com.google.inject.Singleton in project gerrit by GerritCodeReview.

the class SshAddressesModule method getAdvertisedAddresses.

@Provides
@Singleton
@SshAdvertisedAddresses
List<String> getAdvertisedAddresses(@GerritServerConfig Config cfg, @SshListenAddresses List<SocketAddress> listen) {
    String[] want = cfg.getStringList("sshd", null, "advertisedaddress");
    if (want.length > 0) {
        return Arrays.asList(want);
    }
    List<InetSocketAddress> pub = new ArrayList<>();
    List<InetSocketAddress> local = new ArrayList<>();
    for (SocketAddress addr : listen) {
        if (addr instanceof InetSocketAddress) {
            InetSocketAddress inetAddr = (InetSocketAddress) addr;
            if (inetAddr.getAddress().isLoopbackAddress()) {
                local.add(inetAddr);
            } else {
                pub.add(inetAddr);
            }
        }
    }
    if (pub.isEmpty()) {
        pub = local;
    }
    List<String> adv = Lists.newArrayListWithCapacity(pub.size());
    for (InetSocketAddress addr : pub) {
        adv.add(SocketUtil.format(addr, IANA_SSH_PORT));
    }
    return adv;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 50 with Singleton

use of com.google.inject.Singleton in project gerrit by GerritCodeReview.

the class InMemoryModule method configure.

@Override
protected void configure() {
    // Do NOT bind @RemotePeer, as it is bound in a child injector of
    // ChangeMergeQueue (bound via GerritGlobalModule below), so there cannot be
    // a binding in the parent injector. If you need @RemotePeer, you must bind
    // it in a child injector of the one containing InMemoryModule. But unless
    // you really need to test something request-scoped, you likely don't
    // actually need it.
    // For simplicity, don't create child injectors, just use this one to get a
    // few required modules.
    Injector cfgInjector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(cfg);
        }
    });
    bind(MetricMaker.class).to(DisabledMetricMaker.class);
    install(cfgInjector.getInstance(GerritGlobalModule.class));
    install(new DefaultPermissionBackendModule());
    install(new SearchingChangeCacheImpl.Module());
    factory(GarbageCollection.Factory.class);
    bindScope(RequestScoped.class, PerThreadRequestScope.REQUEST);
    // TODO(dborowitz): Use jimfs.
    bind(Path.class).annotatedWith(SitePath.class).toInstance(Paths.get("."));
    bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(cfg);
    bind(GerritOptions.class).toInstance(new GerritOptions(cfg, false, false, false));
    bind(PersonIdent.class).annotatedWith(GerritPersonIdent.class).toProvider(GerritPersonIdentProvider.class);
    bind(String.class).annotatedWith(AnonymousCowardName.class).toProvider(AnonymousCowardNameProvider.class);
    bind(String.class).annotatedWith(GerritServerId.class).toInstance("gerrit");
    bind(AllProjectsName.class).toProvider(AllProjectsNameProvider.class);
    bind(AllUsersName.class).toProvider(AllUsersNameProvider.class);
    bind(GitRepositoryManager.class).to(InMemoryRepositoryManager.class);
    bind(InMemoryRepositoryManager.class).in(SINGLETON);
    bind(TrackingFooters.class).toProvider(TrackingFootersProvider.class).in(SINGLETON);
    bind(NotesMigration.class).toInstance(notesMigration);
    bind(ListeningExecutorService.class).annotatedWith(ChangeUpdateExecutor.class).toInstance(MoreExecutors.newDirectExecutorService());
    bind(DataSourceType.class).to(InMemoryH2Type.class);
    bind(ChangeBundleReader.class).to(GwtormChangeBundleReader.class);
    bind(SecureStore.class).to(DefaultSecureStore.class);
    TypeLiteral<SchemaFactory<ReviewDb>> schemaFactory = new TypeLiteral<SchemaFactory<ReviewDb>>() {
    };
    bind(schemaFactory).to(NotesMigrationSchemaFactory.class);
    bind(Key.get(schemaFactory, ReviewDbFactory.class)).to(InMemoryDatabase.class);
    install(NoSshKeyCache.module());
    install(new CanonicalWebUrlModule() {

        @Override
        protected Class<? extends Provider<String>> provider() {
            return CanonicalWebUrlProvider.class;
        }
    });
    //Replacement of DiffExecutorModule to not use thread pool in the tests
    install(new AbstractModule() {

        @Override
        protected void configure() {
        }

        @Provides
        @Singleton
        @DiffExecutor
        public ExecutorService createDiffExecutor() {
            return MoreExecutors.newDirectExecutorService();
        }
    });
    install(new DefaultCacheFactory.Module());
    install(new FakeEmailSender.Module());
    install(new SignedTokenEmailTokenVerifier.Module());
    install(new GpgModule(cfg));
    install(new H2AccountPatchReviewStore.InMemoryModule());
    bind(AllAccountsIndexer.class).toProvider(Providers.of(null));
    bind(AllChangesIndexer.class).toProvider(Providers.of(null));
    bind(AllGroupsIndexer.class).toProvider(Providers.of(null));
    IndexType indexType = null;
    try {
        indexType = cfg.getEnum("index", null, "type", IndexType.LUCENE);
    } catch (IllegalArgumentException e) {
    // Custom index type, caller must provide their own module.
    }
    if (indexType != null) {
        switch(indexType) {
            case LUCENE:
                install(luceneIndexModule());
                break;
            case ELASTICSEARCH:
                install(elasticIndexModule());
                break;
            default:
                throw new ProvisionException("index type unsupported in tests: " + indexType);
        }
    }
}
Also used : MetricMaker(com.google.gerrit.metrics.MetricMaker) DisabledMetricMaker(com.google.gerrit.metrics.DisabledMetricMaker) GerritServerId(com.google.gerrit.server.config.GerritServerId) GwtormChangeBundleReader(com.google.gerrit.server.notedb.GwtormChangeBundleReader) ChangeBundleReader(com.google.gerrit.server.notedb.ChangeBundleReader) GerritGlobalModule(com.google.gerrit.server.config.GerritGlobalModule) Injector(com.google.inject.Injector) DataSourceType(com.google.gerrit.server.schema.DataSourceType) DefaultPermissionBackendModule(com.google.gerrit.server.project.DefaultPermissionBackendModule) NotesMigrationSchemaFactory(com.google.gerrit.server.schema.NotesMigrationSchemaFactory) SchemaFactory(com.google.gwtorm.server.SchemaFactory) AllProjectsName(com.google.gerrit.server.config.AllProjectsName) DefaultCacheFactory(com.google.gerrit.server.cache.h2.DefaultCacheFactory) GerritOptions(com.google.gerrit.server.config.GerritOptions) SecureStore(com.google.gerrit.server.securestore.SecureStore) DefaultSecureStore(com.google.gerrit.server.securestore.DefaultSecureStore) ChangeUpdateExecutor(com.google.gerrit.server.update.ChangeUpdateExecutor) Singleton(com.google.inject.Singleton) SitePath(com.google.gerrit.server.config.SitePath) DiffExecutor(com.google.gerrit.server.patch.DiffExecutor) Config(org.eclipse.jgit.lib.Config) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) TrackingFootersProvider(com.google.gerrit.server.config.TrackingFootersProvider) AllChangesIndexer(com.google.gerrit.server.index.change.AllChangesIndexer) GarbageCollection(com.google.gerrit.server.git.GarbageCollection) AllAccountsIndexer(com.google.gerrit.server.index.account.AllAccountsIndexer) SignedTokenEmailTokenVerifier(com.google.gerrit.server.mail.SignedTokenEmailTokenVerifier) ProvisionException(com.google.inject.ProvisionException) TypeLiteral(com.google.inject.TypeLiteral) GpgModule(com.google.gerrit.gpg.GpgModule) IndexType(com.google.gerrit.server.index.IndexModule.IndexType) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) SearchingChangeCacheImpl(com.google.gerrit.server.git.SearchingChangeCacheImpl) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) AnonymousCowardName(com.google.gerrit.server.config.AnonymousCowardName) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) Provides(com.google.inject.Provides) H2AccountPatchReviewStore(com.google.gerrit.server.schema.H2AccountPatchReviewStore) AbstractModule(com.google.inject.AbstractModule) NotesMigration(com.google.gerrit.server.notedb.NotesMigration) CanonicalWebUrlModule(com.google.gerrit.server.config.CanonicalWebUrlModule) AllUsersNameProvider(com.google.gerrit.server.config.AllUsersNameProvider) CanonicalWebUrlProvider(com.google.gerrit.server.config.CanonicalWebUrlProvider) GerritPersonIdentProvider(com.google.gerrit.server.GerritPersonIdentProvider) AllProjectsNameProvider(com.google.gerrit.server.config.AllProjectsNameProvider) TrackingFootersProvider(com.google.gerrit.server.config.TrackingFootersProvider) AnonymousCowardNameProvider(com.google.gerrit.server.config.AnonymousCowardNameProvider) Provider(com.google.inject.Provider) AllGroupsIndexer(com.google.gerrit.server.index.group.AllGroupsIndexer) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) ExecutorService(java.util.concurrent.ExecutorService) AllUsersName(com.google.gerrit.server.config.AllUsersName)

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