Search in sources :

Example 11 with Singleton

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;
}
Also used : Shutdowner(com.torodb.core.Shutdowner) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 12 with Singleton

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;
}
Also used : ExtensionMimeDetector(eu.medsea.mimeutil.detector.ExtensionMimeDetector) MagicMimeMimeDetector(eu.medsea.mimeutil.detector.MagicMimeMimeDetector) MimeUtil2(eu.medsea.mimeutil.MimeUtil2) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 13 with Singleton

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);
                }
            });
        }
    };
}
Also used : Named(com.google.inject.name.Named) HttpHandler(co.cask.http.HttpHandler) DatasetAdminOpHTTPHandler(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetAdminOpHTTPHandler) Multibinder(com.google.inject.multibindings.Multibinder) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) DefaultDatasetDefinitionRegistry(co.cask.cdap.data2.dataset2.DefaultDatasetDefinitionRegistry) DatasetDefinitionRegistry(co.cask.cdap.api.dataset.module.DatasetDefinitionRegistry) LocalDatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.LocalDatasetOpExecutor) DatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor) YarnDatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.YarnDatasetOpExecutor) AbstractModule(com.google.inject.AbstractModule) DefaultDatasetDefinitionRegistry(co.cask.cdap.data2.dataset2.DefaultDatasetDefinitionRegistry) Singleton(com.google.inject.Singleton) DatasetOpExecutorService(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService) HBaseDatasetMetricsReporter(co.cask.cdap.data2.metrics.HBaseDatasetMetricsReporter) LevelDBDatasetMetricsReporter(co.cask.cdap.data2.metrics.LevelDBDatasetMetricsReporter) DatasetMetricsReporter(co.cask.cdap.data2.metrics.DatasetMetricsReporter) HBaseDatasetMetricsReporter(co.cask.cdap.data2.metrics.HBaseDatasetMetricsReporter) YarnDatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.YarnDatasetOpExecutor) PrivateModule(com.google.inject.PrivateModule)

Example 14 with Singleton

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

Example 15 with Singleton

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));
}
Also used : Injector(com.google.inject.Injector) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Aggregations

Singleton (com.google.inject.Singleton)24 Provides (com.google.inject.Provides)23 AbstractModule (com.google.inject.AbstractModule)6 Injector (com.google.inject.Injector)5 ConfigModule (co.cask.cdap.common.guice.ConfigModule)2 ProvisionException (com.google.inject.ProvisionException)2 DataSourceFactory (io.dropwizard.db.DataSourceFactory)2 ManagedDataSource (io.dropwizard.db.ManagedDataSource)2 LazySingleton (io.druid.guice.LazySingleton)2 InetSocketAddress (java.net.InetSocketAddress)2 SocketAddress (java.net.SocketAddress)2 Readonly (keywhiz.service.config.Readonly)2 DatasetDefinitionRegistry (co.cask.cdap.api.dataset.module.DatasetDefinitionRegistry)1 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)1 AppFabricServiceRuntimeModule (co.cask.cdap.app.guice.AppFabricServiceRuntimeModule)1 AuthorizationModule (co.cask.cdap.app.guice.AuthorizationModule)1 ProgramRunnerRuntimeModule (co.cask.cdap.app.guice.ProgramRunnerRuntimeModule)1 ServiceStoreModules (co.cask.cdap.app.guice.ServiceStoreModules)1 TwillModule (co.cask.cdap.app.guice.TwillModule)1 CConfiguration (co.cask.cdap.common.conf.CConfiguration)1