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