Search in sources :

Example 66 with FactoryModuleBuilder

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);
}
Also used : ExploreClient(co.cask.cdap.explore.client.ExploreClient) MockExploreClient(co.cask.cdap.explore.client.MockExploreClient) AuthorizerInstantiator(co.cask.cdap.security.authorization.AuthorizerInstantiator) SynchronousPipelineFactory(co.cask.cdap.internal.pipeline.SynchronousPipelineFactory) PipelineFactory(co.cask.cdap.pipeline.PipelineFactory) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) Scheduler(co.cask.cdap.scheduler.Scheduler) NoOpScheduler(co.cask.cdap.scheduler.NoOpScheduler) UGIProvider(co.cask.cdap.security.impersonation.UGIProvider) UnsupportedUGIProvider(co.cask.cdap.security.impersonation.UnsupportedUGIProvider) RuntimeStore(co.cask.cdap.app.store.RuntimeStore) PreferencesStore(co.cask.cdap.config.PreferencesStore) DefaultPreviewStore(co.cask.cdap.internal.app.store.preview.DefaultPreviewStore) PreviewStore(co.cask.cdap.app.store.preview.PreviewStore) Store(co.cask.cdap.app.store.Store) LocalRouteStore(co.cask.cdap.route.store.LocalRouteStore) OwnerStore(co.cask.cdap.security.impersonation.OwnerStore) DefaultOwnerStore(co.cask.cdap.store.DefaultOwnerStore) RouteStore(co.cask.cdap.route.store.RouteStore) RuntimeStore(co.cask.cdap.app.store.RuntimeStore) DefaultStore(co.cask.cdap.internal.app.store.DefaultStore) ArtifactStore(co.cask.cdap.internal.app.runtime.artifact.ArtifactStore) AuthorizationEnforcer(co.cask.cdap.security.spi.authorization.AuthorizationEnforcer) PrivilegesManager(co.cask.cdap.security.spi.authorization.PrivilegesManager) Manager(co.cask.cdap.app.deploy.Manager) DefaultNamespaceAdmin(co.cask.cdap.internal.app.namespace.DefaultNamespaceAdmin) TypeLiteral(com.google.inject.TypeLiteral) AppDeploymentInfo(co.cask.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) StorageProviderNamespaceAdmin(co.cask.cdap.internal.app.namespace.StorageProviderNamespaceAdmin) LocalStorageProviderNamespaceAdmin(co.cask.cdap.internal.app.namespace.LocalStorageProviderNamespaceAdmin) ApplicationWithPrograms(co.cask.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms) PreferencesStore(co.cask.cdap.config.PreferencesStore) LocalRouteStore(co.cask.cdap.route.store.LocalRouteStore) NoopNamespaceResourceDeleter(co.cask.cdap.internal.app.namespace.NoopNamespaceResourceDeleter) DefaultPreviewStore(co.cask.cdap.internal.app.store.preview.DefaultPreviewStore) DefaultOwnerAdmin(co.cask.cdap.security.impersonation.DefaultOwnerAdmin) OwnerAdmin(co.cask.cdap.security.impersonation.OwnerAdmin) PrivilegesManager(co.cask.cdap.security.spi.authorization.PrivilegesManager) StreamCoordinatorClient(co.cask.cdap.data.stream.StreamCoordinatorClient) ArtifactRepository(co.cask.cdap.internal.app.runtime.artifact.ArtifactRepository) OwnerStore(co.cask.cdap.security.impersonation.OwnerStore) DefaultOwnerStore(co.cask.cdap.store.DefaultOwnerStore) ArtifactStore(co.cask.cdap.internal.app.runtime.artifact.ArtifactStore) InMemoryStreamConsumerFactory(co.cask.cdap.data2.transaction.stream.inmemory.InMemoryStreamConsumerFactory) DefaultPreviewRunner(co.cask.cdap.internal.app.preview.DefaultPreviewRunner) DefaultDataTracerFactory(co.cask.cdap.internal.app.preview.DefaultDataTracerFactory)

Example 67 with FactoryModuleBuilder

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);
}
Also used : ModelLoader(io.joynr.generator.loading.ModelLoader) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) Resource(org.eclipse.emf.ecore.resource.Resource) URL(java.net.URL) AbstractModule(com.google.inject.AbstractModule)

