Search in sources :

Example 21 with TypeLiteral

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

the class JeeHttpMessagingModule method configure.

@Override
protected void configure() {
    messagingSkeletonFactory.addBinding(ChannelAddress.class).to(ChannelMessagingSkeleton.class);
    messagingStubFactory.addBinding(ChannelAddress.class).to(ChannelMessagingStubFactory.class);
    Multibinder<GlobalAddressFactory<? extends Address>> globalAddresses;
    globalAddresses = Multibinder.newSetBinder(binder(), new TypeLiteral<GlobalAddressFactory<? extends Address>>() {
    }, Names.named(GlobalAddressProvider.GLOBAL_ADDRESS_PROVIDER));
    globalAddresses.addBinding().to(ServletHttpGlobalAddressFactory.class);
    Multibinder<GlobalAddressFactory<? extends Address>> replyToAddresses;
    replyToAddresses = Multibinder.newSetBinder(binder(), new TypeLiteral<GlobalAddressFactory<? extends Address>>() {
    }, Names.named(ReplyToAddressProvider.REPLY_TO_ADDRESS_PROVIDER));
    replyToAddresses.addBinding().to(ServletHttpGlobalAddressFactory.class);
    install(new AccessControlClientModule());
    bind(RequestConfig.class).toProvider(HttpDefaultRequestConfigProvider.class).in(Singleton.class);
    bind(CloseableHttpClient.class).toProvider(HttpClientProvider.class).in(Singleton.class);
    bind(HttpRequestFactory.class).to(ApacheHttpRequestFactory.class);
    bind(MessageRouter.class).to(CcMessageRouter.class).in(Singleton.class);
    bind(MessageSender.class).to(CcMessageSender.class);
    bind(MessageReceiver.class).to(JeeServletMessageReceiver.class);
    bind(ServletMessageReceiver.class).to(JeeServletMessageReceiver.class);
}
Also used : ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) Address(joynr.system.RoutingTypes.Address) HttpRequestFactory(io.joynr.messaging.http.operation.HttpRequestFactory) ApacheHttpRequestFactory(io.joynr.messaging.http.operation.ApacheHttpRequestFactory) MessageSender(io.joynr.messaging.sender.MessageSender) CcMessageSender(io.joynr.messaging.sender.CcMessageSender) ServletHttpGlobalAddressFactory(io.joynr.messaging.http.ServletHttpGlobalAddressFactory) GlobalAddressFactory(io.joynr.messaging.routing.GlobalAddressFactory) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) ServletMessageReceiver(io.joynr.dispatcher.ServletMessageReceiver) HttpDefaultRequestConfigProvider(io.joynr.messaging.http.operation.HttpDefaultRequestConfigProvider) TypeLiteral(com.google.inject.TypeLiteral) HttpClientProvider(io.joynr.messaging.http.operation.HttpClientProvider) ServletMessageReceiver(io.joynr.dispatcher.ServletMessageReceiver) MessageReceiver(io.joynr.messaging.MessageReceiver) CcMessageRouter(io.joynr.messaging.routing.CcMessageRouter) AccessControlClientModule(io.joynr.accesscontrol.AccessControlClientModule)

Example 22 with TypeLiteral

use of com.google.inject.TypeLiteral 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());
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Deferred(io.joynr.provider.Deferred) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) Properties(java.util.Properties) MessagingQos(io.joynr.messaging.MessagingQos) TypeLiteral(com.google.inject.TypeLiteral) MutableMessage(joynr.MutableMessage) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) Injector(com.google.inject.Injector) PublicationManagerImpl(io.joynr.dispatching.subscription.PublicationManagerImpl) ProviderContainer(io.joynr.provider.ProviderContainer) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Multibinder(com.google.inject.multibindings.Multibinder) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) SubscriptionRequest(joynr.SubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) Request(joynr.Request) Method(java.lang.reflect.Method) AbstractModule(com.google.inject.AbstractModule) Promise(io.joynr.provider.Promise) ImmutableMessage(joynr.ImmutableMessage) Matchers.anyLong(org.mockito.Matchers.anyLong) Module(com.google.inject.Module) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) AbstractModule(com.google.inject.AbstractModule) Before(org.junit.Before)

