use of com.google.inject.multibindings.Multibinder in project joynr by bmwcarit.
the class TtlUpliftTest method setUp.
@Before
public void setUp() throws NoSuchMethodException, SecurityException {
fromParticipantId = "sender";
toParticipantId = "receiver";
cleanupScheduler = new ScheduledThreadPoolExecutor(1);
cleanupSchedulerSpy = Mockito.spy(cleanupScheduler);
Module defaultModule = Modules.override(new JoynrPropertiesModule(new Properties())).with(new JsonMessageSerializerModule(), new AbstractModule() {
@Override
protected void configure() {
bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_TTL_UPLIFT_MS)).toInstance(NO_TTL_UPLIFT);
requestStaticInjection(Request.class);
Multibinder<JoynrMessageProcessor> joynrMessageProcessorMultibinder = Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
});
joynrMessageProcessorMultibinder.addBinding().toInstance(new JoynrMessageProcessor() {
@Override
public MutableMessage processOutgoing(MutableMessage joynrMessage) {
return joynrMessage;
}
@Override
public ImmutableMessage processIncoming(ImmutableMessage joynrMessage) {
return joynrMessage;
}
});
bind(PublicationManager.class).to(PublicationManagerImpl.class);
bind(SubscriptionRequestStorage.class).toInstance(Mockito.mock(FileSubscriptionRequestStorage.class));
bind(AttributePollInterpreter.class).toInstance(attributePollInterpreter);
bind(Dispatcher.class).toInstance(dispatcher);
bind(ProviderDirectory.class).toInstance(providerDirectory);
bind(ScheduledExecutorService.class).annotatedWith(Names.named(JoynrInjectionConstants.JOYNR_SCHEDULER_CLEANUP)).toInstance(cleanupSchedulerSpy);
}
});
Injector injector = Guice.createInjector(defaultModule);
messageFactory = injector.getInstance(MutableMessageFactory.class);
Module ttlUpliftModule = Modules.override(defaultModule).with(new AbstractModule() {
@Override
protected void configure() {
bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_TTL_UPLIFT_MS)).toInstance(TTL_UPLIFT_MS);
}
});
Injector injectorWithTtlUplift = Guice.createInjector(ttlUpliftModule);
messageFactoryWithTtlUplift = injectorWithTtlUplift.getInstance(MutableMessageFactory.class);
requestCaller = new RequestCallerFactory().create(provider);
when(providerContainer.getProviderProxy()).thenReturn(requestCaller.getProxy());
when(providerContainer.getSubscriptionPublisher()).thenReturn(subscriptionPublisher);
Deferred<String> valueToPublishDeferred = new Deferred<String>();
valueToPublishDeferred.resolve(valueToPublish);
Promise<Deferred<String>> valueToPublishPromise = new Promise<Deferred<String>>(valueToPublishDeferred);
doReturn(valueToPublishPromise).when(attributePollInterpreter).execute(any(ProviderContainer.class), any(Method.class));
Module subcriptionUpliftModule = Modules.override(defaultModule).with(new AbstractModule() {
@Override
protected void configure() {
bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_TTL_UPLIFT_MS)).toInstance(SUBSCRIPTION_UPLIFT_MS);
}
});
Injector injectorWithPublicationUplift = Guice.createInjector(subcriptionUpliftModule);
publicationManager = (PublicationManagerImpl) injector.getInstance(PublicationManager.class);
publicationManagerWithTtlUplift = (PublicationManagerImpl) injectorWithPublicationUplift.getInstance(PublicationManager.class);
payload = "payload";
Method method = TestProvider.class.getMethod("methodWithStrings", new Class[] { String.class });
request = new Request(method.getName(), new String[] { payload }, method.getParameterTypes());
messagingQos = new MessagingQos(TTL);
expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
}
use of com.google.inject.multibindings.Multibinder 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);
bind(DatasetTypeService.class).annotatedWith(Names.named(NOAUTH_DATASET_TYPE_SERVICE)).to(DefaultDatasetTypeService.class);
bind(DatasetTypeService.class).to(AuthorizationDatasetTypeService.class);
expose(DatasetTypeService.class);
}
});
}
};
}
use of com.google.inject.multibindings.Multibinder in project cdap by caskdata.
the class DataSetServiceModules method getStandaloneModules.
@Override
public Module getStandaloneModules() {
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().getStandaloneModules());
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(LevelDBDatasetMetricsReporter.class);
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(LocalDatasetOpExecutor.class);
expose(DatasetOpExecutor.class);
bind(DatasetTypeService.class).annotatedWith(Names.named(NOAUTH_DATASET_TYPE_SERVICE)).to(DefaultDatasetTypeService.class);
bind(DatasetTypeService.class).to(AuthorizationDatasetTypeService.class);
expose(DatasetTypeService.class);
}
});
}
};
}
use of com.google.inject.multibindings.Multibinder in project cdap by caskdata.
the class BaseHiveExploreServiceTest method createInMemoryModules.
private static List<Module> createInMemoryModules(CConfiguration configuration, Configuration hConf, TemporaryFolder tmpFolder) throws IOException {
configuration.set(Constants.CFG_DATA_INMEMORY_PERSISTENCE, Constants.InMemoryPersistenceType.MEMORY.name());
configuration.set(Constants.CFG_LOCAL_DATA_DIR, tmpFolder.newFolder().getAbsolutePath());
configuration.set(Constants.Explore.LOCAL_DATA_DIR, tmpFolder.newFolder("hive").getAbsolutePath());
configuration.set(TxConstants.Manager.CFG_TX_SNAPSHOT_LOCAL_DIR, tmpFolder.newFolder("tx").getAbsolutePath());
configuration.setBoolean(TxConstants.Manager.CFG_DO_PERSIST, true);
return ImmutableList.of(new ConfigModule(configuration, hConf), new IOModule(), new DiscoveryRuntimeModule().getInMemoryModules(), new NonCustomLocationUnitTestModule().getModule(), new DataSetsModules().getStandaloneModules(), new DataSetServiceModules().getInMemoryModules(), new MetricsClientRuntimeModule().getInMemoryModules(), new ExploreRuntimeModule().getInMemoryModules(), new ExploreClientModule(), new StreamServiceRuntimeModule().getInMemoryModules(), new ViewAdminModules().getInMemoryModules(), new StreamAdminModules().getInMemoryModules(), new NotificationServiceRuntimeModule().getInMemoryModules(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getMasterModule(), new NamespaceClientUnitTestModule().getModule(), new AbstractModule() {
@Override
protected void configure() {
bind(NotificationFeedManager.class).to(NoOpNotificationFeedManager.class);
bind(UGIProvider.class).to(UnsupportedUGIProvider.class);
bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
Multibinder<HttpHandler> handlerBinder = Multibinder.newSetBinder(binder(), HttpHandler.class, Names.named(Constants.Stream.STREAM_HANDLER));
handlerBinder.addBinding().to(StreamHandler.class);
handlerBinder.addBinding().to(StreamFetchHandler.class);
handlerBinder.addBinding().to(StreamViewHttpHandler.class);
CommonHandlers.add(handlerBinder);
bind(StreamHttpService.class).in(Scopes.SINGLETON);
// Use LocalFileTransactionStateStorage, so that we can use transaction snapshots for assertions in test
install(Modules.override(new DataFabricModules().getInMemoryModules()).with(new AbstractModule() {
@Override
protected void configure() {
bind(TransactionStateStorage.class).annotatedWith(Names.named("persist")).to(LocalFileTransactionStateStorage.class).in(Scopes.SINGLETON);
bind(TransactionStateStorage.class).toProvider(TransactionStateStorageProvider.class).in(Singleton.class);
}
}));
}
});
}
use of com.google.inject.multibindings.Multibinder in project cdap by caskdata.
the class BaseHiveExploreServiceTest method createStandaloneModules.
// these are needed if we actually want to query streams, as the stream input format looks at the filesystem
// to figure out splits.
private static List<Module> createStandaloneModules(CConfiguration cConf, Configuration hConf, TemporaryFolder tmpFolder) throws IOException {
File localDataDir = tmpFolder.newFolder();
cConf.set(Constants.CFG_LOCAL_DATA_DIR, localDataDir.getAbsolutePath());
cConf.set(Constants.CFG_DATA_INMEMORY_PERSISTENCE, Constants.InMemoryPersistenceType.LEVELDB.name());
cConf.set(Constants.Explore.LOCAL_DATA_DIR, tmpFolder.newFolder("hive").getAbsolutePath());
hConf.set(Constants.CFG_LOCAL_DATA_DIR, localDataDir.getAbsolutePath());
hConf.set(Constants.AppFabric.OUTPUT_DIR, cConf.get(Constants.AppFabric.OUTPUT_DIR));
hConf.set("hadoop.tmp.dir", new File(localDataDir, cConf.get(Constants.AppFabric.TEMP_DIR)).getAbsolutePath());
return ImmutableList.of(new ConfigModule(cConf, hConf), new IOModule(), new DiscoveryRuntimeModule().getStandaloneModules(), new NonCustomLocationUnitTestModule().getModule(), new DataFabricModules().getStandaloneModules(), new DataSetsModules().getStandaloneModules(), new DataSetServiceModules().getStandaloneModules(), new MetricsClientRuntimeModule().getStandaloneModules(), new ExploreRuntimeModule().getStandaloneModules(), new ExploreClientModule(), new StreamServiceRuntimeModule().getStandaloneModules(), new ViewAdminModules().getStandaloneModules(), new StreamAdminModules().getStandaloneModules(), new NotificationServiceRuntimeModule().getStandaloneModules(), // unit tests. Since this explore standalone module needs persistent of files this should not affect the tests.
new NamespaceClientRuntimeModule().getInMemoryModules(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getMasterModule(), new AbstractModule() {
@Override
protected void configure() {
bind(NotificationFeedManager.class).to(NoOpNotificationFeedManager.class);
bind(UGIProvider.class).to(UnsupportedUGIProvider.class);
Multibinder<HttpHandler> handlerBinder = Multibinder.newSetBinder(binder(), HttpHandler.class, Names.named(Constants.Stream.STREAM_HANDLER));
handlerBinder.addBinding().to(StreamHandler.class);
handlerBinder.addBinding().to(StreamFetchHandler.class);
CommonHandlers.add(handlerBinder);
bind(StreamHttpService.class).in(Scopes.SINGLETON);
bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
}
});
}
Aggregations