Search in sources :

Example 21 with Singleton

use of javax.inject.Singleton in project wildfly-swarm by wildfly-swarm.

the class CertInfoProducer method produceCertInfo.

@Produces
@Singleton
public CertInfo produceCertInfo() {
    if (generateSelfCertificate.get()) {
        if (SwarmInfo.isProduct()) {
            throw SwarmMessages.MESSAGES.generateSelfSignedCertificateNotSupported();
        }
        checkDataDir();
        return new CertInfo(selfCertificateHost.get(), JBOSS_DATA_DIR);
    } else {
        String keystorePath = undertow.keystorePath();
        if (embeddedKeystore.get()) {
            checkDataDir();
            Path dataDir = Paths.get(System.getProperty(JBOSS_DATA_DIR));
            Path certDestination = dataDir.resolve(keystorePath);
            try {
                URL jks = ClassLoader.getSystemClassLoader().getResource(keystorePath);
                if (jks == null) {
                    Module appModule = Module.getCallerModuleLoader().loadModule("swarm.application");
                    jks = appModule.getClassLoader().getResource(keystorePath);
                }
                if (jks == null) {
                    throw new RuntimeException(String.format("Unable to locate embedded keystore %s in classpath", keystorePath));
                }
                Files.copy(jks.openStream(), certDestination);
                keystorePath = certDestination.toString();
            } catch (Exception ie) {
                throw new RuntimeException("Error copying embedded certificate", ie);
            }
        }
        String keystorePassword = undertow.keystorePassword();
        String keyPassword = undertow.keyPassword();
        String keystoreAlias = undertow.alias();
        return new CertInfo(keystorePath, keystorePassword, keyPassword, keystoreAlias);
    }
}
Also used : CertInfo(org.wildfly.swarm.undertow.descriptors.CertInfo) Path(java.nio.file.Path) Module(org.jboss.modules.Module) URL(java.net.URL) IOException(java.io.IOException) Produces(javax.enterprise.inject.Produces) Singleton(javax.inject.Singleton)

Example 22 with Singleton

use of javax.inject.Singleton in project atlasdb by palantir.

the class TestSweeperModule method provideSweepTaskRunner.

@Provides
@Singleton
public SweepTaskRunner provideSweepTaskRunner(SerializableTransactionManager txm, @Named("kvs") KeyValueService kvs, TransactionService transactionService, SweepStrategyManager sweepStrategyManager, Follower follower, PersistentLockManager persistentLockManager, ServicesConfig config) {
    LongSupplier unreadable = unreadableTs.orElse(txm::getUnreadableTimestamp);
    LongSupplier immutable = immutableTs.orElse(txm::getImmutableTimestamp);
    return new SweepTaskRunner(kvs, unreadable, immutable, transactionService, sweepStrategyManager, new CellsSweeper(txm, kvs, persistentLockManager, ImmutableList.of(follower)));
}
Also used : CellsSweeper(com.palantir.atlasdb.sweep.CellsSweeper) LongSupplier(java.util.function.LongSupplier) SweepTaskRunner(com.palantir.atlasdb.sweep.SweepTaskRunner) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 23 with Singleton

use of javax.inject.Singleton in project butter-android by butterproject.

the class DataModule method provideCache.

@Provides
@Singleton
public Cache provideCache(PreferencesHandler preferencesHandler) {
    int cacheSize = 10 * 1024 * 1024;
    File cacheLocation = new File(preferencesHandler.getStorageLocation());
    cacheLocation.mkdirs();
    return new Cache(cacheLocation, cacheSize);
}
Also used : File(java.io.File) Cache(okhttp3.Cache) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 24 with Singleton

use of javax.inject.Singleton in project sbt-android by scala-android.

the class DebugDataModule method providePicasso.

@Provides
@Singleton
Picasso providePicasso(OkHttpClient client, NetworkBehavior behavior, @IsMockMode boolean isMockMode, Application app) {
    Picasso.Builder builder = new Picasso.Builder(app).downloader(new OkHttpDownloader(client));
    if (isMockMode) {
        builder.addRequestHandler(new MockRequestHandler(behavior, app.getAssets()));
    }
    builder.listener((picasso, uri, exception) -> {
        Timber.e(exception, "Error while loading image " + uri);
    });
    return builder.build();
}
Also used : Picasso(com.squareup.picasso.Picasso) OkHttpDownloader(com.squareup.picasso.OkHttpDownloader) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 25 with Singleton

use of javax.inject.Singleton in project sbt-android by scala-android.

the class DebugDataModule method provideOkHttpClient.

@Provides
@Singleton
OkHttpClient provideOkHttpClient(Application app, Preference<InetSocketAddress> networkProxyAddress) {
    OkHttpClient client = DataModule.createOkHttpClient(app);
    client.setSslSocketFactory(createBadSslSocketFactory());
    client.setProxy(InetSocketAddressPreferenceAdapter.createProxy(networkProxyAddress.get()));
    return client;
}
Also used : OkHttpClient(com.squareup.okhttp.OkHttpClient) 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