Example 23 with TypeLiteral

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

the class DispatcherImplTest method setUp.

@Before
public void setUp() throws NoSuchMethodException, SecurityException {
    Injector injector = Guice.createInjector(new JsonMessageSerializerModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(Dispatcher.class).to(DispatcherImpl.class);
            bind(RequestReplyManager.class).toInstance(requestReplyManagerMock);
            bind(SubscriptionManager.class).toInstance(subscriptionManagerMock);
            bind(PublicationManager.class).toInstance(publicationManagerMock);
            bind(MessageSender.class).toInstance(messageSenderMock);
            bind(MessageRouter.class).toInstance(messageRouterMock);
            bind(MessageReceiver.class).toInstance(messageReceiverMock);
            Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
            });
            requestStaticInjection(RpcUtils.class, Request.class, JoynrMessagingConnectorFactory.class);
            ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("joynr.Cleanup-%d").build();
            ScheduledExecutorService cleanupExecutor = Executors.newSingleThreadScheduledExecutor(namedThreadFactory);
            bind(ScheduledExecutorService.class).annotatedWith(Names.named(JOYNR_SCHEDULER_CLEANUP)).toInstance(cleanupExecutor);
        }
    });
    fixture = injector.getInstance(Dispatcher.class);
    messageReceiverMock.start(fixture, new ReceiverStatusListener() {

        @Override
        public void receiverStarted() {
        }

        @Override
        public void receiverException(Throwable e) {
        }
    });
    requestCallerDirectory = injector.getInstance(ProviderDirectory.class);
    messageFactory = injector.getInstance(MutableMessageFactory.class);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) RpcUtils(io.joynr.dispatching.rpc.RpcUtils) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) OneWayRequest(joynr.OneWayRequest) SubscriptionRequest(joynr.SubscriptionRequest) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) Request(joynr.Request) ReceiverStatusListener(io.joynr.messaging.ReceiverStatusListener) AbstractModule(com.google.inject.AbstractModule) TypeLiteral(com.google.inject.TypeLiteral) Injector(com.google.inject.Injector) JoynrMessagingConnectorFactory(io.joynr.proxy.JoynrMessagingConnectorFactory) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Before(org.junit.Before)

Example 24 with TypeLiteral

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

the class RequestReplyManagerTest method setUp.

