Search in sources :

Example 66 with Singleton

use of com.google.inject.Singleton in project LanternServer by LanternPowered.

the class LanternModule method provideAssetManager.

@Exposed
@Provides
@Singleton
private LanternAssetManager provideAssetManager(@Option({ "asset-repository-config", "asset-repo-config" }) @Nullable Path repoConfig, LanternPluginManager pluginManager) {
    final Gson gson = new GsonBuilder().registerTypeAdapter(AssetRepository.class, new AssetRepositoryJsonDeserializer(pluginManager)).create();
    try {
        URL url;
        if (repoConfig != null) {
            url = PathUtils.toURL(repoConfig);
        } else {
            url = getClass().getClassLoader().getResource("assets_repo.json");
            checkNotNull(url);
        }
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
            return new LanternAssetManager(gson.fromJson(reader, AssetRepository.class));
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : LanternAssetManager(org.lanternpowered.server.asset.LanternAssetManager) InputStreamReader(java.io.InputStreamReader) GsonBuilder(com.google.gson.GsonBuilder) BufferedReader(java.io.BufferedReader) Gson(com.google.gson.Gson) AssetRepository(org.lanternpowered.server.asset.AssetRepository) IOException(java.io.IOException) AssetRepositoryJsonDeserializer(org.lanternpowered.server.asset.json.AssetRepositoryJsonDeserializer) URL(java.net.URL) Exposed(com.google.inject.Exposed) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 67 with Singleton

use of com.google.inject.Singleton in project guice by google.

the class ProviderMethodsTest method testScopedProviderMethodThrowsException.

@Test
public void testScopedProviderMethodThrowsException() {
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Provides
        @Singleton
        int provideInt() {
            throw new RuntimeException("boom");
        }
    });
    Provider<Integer> intProvider = injector.getProvider(Integer.class);
    try {
        intProvider.get();
        fail();
    } catch (ProvisionException pe) {
        // by default assertContains asserts that the last item doesn't repeat... which is the main
        // thing we are testing for
        assertContains(pe.getMessage(), "RuntimeException: boom", "provideInt");
    }
}
Also used : ProvisionException(com.google.inject.ProvisionException) Injector(com.google.inject.Injector) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 68 with Singleton

use of com.google.inject.Singleton in project gerrit by GerritCodeReview.

the class SshAddressesModule method provideListenAddresses.

@Provides
@Singleton
@SshListenAddresses
public List<SocketAddress> provideListenAddresses(@GerritServerConfig Config cfg) {
    List<SocketAddress> listen = Lists.newArrayListWithExpectedSize(2);
    String[] want = cfg.getStringList("sshd", null, "listenaddress");
    if (want == null || want.length == 0) {
        listen.add(new InetSocketAddress(DEFAULT_PORT));
        return listen;
    }
    if (want.length == 1 && isOff(want[0])) {
        return listen;
    }
    for (String desc : want) {
        try {
            listen.add(SocketUtil.resolve(desc, DEFAULT_PORT));
        } catch (IllegalArgumentException e) {
            logger.atSevere().log("Bad sshd.listenaddress: %s: %s", desc, e.getMessage());
        }
    }
    return listen;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 69 with Singleton

use of com.google.inject.Singleton in project druid by druid-io.

the class JettyServerModule method getJacksonSmileProvider.

@Provides
@Singleton
public JacksonSmileProvider getJacksonSmileProvider(@Smile ObjectMapper objectMapper) {
    final JacksonSmileProvider provider = new JacksonSmileProvider();
    provider.setMapper(objectMapper);
    return provider;
}
Also used : JacksonSmileProvider(com.fasterxml.jackson.jaxrs.smile.JacksonSmileProvider) LazySingleton(org.apache.druid.guice.LazySingleton) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 70 with Singleton

use of com.google.inject.Singleton in project druid by druid-io.

the class JettyServerModule method getJacksonJsonProvider.

@Provides
@Singleton
public JacksonJsonProvider getJacksonJsonProvider(@Json ObjectMapper objectMapper) {
    final JacksonJsonProvider provider = new JacksonJsonProvider();
    provider.setMapper(objectMapper);
    return provider;
}
Also used : JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) LazySingleton(org.apache.druid.guice.LazySingleton) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Aggregations

Singleton (com.google.inject.Singleton)81 Provides (com.google.inject.Provides)78 AbstractModule (com.google.inject.AbstractModule)8 Injector (com.google.inject.Injector)8 Named (com.google.inject.name.Named)7 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)7 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)7 Model (org.ovirt.engine.ui.uicommonweb.models.Model)7 File (java.io.File)5 IOException (java.io.IOException)5 SearchableDetailTabModelProvider (org.ovirt.engine.ui.common.uicommon.model.SearchableDetailTabModelProvider)5 PermissionListModel (org.ovirt.engine.ui.uicommonweb.models.configure.PermissionListModel)5 DataSourceFactory (io.dropwizard.db.DataSourceFactory)4 ManagedDataSource (io.dropwizard.db.ManagedDataSource)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 InetSocketAddress (java.net.InetSocketAddress)3 SocketAddress (java.net.SocketAddress)3 Properties (java.util.Properties)3 Test (org.junit.Test)3 ConfigModule (co.cask.cdap.common.guice.ConfigModule)2