Search in sources :

Example 1 with Singleton

use of javax.inject.Singleton in project MovieGuide by esoxjem.

the class NetworkModule method provideOkHttpClient.

@Provides
@Singleton
OkHttpClient provideOkHttpClient() {
    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    return new okhttp3.OkHttpClient.Builder().connectTimeout(CONNECT_TIMEOUT_IN_MS, TimeUnit.MILLISECONDS).addInterceptor(loggingInterceptor).build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 2 with Singleton

use of javax.inject.Singleton in project SeriesGuide by UweTrottmann.

the class HttpClientModule method provideOkHttpClient.

/**
     * Returns this apps {@link OkHttpClient} with enabled response cache. Should be used with API
     * calls.
     */
@Provides
@Singleton
OkHttpClient provideOkHttpClient(SgApp app, Cache cache) {
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.connectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    builder.readTimeout(READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    builder.addInterceptor(new SgTmdbInterceptor());
    builder.addNetworkInterceptor(new SgTheTvdbInterceptor(app));
    builder.addNetworkInterceptor(new SgTraktInterceptor(app));
    builder.authenticator(new AllApisAuthenticator(app));
    builder.cache(cache);
    return builder.build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) SgTmdbInterceptor(com.battlelancer.seriesguide.tmdbapi.SgTmdbInterceptor) SgTraktInterceptor(com.battlelancer.seriesguide.traktapi.SgTraktInterceptor) SgTheTvdbInterceptor(com.battlelancer.seriesguide.thetvdbapi.SgTheTvdbInterceptor) AllApisAuthenticator(com.battlelancer.seriesguide.util.AllApisAuthenticator) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 3 with Singleton

use of javax.inject.Singleton in project OpenAM by OpenRock.

the class CoreGuiceModule method getCTSObjectMapper.

/**
     * CTS Jackson Object Mapper.
     * <p>
     * Use a static singleton as per <a href="http://wiki.fasterxml.com/JacksonBestPracticesPerformance">performance
     * best practice.</a>
     */
@Provides
@Named(CoreTokenConstants.OBJECT_MAPPER)
@Singleton
ObjectMapper getCTSObjectMapper() {
    ObjectMapper mapper = new ObjectMapper().configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true).configure(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
    /**
         * @see http://stackoverflow.com/questions/7105745/how-to-specify-jackson-to-only-use-fields-preferably-globally
         */
    mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker().withFieldVisibility(JsonAutoDetect.Visibility.ANY).withGetterVisibility(JsonAutoDetect.Visibility.NONE).withIsGetterVisibility(JsonAutoDetect.Visibility.NONE).withSetterVisibility(JsonAutoDetect.Visibility.NONE).withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
    SimpleModule customModule = new SimpleModule("openam", Version.unknownVersion());
    customModule.addKeyDeserializer(SessionID.class, new SessionIDKeyDeserialiser());
    mapper.registerModule(customModule);
    mapper.addHandler(new CompatibilityProblemHandler());
    return mapper;
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) Named(javax.inject.Named) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 4 with Singleton

use of javax.inject.Singleton in project OpenAM by OpenRock.

the class CoreGuiceModule method getSAML2TokenRepository.

@Provides
@Singleton
SAML2TokenRepository getSAML2TokenRepository() {
    final String DEFAULT_REPOSITORY_CLASS = "org.forgerock.openam.cts.impl.SAML2CTSPersistentStore";
    final String REPOSITORY_CLASS_PROPERTY = "com.sun.identity.saml2.plugins.SAML2RepositoryImpl";
    final String CTS_SAML2_REPOSITORY_CLASS_NAME = SystemPropertiesManager.get(REPOSITORY_CLASS_PROPERTY, DEFAULT_REPOSITORY_CLASS);
    SAML2TokenRepository result;
    try {
        // Use Guice to create class to get all of its dependency goodness
        result = InjectorHolder.getInstance(Class.forName(CTS_SAML2_REPOSITORY_CLASS_NAME).asSubclass(SAML2TokenRepository.class));
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException(e);
    }
    return result;
}
Also used : SAML2TokenRepository(org.forgerock.openam.federation.saml2.SAML2TokenRepository) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 5 with Singleton

use of javax.inject.Singleton in project OpenAM by OpenRock.

the class RestGuiceModule method getInternalCrestRealmRouter.

@Provides
@Named("InternalCrestRouter")
@Singleton
Router getInternalCrestRealmRouter(@Named("CrestRealmRouter") Router crestRealmRouter) {
    Router internalCrestRouter = new Router();
    internalCrestRouter.setDefaultRoute(crestRealmRouter);
    return internalCrestRouter;
}
Also used : Router(org.forgerock.json.resource.Router) Named(javax.inject.Named) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Aggregations

Singleton (javax.inject.Singleton)168 Provides (dagger.Provides)98 Provides (com.google.inject.Provides)57 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)21 Named (javax.inject.Named)17 OkHttpClient (okhttp3.OkHttpClient)17 Cache (okhttp3.Cache)10 List (java.util.List)9 ConfigBinder.configBinder (com.facebook.airlift.configuration.ConfigBinder.configBinder)8 Binder (com.google.inject.Binder)8 Module (com.google.inject.Module)8 CachingStripeMetadataSource (com.facebook.presto.orc.CachingStripeMetadataSource)7 DwrfAwareStripeMetadataSourceFactory (com.facebook.presto.orc.DwrfAwareStripeMetadataSourceFactory)7 OrcDataSourceId (com.facebook.presto.orc.OrcDataSourceId)7 StorageStripeMetadataSource (com.facebook.presto.orc.StorageStripeMetadataSource)7 StripeMetadataSource (com.facebook.presto.orc.StripeMetadataSource)7 StripeMetadataSourceFactory (com.facebook.presto.orc.StripeMetadataSourceFactory)7 CachingOrcFileTailSource (com.facebook.presto.orc.cache.CachingOrcFileTailSource)7 OrcCacheConfig (com.facebook.presto.orc.cache.OrcCacheConfig)7 OrcFileTailSource (com.facebook.presto.orc.cache.OrcFileTailSource)7