Search in sources :

Example 6 with Singleton

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

the class ThymeleafModule method provideTemplateResolver.

@Provides
@Singleton
ITemplateResolver provideTemplateResolver(ServerConfig serverConfig, Config config) {
    IResourceResolver resourceResolver = new FileSystemBindingThymeleafResourceResolver(serverConfig.getBaseDir());
    TemplateResolver templateResolver = new TemplateResolver();
    templateResolver.setResourceResolver(resourceResolver);
    templateResolver.setTemplateMode(getTemplatesModeSetting(config));
    templateResolver.setPrefix(getTemplatesPrefixSetting(config));
    templateResolver.setSuffix(getTemplatesSuffixSetting(config));
    templateResolver.setCacheable(getCacheSizeSetting(config) > 0);
    // Never use TTL expiration
    templateResolver.setCacheTTLMs(null);
    return templateResolver;
}
Also used : IResourceResolver(org.thymeleaf.resourceresolver.IResourceResolver) FileSystemBindingThymeleafResourceResolver(ratpack.thymeleaf.internal.FileSystemBindingThymeleafResourceResolver) TemplateResolver(org.thymeleaf.templateresolver.TemplateResolver) ITemplateResolver(org.thymeleaf.templateresolver.ITemplateResolver) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 7 with Singleton

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

the class ThymeleafModule method provideTemplateEngine.

@Provides
@Singleton
TemplateEngine provideTemplateEngine(ITemplateResolver templateResolver, ICacheManager cacheManager, Set<IDialect> dialects) {
    final TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);
    templateEngine.setCacheManager(cacheManager);
    dialects.stream().forEach(templateEngine::addDialect);
    return templateEngine;
}
Also used : TemplateEngine(org.thymeleaf.TemplateEngine) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 8 with Singleton

use of com.google.inject.Singleton in project keywhiz by square.

the class ServiceModule 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 : 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 9 with Singleton

use of com.google.inject.Singleton in project keywhiz by square.

the class ServiceModule method readonlyJooqContext.

@Provides
@Singleton
@Readonly
DSLContext readonlyJooqContext(@Readonly ManagedDataSource dataSource) throws SQLException {
    DSLContext dslContext = DSLContexts.databaseAgnostic(dataSource);
    org.jooq.Configuration configuration = dslContext.configuration();
    // Disable support for nested transactions via savepoints (required for MySQL)
    // See: https://groups.google.com/forum/#!topic/jooq-user/zG0U6CkxI5o
    configuration.set(new DefaultTransactionProvider(configuration.connectionProvider(), false));
    return dslContext;
}
Also used : DefaultTransactionProvider(org.jooq.impl.DefaultTransactionProvider) DSLContext(org.jooq.DSLContext) Readonly(keywhiz.service.config.Readonly) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 10 with Singleton

use of com.google.inject.Singleton in project keywhiz by square.

the class ServiceModule method dataSource.

// ManagedDataSource
@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 : DataSourceFactory(io.dropwizard.db.DataSourceFactory) ManagedDataSource(io.dropwizard.db.ManagedDataSource) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Aggregations

Singleton (com.google.inject.Singleton)24 Provides (com.google.inject.Provides)23 AbstractModule (com.google.inject.AbstractModule)6 Injector (com.google.inject.Injector)5 ConfigModule (co.cask.cdap.common.guice.ConfigModule)2 ProvisionException (com.google.inject.ProvisionException)2 DataSourceFactory (io.dropwizard.db.DataSourceFactory)2 ManagedDataSource (io.dropwizard.db.ManagedDataSource)2 LazySingleton (io.druid.guice.LazySingleton)2 InetSocketAddress (java.net.InetSocketAddress)2 SocketAddress (java.net.SocketAddress)2 Readonly (keywhiz.service.config.Readonly)2 DatasetDefinitionRegistry (co.cask.cdap.api.dataset.module.DatasetDefinitionRegistry)1 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)1 AppFabricServiceRuntimeModule (co.cask.cdap.app.guice.AppFabricServiceRuntimeModule)1 AuthorizationModule (co.cask.cdap.app.guice.AuthorizationModule)1 ProgramRunnerRuntimeModule (co.cask.cdap.app.guice.ProgramRunnerRuntimeModule)1 ServiceStoreModules (co.cask.cdap.app.guice.ServiceStoreModules)1 TwillModule (co.cask.cdap.app.guice.TwillModule)1 CConfiguration (co.cask.cdap.common.conf.CConfiguration)1