Search in sources :

Example 1 with JoynrMessageScopeModule

use of io.joynr.context.JoynrMessageScopeModule 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 2 with JoynrMessageScopeModule

use of io.joynr.context.JoynrMessageScopeModule in project joynr by bmwcarit.

the class RpcStubbingTest method setUp.

@Before
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "NP_NULL_PARAM_DEREF", justification = "NPE in test would fail test")
public void setUp() throws JoynrCommunicationException, JoynrSendBufferFullException, JsonGenerationException, JsonMappingException, IOException, JoynrMessageNotSentException {
    Deferred<GpsLocation> deferredGpsLocation = new Deferred<GpsLocation>();
    deferredGpsLocation.resolve(gpsValue);
    when(testMock.returnsGpsLocation()).thenReturn(new Promise<Deferred<GpsLocation>>(deferredGpsLocation));
    Deferred<List<GpsLocation>> deferredGpsLocationList = new Deferred<List<GpsLocation>>();
    deferredGpsLocationList.resolve(gpsList);
    when(testMock.returnsGpsLocationList()).thenReturn(new Promise<Deferred<List<GpsLocation>>>(deferredGpsLocationList));
    DeferredVoid deferredVoid = new DeferredVoid();
    deferredVoid.resolve();
    when(testMock.noParamsNoReturnValue()).thenReturn(new Promise<DeferredVoid>(deferredVoid));
    when(testMock.takesTwoSimpleParams(any(Integer.class), any(String.class))).thenReturn(new Promise<DeferredVoid>(deferredVoid));
    fromParticipantId = UUID.randomUUID().toString();
    toParticipantId = UUID.randomUUID().toString();
    toDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
    toDiscoveryEntry.setParticipantId(toParticipantId);
    // required to inject static members of JoynMessagingConnectorFactory
    injector = Guice.createInjector(new JoynrPropertiesModule(PropertyLoader.loadProperties(MessagingPropertyKeys.DEFAULT_MESSAGING_PROPERTIES_FILE)), new JsonMessageSerializerModule(), new AbstractModule() {

        @Override
        protected void configure() {
            requestStaticInjection(RpcUtils.class);
            install(new JoynrMessageScopeModule());
            MapBinder<Class<? extends Address>, AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>> messagingStubFactory;
            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);
        }
    });
    final RequestInterpreter requestInterpreter = injector.getInstance(RequestInterpreter.class);
    final RequestCallerFactory requestCallerFactory = injector.getInstance(RequestCallerFactory.class);
    when(requestReplyManager.sendSyncRequest(eq(fromParticipantId), eq(toDiscoveryEntry), any(Request.class), any(SynchronizedReplyCaller.class), eq(messagingQos))).thenAnswer(new Answer<Reply>() {

        @Override
        public Reply answer(InvocationOnMock invocation) throws Throwable {
            RequestCaller requestCaller = requestCallerFactory.create(testMock);
            Object[] args = invocation.getArguments();
            Request request = null;
            for (Object arg : args) {
                if (arg instanceof Request) {
                    request = (Request) arg;
                    break;
                }
            }
            final Future<Reply> future = new Future<Reply>();
            ProviderCallback<Reply> callback = new ProviderCallback<Reply>() {

                @Override
                public void onSuccess(Reply result) {
                    future.onSuccess(result);
                }

                @Override
                public void onFailure(JoynrException error) {
                    future.onFailure(error);
                }
            };
            requestInterpreter.execute(callback, requestCaller, request);
            return future.get();
        }
    });
    JoynrMessagingConnectorFactory joynrMessagingConnectorFactory = new JoynrMessagingConnectorFactory(requestReplyManager, replyCallerDirectory, subscriptionManager);
    connector = joynrMessagingConnectorFactory.create(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), messagingQos);
}
Also used : InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) Address(joynr.system.RoutingTypes.Address) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) Deferred(io.joynr.provider.Deferred) DeferredVoid(io.joynr.provider.DeferredVoid) TypeLiteral(com.google.inject.TypeLiteral) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) List(java.util.List) ProviderCallback(io.joynr.provider.ProviderCallback) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) Request(joynr.Request) GpsLocation(joynr.types.Localisation.GpsLocation) JoynrException(io.joynr.exceptions.JoynrException) AbstractModule(com.google.inject.AbstractModule) JoynrMessageScopeModule(io.joynr.context.JoynrMessageScopeModule) RequestCaller(io.joynr.dispatching.RequestCaller) AbstractMiddlewareMessagingStubFactory(io.joynr.messaging.AbstractMiddlewareMessagingStubFactory) RequestInterpreter(io.joynr.dispatching.rpc.RequestInterpreter) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Reply(joynr.Reply) IMessagingStub(io.joynr.messaging.IMessagingStub) SynchronizedReplyCaller(io.joynr.dispatching.rpc.SynchronizedReplyCaller) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) RequestCallerFactory(io.joynr.dispatching.RequestCallerFactory) Before(org.junit.Before)

Example 3 with JoynrMessageScopeModule

use of io.joynr.context.JoynrMessageScopeModule 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)

Aggregations

TypeLiteral (com.google.inject.TypeLiteral)3 JoynrMessageScopeModule (io.joynr.context.JoynrMessageScopeModule)3 AbstractModule (com.google.inject.AbstractModule)2 JsonMessageSerializerModule (io.joynr.messaging.JsonMessageSerializerModule)2 InProcessAddress (io.joynr.messaging.inprocess.InProcessAddress)2 Address (joynr.system.RoutingTypes.Address)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 Injector (com.google.inject.Injector)1 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)1 CapabilitiesRegistrar (io.joynr.capabilities.CapabilitiesRegistrar)1 ParticipantIdStorage (io.joynr.capabilities.ParticipantIdStorage)1 PropertiesFileParticipantIdStorage (io.joynr.capabilities.PropertiesFileParticipantIdStorage)1 StaticCapabilitiesProvisioningModule (io.joynr.capabilities.StaticCapabilitiesProvisioningModule)1 JoynrPropertiesModule (io.joynr.common.JoynrPropertiesModule)1 LocalDiscoveryAggregator (io.joynr.discovery.LocalDiscoveryAggregator)1 Dispatcher (io.joynr.dispatching.Dispatcher)1 RequestCaller (io.joynr.dispatching.RequestCaller)1 RequestCallerFactory (io.joynr.dispatching.RequestCallerFactory)1 RequestReplyManager (io.joynr.dispatching.RequestReplyManager)1