use of com.google.inject.TypeLiteral in project divide by HiddenStage.
the class BackendModule method configure.
@Override
protected final void configure() {
logConfiguration();
if (config == null)
throw new IllegalStateException("Config can not be null");
// ORDER MATTER
bind(type).toInstance(config);
bind(Config.class).toInstance(config);
bind(Backend.class).in(Singleton.class);
bind(Storage.class).toInstance(new XmlStorage(new File(config.fileSavePath + "storage.xml"), Storage.MODE_WORLD_WRITEABLE));
bind(AccountStorage.class).toInstance(new XmlAccoutStorage(new File(config.fileSavePath + "accounts.xml")));
bind(new TypeLiteral<DAO<BackendObject, BackendObject>>() {
}).to(new TypeLiteral<LocalStorageIBoxDb<BackendObject, BackendObject>>() {
}).in(Singleton.class);
// ugly but required, doesnt allow binding to itself
if (AuthManager.class.equals(getAuthManagerClass())) {
bind(AuthManager.class).in(Singleton.class);
} else {
bind(AuthManager.class).to(getAuthManagerClass()).in(Singleton.class);
}
if (DataManager.class.equals(getDataManagerClass())) {
bind(DataManager.class).in(Singleton.class);
} else {
bind(DataManager.class).to(getDataManagerClass()).in(Singleton.class);
}
if (ObjectManager.class.equals(getObjectManagerClass())) {
bind(ObjectManager.class).in(Singleton.class);
} else {
bind(ObjectManager.class).to(getObjectManagerClass()).in(Singleton.class);
}
requestStaticInjection(Backend.class);
requestStaticInjection(BackendUser.class);
requestStaticInjection(BackendServices.class);
additionalConfig(config);
}
use of com.google.inject.TypeLiteral in project gerrit by GerritCodeReview.
the class InMemoryTestingDatabaseModule method configure.
@Override
protected void configure() {
bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(cfg);
// TODO(dborowitz): Use jimfs.
Path p = Paths.get(cfg.getString("gerrit", null, "tempSiteDir"));
bind(Path.class).annotatedWith(SitePath.class).toInstance(p);
makeSiteDirs(p);
bind(GitRepositoryManager.class).to(InMemoryRepositoryManager.class);
bind(InMemoryRepositoryManager.class).in(SINGLETON);
bind(MetricMaker.class).to(DisabledMetricMaker.class);
bind(DataSourceType.class).to(InMemoryH2Type.class);
bind(NotesMigration.class).to(TestNotesMigration.class);
TypeLiteral<SchemaFactory<ReviewDb>> schemaFactory = new TypeLiteral<SchemaFactory<ReviewDb>>() {
};
bind(schemaFactory).to(NotesMigrationSchemaFactory.class);
bind(Key.get(schemaFactory, ReviewDbFactory.class)).to(InMemoryDatabase.class);
bind(InMemoryDatabase.class).in(SINGLETON);
bind(ChangeBundleReader.class).to(GwtormChangeBundleReader.class);
listener().to(CreateDatabase.class);
bind(SitePaths.class);
bind(TrackingFooters.class).toProvider(TrackingFootersProvider.class).in(SINGLETON);
install(new SchemaModule());
bind(SchemaVersion.class).to(SchemaVersion.C);
}
use of com.google.inject.TypeLiteral in project cdap by caskdata.
the class DatasetServiceTestBase method initializeAndStartService.
protected static void initializeAndStartService(CConfiguration cConf) throws Exception {
// TODO: this whole method is a mess. Streamline it!
injector = Guice.createInjector(new ConfigModule(cConf), new DiscoveryRuntimeModule().getInMemoryModules(), new NonCustomLocationUnitTestModule().getModule(), new NamespaceClientRuntimeModule().getInMemoryModules(), new SystemDatasetRuntimeModule().getInMemoryModules(), new TransactionInMemoryModule(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getMasterModule(), new AbstractModule() {
@Override
protected void configure() {
bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class).in(Singleton.class);
install(new FactoryModuleBuilder().implement(DatasetDefinitionRegistry.class, DefaultDatasetDefinitionRegistry.class).build(DatasetDefinitionRegistryFactory.class));
// through the injector, we only need RemoteDatasetFramework in these tests
bind(RemoteDatasetFramework.class);
bind(OwnerStore.class).to(InMemoryOwnerStore.class);
bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
}
});
AuthorizationEnforcer authEnforcer = injector.getInstance(AuthorizationEnforcer.class);
AuthenticationContext authenticationContext = injector.getInstance(AuthenticationContext.class);
DiscoveryService discoveryService = injector.getInstance(DiscoveryService.class);
discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
dsFramework = injector.getInstance(RemoteDatasetFramework.class);
// Tx Manager to support working with datasets
txManager = injector.getInstance(TransactionManager.class);
txManager.startAndWait();
TransactionSystemClient txSystemClient = injector.getInstance(TransactionSystemClient.class);
TransactionSystemClientService txSystemClientService = new DelegatingTransactionSystemClientService(txSystemClient);
NamespacedLocationFactory namespacedLocationFactory = injector.getInstance(NamespacedLocationFactory.class);
SystemDatasetInstantiatorFactory datasetInstantiatorFactory = new SystemDatasetInstantiatorFactory(locationFactory, dsFramework, cConf);
// ok to pass null, since the impersonator won't actually be called, if kerberos security is not enabled
Impersonator impersonator = new DefaultImpersonator(cConf, null);
DatasetAdminService datasetAdminService = new DatasetAdminService(dsFramework, cConf, locationFactory, datasetInstantiatorFactory, new NoOpMetadataStore(), impersonator);
ImmutableSet<HttpHandler> handlers = ImmutableSet.<HttpHandler>of(new DatasetAdminOpHTTPHandler(datasetAdminService));
MetricsCollectionService metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
opExecutorService = new DatasetOpExecutorService(cConf, discoveryService, metricsCollectionService, handlers);
opExecutorService.startAndWait();
Map<String, DatasetModule> defaultModules = injector.getInstance(Key.get(new TypeLiteral<Map<String, DatasetModule>>() {
}, Constants.Dataset.Manager.DefaultDatasetModules.class));
ImmutableMap<String, DatasetModule> modules = ImmutableMap.<String, DatasetModule>builder().putAll(defaultModules).putAll(DatasetMetaTableUtil.getModules()).build();
registryFactory = injector.getInstance(DatasetDefinitionRegistryFactory.class);
inMemoryDatasetFramework = new InMemoryDatasetFramework(registryFactory, modules);
DiscoveryExploreClient exploreClient = new DiscoveryExploreClient(discoveryServiceClient, authenticationContext);
ExploreFacade exploreFacade = new ExploreFacade(exploreClient, cConf);
namespaceAdmin = injector.getInstance(NamespaceAdmin.class);
namespaceAdmin.create(NamespaceMeta.DEFAULT);
ownerAdmin = injector.getInstance(OwnerAdmin.class);
NamespaceQueryAdmin namespaceQueryAdmin = injector.getInstance(NamespaceQueryAdmin.class);
TransactionExecutorFactory txExecutorFactory = new DynamicTransactionExecutorFactory(txSystemClient);
DatasetTypeManager typeManager = new DatasetTypeManager(cConf, locationFactory, txSystemClientService, txExecutorFactory, inMemoryDatasetFramework, impersonator);
DatasetOpExecutor opExecutor = new InMemoryDatasetOpExecutor(dsFramework);
DatasetInstanceManager instanceManager = new DatasetInstanceManager(txSystemClientService, txExecutorFactory, inMemoryDatasetFramework);
PrivilegesManager privilegesManager = injector.getInstance(PrivilegesManager.class);
DatasetTypeService typeService = new DatasetTypeService(typeManager, namespaceAdmin, namespacedLocationFactory, authEnforcer, privilegesManager, authenticationContext, cConf, impersonator, txSystemClientService, inMemoryDatasetFramework, txExecutorFactory, defaultModules);
instanceService = new DatasetInstanceService(typeService, instanceManager, opExecutor, exploreFacade, namespaceQueryAdmin, ownerAdmin, authEnforcer, privilegesManager, authenticationContext);
service = new DatasetService(cConf, discoveryService, discoveryServiceClient, metricsCollectionService, opExecutor, new HashSet<DatasetMetricsReporter>(), typeService, instanceService);
// Start dataset service, wait for it to be discoverable
service.startAndWait();
waitForService(Constants.Service.DATASET_EXECUTOR);
waitForService(Constants.Service.DATASET_MANAGER);
// this usually happens while creating a namespace, however not doing that in data fabric tests
Locations.mkdirsIfNotExists(namespacedLocationFactory.get(NamespaceId.DEFAULT));
}
use of com.google.inject.TypeLiteral in project druid by druid-io.
the class ConditionalMultibindTest method testMultiConditionalBind_typeLiteral.
@Test
public void testMultiConditionalBind_typeLiteral() {
props.setProperty("animal.type", "pets");
final Set<Animal> set1 = ImmutableSet.<Animal>of(new Dog(), new Tiger());
final Set<Animal> set2 = ImmutableSet.<Animal>of(new Cat(), new Fish());
final Set<Animal> set3 = ImmutableSet.<Animal>of(new Cat());
final Set<Animal> union = new HashSet<>();
union.addAll(set1);
union.addAll(set2);
final Zoo<Animal> zoo1 = new Zoo<>(set1);
final Zoo<Animal> zoo2 = new Zoo<>();
Injector injector = Guice.createInjector(new Module() {
@Override
public void configure(Binder binder) {
ConditionalMultibind.create(props, binder, new TypeLiteral<Set<Animal>>() {
}).addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), set1).addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), set2);
ConditionalMultibind.create(props, binder, new TypeLiteral<Zoo<Animal>>() {
}).addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), zoo1);
}
}, new Module() {
@Override
public void configure(Binder binder) {
ConditionalMultibind.create(props, binder, new TypeLiteral<Set<Animal>>() {
}).addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), set3);
ConditionalMultibind.create(props, binder, new TypeLiteral<Set<Animal>>() {
}, SanDiego.class).addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), union);
ConditionalMultibind.create(props, binder, new TypeLiteral<Zoo<Animal>>() {
}).addBinding(new TypeLiteral<Zoo<Animal>>() {
});
}
});
Set<Set<Animal>> actualAnimalSet = injector.getInstance(Key.get(new TypeLiteral<Set<Set<Animal>>>() {
}));
Assert.assertEquals(3, actualAnimalSet.size());
Assert.assertEquals(ImmutableSet.of(set1, set2, set3), actualAnimalSet);
actualAnimalSet = injector.getInstance(Key.get(new TypeLiteral<Set<Set<Animal>>>() {
}, SanDiego.class));
Assert.assertEquals(1, actualAnimalSet.size());
Assert.assertEquals(ImmutableSet.of(union), actualAnimalSet);
final Set<Zoo<Animal>> actualZooSet = injector.getInstance(Key.get(new TypeLiteral<Set<Zoo<Animal>>>() {
}));
Assert.assertEquals(2, actualZooSet.size());
Assert.assertEquals(ImmutableSet.of(zoo1, zoo2), actualZooSet);
}
use of com.google.inject.TypeLiteral in project druid by druid-io.
the class ConditionalMultibindTest method testMultiConditionalBind_multiple_modules.
@Test
public void testMultiConditionalBind_multiple_modules() {
props.setProperty("animal.type", "pets");
Injector injector = Guice.createInjector(new Module() {
@Override
public void configure(Binder binder) {
ConditionalMultibind.create(props, binder, Animal.class).addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), Cat.class).addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), Dog.class);
}
}, new Module() {
@Override
public void configure(Binder binder) {
ConditionalMultibind.create(props, binder, Animal.class).addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("not_match"), Tiger.class).addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), Fish.class);
}
});
Set<Animal> animalSet = injector.getInstance(Key.get(new TypeLiteral<Set<Animal>>() {
}));
Assert.assertEquals(3, animalSet.size());
Assert.assertEquals(animalSet, ImmutableSet.<Animal>of(new Cat(), new Dog(), new Fish()));
}
Aggregations