Search in sources :

Example 56 with Singleton

use of javax.inject.Singleton in project webpieces by deanhiller.

the class GuiceModule method createClient.

@Provides
@Singleton
public Http2Client createClient(MeterRegistry metrics) {
    BackpressureConfig config = new BackpressureConfig();
    // clients should NOT have backpressure or it could screw the server over when the server does not support backpresssure
    config.setMaxBytes(null);
    // This is an http1_1 client masquerading as an http2 client so we can switch to http2 faster when ready!!
    Http2Client httpClient = Http2to11ClientFactory.createHttpClient("httpclient", 10, config, metrics);
    return httpClient;
}
Also used : BackpressureConfig(org.webpieces.nio.api.BackpressureConfig) Http2Client(org.webpieces.http2client.api.Http2Client) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 57 with Singleton

use of javax.inject.Singleton in project webpieces by deanhiller.

the class WebServerModule method providesAsyncServerMgr.

@Provides
@Singleton
public HttpFrontendManager providesAsyncServerMgr(ChannelManager chanMgr, ScheduledExecutorService timer, BufferPool pool, Time time, WebServerConfig config, MeterRegistry metrics) {
    HttpParser httpParser = HttpParserFactory.createParser("a", new SimpleMeterRegistry(), pool);
    HpackParser http2Parser = HpackParserFactory.createParser(pool, true);
    InjectionConfig injConfig = new InjectionConfig(http2Parser, time, config.getHttp2Config());
    return HttpFrontendFactory.createFrontEnd(chanMgr, timer, injConfig, httpParser, metrics);
}
Also used : HpackParser(com.webpieces.hpack.api.HpackParser) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) HttpParser(org.webpieces.httpparser.api.HttpParser) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 58 with Singleton

use of javax.inject.Singleton in project roboguice by roboguice.

the class MiniGuiceTest method testSingletonsAreEager.

public void testSingletonsAreEager() {
    final AtomicBoolean sInjected = new AtomicBoolean();
    R.injected = false;
    MiniGuice.inject(A.class, new Object() {

        @Provides
        F provideF(R r) {
            return new F();
        }

        @Provides
        @Singleton
        S provideS() {
            sInjected.set(true);
            return new S();
        }
    });
    assertTrue(R.injected);
    assertTrue(sInjected.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 59 with Singleton

use of javax.inject.Singleton in project jianshi by wingjay.

the class AppModule method provideOkHttpClient.

@Provides
@Singleton
OkHttpClient provideOkHttpClient(GlobalRequestInterceptor globalRequestInterceptor) {
    OkHttpClient.Builder builder = new OkHttpClient.Builder().connectionPool(new ConnectionPool(5, 59, TimeUnit.SECONDS)).connectTimeout(20, TimeUnit.SECONDS).readTimeout(20, TimeUnit.SECONDS).addInterceptor(globalRequestInterceptor).retryOnConnectionFailure(false);
    if (BuildConfig.DEBUG) {
        builder.addNetworkInterceptor(new StethoInterceptor());
    }
    HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
    httpLoggingInterceptor.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE);
    builder.addInterceptor(httpLoggingInterceptor);
    return builder.build();
}
Also used : ConnectionPool(okhttp3.ConnectionPool) OkHttpClient(okhttp3.OkHttpClient) StethoInterceptor(com.facebook.stetho.okhttp3.StethoInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 60 with Singleton

use of javax.inject.Singleton in project u2020 by JakeWharton.

the class DebugApiModule method provideLoggingInterceptor.

@Provides
@Singleton
HttpLoggingInterceptor provideLoggingInterceptor() {
    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(message -> Timber.tag("OkHttp").v(message));
    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
    return loggingInterceptor;
}
Also used : HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Singleton(javax.inject.Singleton) Provides(dagger.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