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();
}
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();
}
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;
}
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;
}
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;
}
Aggregations