@Before
public void setUp() throws NoSuchMethodException, SecurityException, JsonGenerationException, IOException {
    requestCallerFactory = new RequestCallerFactory();
    testOneWayRecipientParticipantId = "testOneWayRecipientParticipantId";
    testOneWayRecipientDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
    testOneWayRecipientDiscoveryEntry.setParticipantId(testOneWayRecipientParticipantId);
    testOneWayRecipientDiscoveryEntries = Sets.newHashSet(testOneWayRecipientDiscoveryEntry);
    testMessageResponderParticipantId = "testMessageResponderParticipantId";
    testMessageResponderDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
    testMessageResponderDiscoveryEntry.setParticipantId(testMessageResponderParticipantId);
    testSenderParticipantId = "testSenderParticipantId";
    testResponderUnregisteredParticipantId = "testResponderUnregisteredParticipantId";
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            install(new JoynrMessageScopeModule());
            bind(MessageSender.class).toInstance(messageSenderMock);
            bind(MessageRouter.class).toInstance(messageRouterMock);
            bind(RequestReplyManager.class).to(RequestReplyManagerImpl.class);
            requestStaticInjection(RpcUtils.class, Request.class, JoynrMessagingConnectorFactory.class);
            ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("joynr.Cleanup-%d").build();
            ScheduledExecutorService cleanupExecutor = Executors.newSingleThreadScheduledExecutor(namedThreadFactory);
            bind(ScheduledExecutorService.class).annotatedWith(Names.named(JOYNR_SCHEDULER_CLEANUP)).toInstance(cleanupExecutor);
            Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
            });
        }
    });
    objectMapper = injector.getInstance(ObjectMapper.class);
    objectMapper.registerSubtypes(Request.class, OneWayRequest.class);
    requestReplyManager = injector.getInstance(RequestReplyManager.class);
    providerDirectory = injector.getInstance(ProviderDirectory.class);
    replyCallerDirectory = injector.getInstance(ReplyCallerDirectory.class);
    requestReplyManager = injector.getInstance(RequestReplyManager.class);
    // dispatcher.addListener(testOneWayRecipientParticipantId, testListener);
    // jsonRequestString1 = "{\"_typeName\":\"Request\", \"methodName\":\"respond\",\"params\":{\"payload\": \""
    // + payload1 + "\"}}";
    // jsonRequestString2 = "{\"_typeName\":\"Request\", \"methodName\":\"respond\",\"params\":{\"payload\": \""
    // + payload2 + "\"}}";
    Object[] params1 = new Object[] { payload1 };
    Object[] params2 = new Object[] { payload2 };
    // MethodMetaInformation methodMetaInformation = new
    // MethodMetaInformation(TestRequestCaller.class.getMethod("respond", new Class[]{ Object.class }));
    Method method = TestProvider.class.getMethod("methodWithStrings", new Class[] { String.class });
    request1 = new Request(method.getName(), params1, method.getParameterTypes());
    request2 = new Request(method.getName(), params2, method.getParameterTypes());
    request3 = new Request("unknownMethodName", params2, method.getParameterTypes());
    Method fireAndForgetMethod = TestOneWayRecipient.class.getMethod("fireAndForgetMethod", new Class[] { String.class });
    oneWay1 = new OneWayRequest(fireAndForgetMethod.getName(), new Object[] { payload1 }, fireAndForgetMethod.getParameterTypes());
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) RpcUtils(io.joynr.dispatching.rpc.RpcUtils) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) OneWayRequest(joynr.OneWayRequest) Request(joynr.Request) Method(java.lang.reflect.Method) AbstractModule(com.google.inject.AbstractModule) JoynrMessageScopeModule(io.joynr.context.JoynrMessageScopeModule) OneWayRequest(joynr.OneWayRequest) TypeLiteral(com.google.inject.TypeLiteral) ReplyCallerDirectory(io.joynr.dispatching.rpc.ReplyCallerDirectory) Injector(com.google.inject.Injector) JoynrMessagingConnectorFactory(io.joynr.proxy.JoynrMessagingConnectorFactory) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 25 with TypeLiteral

use of com.google.inject.TypeLiteral in project LanternServer by LanternPowered.

the class LanternModule method bindService.

private <T> void bindService(Class<T> clazz) {
    final TypeToken<Service<T>> token = new TypeToken<Service<T>>() {
    }.where(new TypeParameter<T>() {
    }, clazz);
    final TypeLiteral literal = TypeLiteral.get(token.getType());
    // noinspection unchecked
    bindAndExpose(literal).toProvider(ServiceObjectProvider.class);
}
Also used : TypeLiteral(com.google.inject.TypeLiteral) PermissionService(org.spongepowered.api.service.permission.PermissionService) RconService(org.spongepowered.api.service.rcon.RconService) SqlService(org.spongepowered.api.service.sql.SqlService) WhitelistService(org.spongepowered.api.service.whitelist.WhitelistService) BanService(org.spongepowered.api.service.ban.BanService) UserStorageService(org.spongepowered.api.service.user.UserStorageService) SpongeExecutorService(org.spongepowered.api.scheduler.SpongeExecutorService) PaginationService(org.spongepowered.api.service.pagination.PaginationService)

Aggregations

TypeLiteral (com.google.inject.TypeLiteral)195 Injector (com.google.inject.Injector)69 AbstractModule (com.google.inject.AbstractModule)56 Module (com.google.inject.Module)29 Test (org.junit.Test)28 Binder (com.google.inject.Binder)20 Key (com.google.inject.Key)18 Map (java.util.Map)18 Set (java.util.Set)18 Method (java.lang.reflect.Method)15 ParameterizedType (java.lang.reflect.ParameterizedType)15 ImmutableSet (com.google.common.collect.ImmutableSet)14 InjectionPoint (com.google.inject.spi.InjectionPoint)14 Provider (com.google.inject.Provider)12 Annotation (java.lang.annotation.Annotation)12 List (java.util.List)12 Type (java.lang.reflect.Type)11 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)11