use of com.google.inject.assistedinject.FactoryModuleBuilder in project cdap by caskdata.
the class PreviewRunnerModule method configure.
@Override
protected void configure() {
bind(ArtifactRepository.class).toInstance(artifactRepository);
expose(ArtifactRepository.class);
bind(ArtifactStore.class).toInstance(artifactStore);
expose(ArtifactStore.class);
bind(AuthorizerInstantiator.class).toInstance(authorizerInstantiator);
expose(AuthorizerInstantiator.class);
bind(AuthorizationEnforcer.class).toInstance(authorizationEnforcer);
expose(AuthorizationEnforcer.class);
bind(PrivilegesManager.class).toInstance(privilegesManager);
expose(PrivilegesManager.class);
bind(StreamConsumerFactory.class).to(InMemoryStreamConsumerFactory.class).in(Scopes.SINGLETON);
expose(StreamConsumerFactory.class);
bind(StreamCoordinatorClient.class).toInstance(streamCoordinatorClient);
expose(StreamCoordinatorClient.class);
bind(PreferencesStore.class).toInstance(preferencesStore);
// bind explore client to mock.
bind(ExploreClient.class).to(MockExploreClient.class);
expose(ExploreClient.class);
bind(StorageProviderNamespaceAdmin.class).to(LocalStorageProviderNamespaceAdmin.class);
bind(PipelineFactory.class).to(SynchronousPipelineFactory.class);
install(new FactoryModuleBuilder().implement(new TypeLiteral<Manager<AppDeploymentInfo, ApplicationWithPrograms>>() {
}, new TypeLiteral<PreviewApplicationManager<AppDeploymentInfo, ApplicationWithPrograms>>() {
}).build(new TypeLiteral<ManagerFactory<AppDeploymentInfo, ApplicationWithPrograms>>() {
}));
bind(Store.class).to(DefaultStore.class);
bind(RouteStore.class).to(LocalRouteStore.class).in(Scopes.SINGLETON);
bind(UGIProvider.class).to(UnsupportedUGIProvider.class);
expose(UGIProvider.class);
bind(RuntimeStore.class).to(DefaultStore.class);
expose(RuntimeStore.class);
// we don't delete namespaces in preview as we just delete preview directory when its done
bind(NamespaceResourceDeleter.class).to(NoopNamespaceResourceDeleter.class).in(Scopes.SINGLETON);
bind(NamespaceAdmin.class).to(DefaultNamespaceAdmin.class).in(Scopes.SINGLETON);
bind(NamespaceQueryAdmin.class).to(DefaultNamespaceAdmin.class).in(Scopes.SINGLETON);
expose(NamespaceAdmin.class);
expose(NamespaceQueryAdmin.class);
bind(PreviewRunner.class).to(DefaultPreviewRunner.class).in(Scopes.SINGLETON);
expose(PreviewRunner.class);
bind(PreviewStore.class).to(DefaultPreviewStore.class).in(Scopes.SINGLETON);
bind(Scheduler.class).to(NoOpScheduler.class);
bind(DataTracerFactory.class).to(DefaultDataTracerFactory.class);
expose(DataTracerFactory.class);
bind(OwnerStore.class).to(DefaultOwnerStore.class);
expose(OwnerStore.class);
bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
expose(OwnerAdmin.class);
}
use of com.google.inject.assistedinject.FactoryModuleBuilder in project joynr by bmwcarit.
the class CppStdTypeUtilTest method setUp.
@Override
protected void setUp() throws Exception {
URL fixtureURL = CppStdTypeUtilTest.class.getResource("CppStdTypeUtil.fidl");
ModelLoader loader = new ModelLoader(fixtureURL.getPath());
Resource fixtureResource = loader.getResources().iterator().next();
cppStdTypeUtil = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Names.named("generationId")).to("");
bindConstant().annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_CLEAN)).to(false);
bindConstant().annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_GENERATE)).to(true);
install(new FactoryModuleBuilder().build(CppTemplateFactory.class));
}
}).getInstance(CppStdTypeUtil.class);
model = (FModel) fixtureResource.getContents().get(0);
}
use of com.google.inject.assistedinject.FactoryModuleBuilder in project joynr by bmwcarit.
the class AbstractRuntimeModule method configure.
@Override
protected void configure() {
requestStaticInjection(CapabilityUtils.class, RpcUtils.class, ArbitratorFactory.class, JoynrDelayMessageException.class, JoynrAppenderManagerFactory.class);
install(new JsonMessageSerializerModule());
install(new FactoryModuleBuilder().implement(ProxyInvocationHandler.class, ProxyInvocationHandlerImpl.class).build(ProxyInvocationHandlerFactory.class));
install(new JoynrMessageScopeModule());
messagingStubFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
}, new TypeLiteral<AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>>() {
}, Names.named(MessagingStubFactory.MIDDLEWARE_MESSAGING_STUB_FACTORIES));
messagingStubFactory.addBinding(InProcessAddress.class).to(InProcessMessagingStubFactory.class);
messagingSkeletonFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
}, new TypeLiteral<IMessagingSkeleton>() {
}, Names.named(MessagingSkeletonFactory.MIDDLEWARE_MESSAGING_SKELETONS));
messagingSkeletonFactory.addBinding(InProcessAddress.class).to(InProcessLibjoynrMessagingSkeleton.class);
// other address types must be added to the Multibinder to support global addressing. Created here to make
// sure the Set exists, even if empty.
Multibinder.newSetBinder(binder(), new TypeLiteral<GlobalAddressFactory<? extends Address>>() {
}, Names.named(GlobalAddressProvider.GLOBAL_ADDRESS_PROVIDER));
Multibinder.newSetBinder(binder(), new TypeLiteral<GlobalAddressFactory<? extends Address>>() {
}, Names.named(ReplyToAddressProvider.REPLY_TO_ADDRESS_PROVIDER));
multicastAddressCalculators = Multibinder.newSetBinder(binder(), new TypeLiteral<MulticastAddressCalculator>() {
});
bind(ProxyBuilderFactory.class).to(ProxyBuilderFactoryImpl.class);
bind(RequestReplyManager.class).to(RequestReplyManagerImpl.class);
bind(SubscriptionManager.class).to(SubscriptionManagerImpl.class);
bind(PublicationManager.class).to(PublicationManagerImpl.class);
bind(Dispatcher.class).to(DispatcherImpl.class);
bind(LocalDiscoveryAggregator.class).in(Singleton.class);
bind(DiscoveryAsync.class).to(LocalDiscoveryAggregator.class);
bind(CapabilitiesRegistrar.class).to(CapabilitiesRegistrarImpl.class);
bind(ParticipantIdStorage.class).to(PropertiesFileParticipantIdStorage.class);
bind(SubscriptionRequestStorage.class).to(FileSubscriptionRequestStorage.class);
bind(MessagingSettings.class).to(ConfigurableMessagingSettings.class);
bind(RoutingTable.class).to(RoutingTableImpl.class).asEagerSingleton();
bind(MulticastReceiverRegistry.class).to(InMemoryMulticastReceiverRegistry.class).asEagerSingleton();
bind(RawMessagingPreprocessor.class).to(NoOpRawMessagingPreprocessor.class);
bind(ScheduledExecutorService.class).annotatedWith(Names.named(MessageRouter.SCHEDULEDTHREADPOOL)).toProvider(DefaultScheduledExecutorServiceProvider.class);
bind(StatusReceiver.class).to(DefaultStatusReceiver.class);
install(new StaticCapabilitiesProvisioningModule());
bind(ScheduledExecutorService.class).annotatedWith(Names.named(JOYNR_SCHEDULER_CLEANUP)).toProvider(DefaultScheduledExecutorServiceProvider.class);
Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
});
}
use of com.google.inject.assistedinject.FactoryModuleBuilder in project joynr by bmwcarit.
the class CompoundTypeGeneratorTest method testRecursiveStruct.
@Test
public void testRecursiveStruct() throws Exception {
FModel model = FrancaFactory.eINSTANCE.createFModel();
FStructType structType = FrancaFactory.eINSTANCE.createFStructType();
FTypeCollection typeCollection = FrancaFactory.eINSTANCE.createFTypeCollection();
typeCollection.getTypes().add(structType);
model.getTypeCollections().add(typeCollection);
structType.setName("TestStruct");
FField field = FrancaFactory.eINSTANCE.createFField();
field.setName("exampleField");
field.setArray(true);
FTypeRef typeRef = FrancaFactory.eINSTANCE.createFTypeRef();
typeRef.setDerived(structType);
field.setType(typeRef);
structType.getElements().add(field);
JsTemplateFactory templateFactory = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(new FactoryModuleBuilder().build(JsTemplateFactory.class));
bind(Boolean.class).annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_GENERATE)).toInstance(true);
bind(Boolean.class).annotatedWith(Names.named(JoynrGeneratorExtensions.JOYNR_GENERATOR_CLEAN)).toInstance(false);
}
}).getInstance(JsTemplateFactory.class);
CompoundTypeGenerator generator = templateFactory.createCompoundTypeGenerator(structType);
generator.generate();
}
use of com.google.inject.assistedinject.FactoryModuleBuilder in project guice by google.
the class SubpackageTest method testNoPrivateFallbackOrWorkaround.
@Test
public void testNoPrivateFallbackOrWorkaround() throws Exception {
setAllowMethodHandleWorkaround(false);
setAllowPrivateLookupFallback(false);
if (JAVA_VERSION > 1.8) {
// Above 1.8 will fail, because they can't access private details w/o the workarounds.
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(new FactoryModuleBuilder().build(ConcreteAssistedWithOverride.Factory.class));
}
});
fail("Expected CreationException");
} catch (CreationException ce) {
assertThat(Iterables.getOnlyElement(ce.getErrorMessages()).getMessage()).contains("Please call FactoryModuleBuilder.withLookups");
}
LogRecord record = Iterables.getOnlyElement(logRecords);
assertThat(record.getMessage()).contains("Please pass a `MethodHandles.lookup()`");
} else {
// 1.8 & below will succeed, because that's the only way they can work.
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(new FactoryModuleBuilder().build(ConcreteAssistedWithOverride.Factory.class));
}
});
LogRecord record = Iterables.getOnlyElement(logRecords);
assertThat(record.getMessage()).contains("Please pass a `MethodHandles.lookup()`");
ConcreteAssistedWithOverride.Factory factory = injector.getInstance(ConcreteAssistedWithOverride.Factory.class);
factory.create("foo");
AbstractAssisted.Factory<ConcreteAssistedWithOverride, String> factoryAbstract = factory;
factoryAbstract.create("foo");
}
}
Aggregations