Search in sources :

Example 86 with Singleton

use of javax.inject.Singleton in project Rutgers-Course-Tracker by tevjef.

the class ScraperModule method providesRMP.

@Provides
@Singleton
public RMPScraper providesRMP(OkHttpClient client) {
    OkHttpClient okClient = client.clone();
    okClient.setConnectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    okClient.setReadTimeout(READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    //okClient.networkInterceptors().add(getCacheControlInterceptor(TimeUnit.DAYS.toMillis(7)));
    return new RMPScraper(okClient);
}
Also used : OkHttpClient(com.squareup.okhttp.OkHttpClient) RMPScraper(com.tevinjeffrey.rmp.scraper.RMPScraper) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 87 with Singleton

use of javax.inject.Singleton in project Rutgers-Course-Tracker by tevjef.

the class RutgersCTModule method providesOkHttpClient.

@Provides
@Singleton
public OkHttpClient providesOkHttpClient(Context context) {
    OkHttpClient client = new OkHttpClient();
    client.setConnectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    client.setReadTimeout(READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    client.networkInterceptors().add(new StethoInterceptor());
    File httpCacheDir = new File(context.getCacheDir(), context.getString(R.string.application_name));
    // 50 MiB
    long httpCacheSize = 50 * 1024 * 1024;
    Cache cache = new Cache(httpCacheDir, httpCacheSize);
    client.setCache(cache);
    if (BuildConfig.DEBUG) {
        try {
            cache.evictAll();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return client;
}
Also used : OkHttpClient(com.squareup.okhttp.OkHttpClient) StethoInterceptor(com.facebook.stetho.okhttp.StethoInterceptor) IOException(java.io.IOException) File(java.io.File) Cache(com.squareup.okhttp.Cache) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 88 with Singleton

use of javax.inject.Singleton in project Rutgers-Course-Tracker by tevjef.

the class RetroRutgersModule method providesRutgersRestAdapter.

@Provides
@Singleton
public RetroRutgersService providesRutgersRestAdapter(OkHttpClient client, Gson gson) {
    OkHttpClient okClient = client.clone();
    okClient.networkInterceptors().add(getCacheControlInterceptor(TimeUnit.SECONDS.toMillis(5)));
    return new RestAdapter.Builder().setEndpoint("http://sis.rutgers.edu/soc/").setLogLevel(RestAdapter.LogLevel.HEADERS_AND_ARGS).setErrorHandler(new MyErrorHandler()).setClient(new OkClient(okClient)).setConverter(new GsonConverter(gson)).build().create(RetroRutgersService.class);
}
Also used : GsonConverter(retrofit.converter.GsonConverter) OkHttpClient(com.squareup.okhttp.OkHttpClient) OkClient(retrofit.client.OkClient) RestAdapter(retrofit.RestAdapter) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 89 with Singleton

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

the class CoreRestGuiceModule method getServerAttributeTitles.

@Provides
@Singleton
@Named("ServerAttributeTitles")
public Properties getServerAttributeTitles() throws IOException {
    Properties titleProperties = new Properties();
    titleProperties.load(getClass().getClassLoader().getResourceAsStream("amConsole.properties"));
    return titleProperties;
}
Also used : SystemProperties(com.iplanet.am.util.SystemProperties) Properties(java.util.Properties) Named(javax.inject.Named) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 90 with Singleton

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

the class SoapSTSInstanceModule method getSTSProperties.

/**
     * This method will provide the instance of the STSPropertiesMBean necessary both for the STS proper, and for the
     * CXF interceptor-set which enforces the SecurityPolicy bindings.
     *
     * It should be a singleton because this same instance is shared by all of the token operation instances, as well as
     * by the CXF interceptor-set
     */
@Provides
@Singleton
@Inject
STSPropertiesMBean getSTSProperties(Logger logger) {
    StaticSTSProperties stsProperties = new StaticSTSProperties();
    // KeystoreConfig may be null for a TLS-based SecurityPolicy binding, or for the AM-bare binding.
    if (stsInstanceConfig.getKeystoreConfig() != null) {
        stsProperties.setCallbackHandler(new SoapSTSCallbackHandler(stsInstanceConfig.getKeystoreConfig(), logger));
        Crypto crypto;
        try {
            crypto = CryptoFactory.getInstance(getEncryptionProperties());
        } catch (WSSecurityException e) {
            String message = "Exception caught initializing the CryptoFactory: " + e;
            logger.error(message, e);
            throw new IllegalStateException(message);
        }
        stsProperties.setSignatureCrypto(crypto);
        stsProperties.setEncryptionCrypto(crypto);
        stsProperties.setSignatureUsername(stsInstanceConfig.getKeystoreConfig().getSignatureKeyAlias());
    }
    return stsProperties;
}
Also used : Crypto(org.apache.ws.security.components.crypto.Crypto) SoapSTSCallbackHandler(org.forgerock.openam.sts.soap.SoapSTSCallbackHandler) WSSecurityException(org.apache.ws.security.WSSecurityException) StaticSTSProperties(org.apache.cxf.sts.StaticSTSProperties) Inject(javax.inject.Inject) 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