Search in sources :

Example 61 with Singleton

use of com.google.inject.Singleton in project ovirt-engine by oVirt.

the class BaseSystemModule method getGenericApiGWTService.

@Provides
@Singleton
public GenericApiGWTServiceAsync getGenericApiGWTService(final XsrfRpcRequestBuilder requestBuilder) {
    // no need to use GenericApiGWTServiceAsync.Util as this is GIN-managed singleton anyway
    GenericApiGWTServiceAsync service = GWT.create(GenericApiGWTService.class);
    // cast to ServiceDefTarget and set RPC request builder as needed
    ((ServiceDefTarget) service).setRpcRequestBuilder(requestBuilder);
    return service;
}
Also used : GenericApiGWTServiceAsync(org.ovirt.engine.ui.frontend.gwtservices.GenericApiGWTServiceAsync) ServiceDefTarget(com.google.gwt.user.client.rpc.ServiceDefTarget) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 62 with Singleton

use of com.google.inject.Singleton in project n4js by eclipse.

the class GHOLD_180_CheckInjectedSharedSingletons_PluginUITest method testInjectorsSharingSameSingleton.

/**
 * Checks whether the same instance is provided by different injector instances when the class of the provided
 * instance is annotated with {@code @Singleton}.
 */
@Test
public void testInjectorsSharingSameSingleton() throws Exception {
    final Class<N4JSTypeSystem> testedType = N4JSTypeSystem.class;
    final Singleton[] singletons = testedType.getAnnotationsByType(Singleton.class);
    assertTrue(testedType.getSimpleName() + " is not annotated with " + Singleton.class.getName() + ".", !Arrays2.isEmpty(singletons));
    final String injectorId = N4JSActivator.ORG_ECLIPSE_N4JS_N4JS;
    final Injector parentInjector = N4JSActivator.getInstance().getInjector(injectorId);
    final MockUIPlugin mockBundle = new MockUIPlugin();
    try {
        mockBundle.start(/* context */
        null);
        assertTrue("Mock bundle is not running yet.", Bundle.ACTIVE == mockBundle.getBundle().getState());
        final Injector childInjector = mockBundle.getN4JSChildInjector();
        final N4JSTypeSystem instanceFromParent = parentInjector.getInstance(testedType);
        final N4JSTypeSystem instanceFromChild = childInjector.getInstance(testedType);
        assertTrue("Expected the same instance of " + testedType.getSimpleName() + " from parent and child injectors.", instanceFromChild == instanceFromParent);
    } finally {
        mockBundle.stop(/* context */
        null);
    }
}
Also used : N4JSTypeSystem(org.eclipse.n4js.typesystem.N4JSTypeSystem) Singleton(com.google.inject.Singleton) Injector(com.google.inject.Injector) Test(org.junit.Test)

Example 63 with Singleton

use of com.google.inject.Singleton in project airpal by airbnb.

the class AirpalModule method provideSchemaCache.

@Singleton
@Provides
public SchemaCache provideSchemaCache(QueryRunnerFactory queryRunnerFactory, @Named("presto") ExecutorService executorService) {
    final SchemaCache cache = new SchemaCache(queryRunnerFactory, executorService);
    cache.populateCache(config.getPrestoCatalog());
    return cache;
}
Also used : SchemaCache(com.airbnb.airpal.presto.metadata.SchemaCache) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 64 with Singleton

use of com.google.inject.Singleton in project airpal by airbnb.

the class AirpalModule method provideDBI.

@Singleton
@Provides
public DBI provideDBI(ObjectMapper objectMapper) throws ClassNotFoundException {
    final DBIFactory factory = new DBIFactory();
    final DBI dbi = factory.build(environment, config.getDataSourceFactory(), provideDbType().name());
    dbi.registerMapper(new TableRow.TableRowMapper(objectMapper));
    dbi.registerMapper(new QueryStoreMapper(objectMapper));
    dbi.registerArgumentFactory(new UUIDArgumentFactory());
    dbi.registerArgumentFactory(new URIArgumentFactory());
    return dbi;
}
Also used : URIArgumentFactory(com.airbnb.airpal.sql.jdbi.URIArgumentFactory) UUIDArgumentFactory(com.airbnb.airpal.sql.jdbi.UUIDArgumentFactory) TableRow(com.airbnb.airpal.sql.beans.TableRow) DBI(org.skife.jdbi.v2.DBI) QueryStoreMapper(com.airbnb.airpal.sql.jdbi.QueryStoreMapper) DBIFactory(io.dropwizard.jdbi.DBIFactory) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 65 with Singleton

use of com.google.inject.Singleton in project joynr by bmwcarit.

the class AccessControlClientModule method provideCacheManager.

@Provides
@Singleton
public CacheManager provideCacheManager() {
    Configuration configuration = new Configuration();
    configuration.setName("LDACEhCacheManager");
    configuration.setUpdateCheck(false);
    return CacheManager.create(configuration);
}
Also used : Configuration(net.sf.ehcache.config.Configuration) 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