Example 68 with FactoryModuleBuilder

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>() {
    });
}
Also used : PublicationManager(io.joynr.dispatching.subscription.PublicationManager) FileSubscriptionRequestStorage(io.joynr.dispatching.subscription.FileSubscriptionRequestStorage) SubscriptionRequestStorage(io.joynr.dispatching.subscription.SubscriptionRequestStorage) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) Address(joynr.system.RoutingTypes.Address) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) GlobalAddressFactory(io.joynr.messaging.routing.GlobalAddressFactory) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) PropertiesFileParticipantIdStorage(io.joynr.capabilities.PropertiesFileParticipantIdStorage) ParticipantIdStorage(io.joynr.capabilities.ParticipantIdStorage) SubscriptionManager(io.joynr.dispatching.subscription.SubscriptionManager) Dispatcher(io.joynr.dispatching.Dispatcher) NoOpRawMessagingPreprocessor(io.joynr.messaging.NoOpRawMessagingPreprocessor) RawMessagingPreprocessor(io.joynr.messaging.RawMessagingPreprocessor) StatusReceiver(io.joynr.statusmetrics.StatusReceiver) DefaultStatusReceiver(io.joynr.statusmetrics.DefaultStatusReceiver) MessagingSettings(io.joynr.messaging.MessagingSettings) ConfigurableMessagingSettings(io.joynr.messaging.ConfigurableMessagingSettings) TypeLiteral(com.google.inject.TypeLiteral) RequestReplyManager(io.joynr.dispatching.RequestReplyManager) ProxyInvocationHandlerFactory(io.joynr.proxy.ProxyInvocationHandlerFactory) RoutingTableImpl(io.joynr.messaging.routing.RoutingTableImpl) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) DiscoveryAsync(joynr.system.DiscoveryAsync) CapabilitiesRegistrar(io.joynr.capabilities.CapabilitiesRegistrar) StaticCapabilitiesProvisioningModule(io.joynr.capabilities.StaticCapabilitiesProvisioningModule) InMemoryMulticastReceiverRegistry(io.joynr.messaging.routing.InMemoryMulticastReceiverRegistry) ProxyBuilderFactory(io.joynr.proxy.ProxyBuilderFactory) JoynrMessageScopeModule(io.joynr.context.JoynrMessageScopeModule) LocalDiscoveryAggregator(io.joynr.discovery.LocalDiscoveryAggregator)

Example 69 with FactoryModuleBuilder

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();
}
Also used : FStructType(org.franca.core.franca.FStructType) FTypeRef(org.franca.core.franca.FTypeRef) FTypeCollection(org.franca.core.franca.FTypeCollection) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) FModel(org.franca.core.franca.FModel) JsTemplateFactory(io.joynr.generator.js.util.JsTemplateFactory) FField(org.franca.core.franca.FField) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 70 with FactoryModuleBuilder

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");
    }
}
Also used : LogRecord(java.util.logging.LogRecord) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) Injector(com.google.inject.Injector) CreationException(com.google.inject.CreationException) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Aggregations

FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)85 AbstractModule (com.google.inject.AbstractModule)20 Injector (com.google.inject.Injector)12 ConfigModule (co.cask.cdap.common.guice.ConfigModule)10 PrivateModule (com.google.inject.PrivateModule)10 DatasetDefinitionRegistry (co.cask.cdap.api.dataset.module.DatasetDefinitionRegistry)8 DefaultDatasetDefinitionRegistry (co.cask.cdap.data2.dataset2.DefaultDatasetDefinitionRegistry)8 InMemoryDatasetFramework (co.cask.cdap.data2.dataset2.InMemoryDatasetFramework)8 TypeLiteral (com.google.inject.TypeLiteral)8 DatasetFramework (co.cask.cdap.data2.dataset2.DatasetFramework)7 DiscoveryRuntimeModule (co.cask.cdap.common.guice.DiscoveryRuntimeModule)6 LocationRuntimeModule (co.cask.cdap.common.guice.LocationRuntimeModule)6 SystemDatasetRuntimeModule (co.cask.cdap.data.runtime.SystemDatasetRuntimeModule)6 DatasetOpExecutor (co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor)6 DatasetDefinitionRegistryFactory (co.cask.cdap.data2.dataset2.DatasetDefinitionRegistryFactory)6 Singleton (com.google.inject.Singleton)6 TransactionManager (org.apache.tephra.TransactionManager)6 DatasetService (co.cask.cdap.data2.datafabric.dataset.service.DatasetService)5 DatasetAdminOpHTTPHandler (co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetAdminOpHTTPHandler)5 CConfiguration (co.cask.cdap.common.conf.CConfiguration)4