use of com.google.inject.Singleton in project torodb by torodb.
the class CoreModule method createShutdowner.
@Provides
@Singleton
protected Shutdowner createShutdowner(ThreadFactory threadFactory) {
Shutdowner s = new Shutdowner(threadFactory);
s.startAsync();
s.awaitRunning();
return s;
}
use of com.google.inject.Singleton in project gerrit by GerritCodeReview.
the class MimeUtil2Module method provideMimeUtil2.
@Provides
@Singleton
MimeUtil2 provideMimeUtil2() {
MimeUtil2 m = new MimeUtil2();
m.registerMimeDetector(ExtensionMimeDetector.class.getName());
m.registerMimeDetector(MagicMimeMimeDetector.class.getName());
if (HostPlatform.isWin32()) {
m.registerMimeDetector("eu.medsea.mimeutil.detector.WindowsRegistryMimeDetector");
}
m.registerMimeDetector(DefaultFileExtensionRegistry.class.getName());
return m;
}
use of com.google.inject.Singleton in project cdap by caskdata.
the class DataSetServiceModules method getDistributedModules.
@Override
public Module getDistributedModules() {
return new AbstractModule() {
@Override
protected void configure() {
// Add the system dataset runtime module as public binding so that adding bindings could be added
install(new SystemDatasetRuntimeModule().getDistributedModules());
install(new PrivateModule() {
@Override
protected void configure() {
install(new FactoryModuleBuilder().implement(DatasetDefinitionRegistry.class, DefaultDatasetDefinitionRegistry.class).build(DatasetDefinitionRegistryFactory.class));
bind(DatasetFramework.class).annotatedWith(Names.named("datasetMDS")).toProvider(DatasetMdsProvider.class).in(Singleton.class);
expose(DatasetFramework.class).annotatedWith(Names.named("datasetMDS"));
Multibinder.newSetBinder(binder(), DatasetMetricsReporter.class).addBinding().to(HBaseDatasetMetricsReporter.class);
// NOTE: this cannot be a singleton, because MasterServiceMain needs to obtain a new instance
// every time it becomes leader and starts a dataset service.
bind(DatasetService.class);
expose(DatasetService.class);
Named datasetUserName = Names.named(Constants.Service.DATASET_EXECUTOR);
Multibinder<HttpHandler> handlerBinder = Multibinder.newSetBinder(binder(), HttpHandler.class, datasetUserName);
CommonHandlers.add(handlerBinder);
handlerBinder.addBinding().to(DatasetAdminOpHTTPHandler.class);
bind(DatasetOpExecutorService.class).in(Scopes.SINGLETON);
expose(DatasetOpExecutorService.class);
bind(DatasetOpExecutor.class).to(YarnDatasetOpExecutor.class);
expose(DatasetOpExecutor.class);
}
});
}
};
}
use of com.google.inject.Singleton in project guice by google.
the class ProviderMethodsTest method testScopedProviderMethodThrowsException.
public void testScopedProviderMethodThrowsException() {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
}
@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(), "java.lang.RuntimeException: boom", "provideInt");
}
}
use of com.google.inject.Singleton in project ninja by ninjaframework.
the class LifecycleSupportTest method providedSingletonStartableShouldBeStarted.
@Test
public void providedSingletonStartableShouldBeStarted() {
Injector injector = createInjector(new AbstractModule() {
@Override
protected void configure() {
}
@Provides
@Singleton
public MockSingletonService provide() {
return new MockSingletonService();
}
});
start(injector);
assertThat(MockSingletonService.started, equalTo(1));
}
Aggregations