Search in sources :

Example 1 with JoynrMessageProcessor

use of io.joynr.messaging.JoynrMessageProcessor in project joynr by bmwcarit.

the class ChannelMessagingSkeleton method forwardMessage.

private void forwardMessage(ImmutableMessage message, FailureAction failureAction) {
    if (messageProcessors != null) {
        for (JoynrMessageProcessor processor : messageProcessors) {
            message = processor.processIncoming(message);
        }
    }
    logger.debug("<<< INCOMING <<< {}", message);
    try {
        message.setReceivedFromGlobal(true);
        messageRouter.route(message);
    } catch (Exception exception) {
        logger.error("Error processing incoming message. Message will be dropped: {} ", exception);
        failureAction.execute(exception);
    }
}
Also used : JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor)

Example 2 with JoynrMessageProcessor

use of io.joynr.messaging.JoynrMessageProcessor 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 3 with JoynrMessageProcessor

use of io.joynr.messaging.JoynrMessageProcessor in project joynr by bmwcarit.

the class WebSocketTest method testJoynrMessageProcessorIsCalled.

@Test
public void testJoynrMessageProcessorIsCalled() throws Throwable {
    JoynrMessageProcessor processorMock = mock(JoynrMessageProcessor.class);
    when(processorMock.processIncoming(any(ImmutableMessage.class))).then(returnsFirstArg());
    int millis = 1000;
    int maxMessageSize = 100000;
    long reconnectDelay = 100;
    long websocketIdleTimeout = millis - 100;
    configure(maxMessageSize, reconnectDelay, websocketIdleTimeout, Sets.newHashSet(processorMock));
    sendMessage();
    Thread.sleep(millis);
    verify(processorMock).processIncoming(any(ImmutableMessage.class));
}
Also used : ImmutableMessage(joynr.ImmutableMessage) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) Test(org.junit.Test)

Example 4 with JoynrMessageProcessor

use of io.joynr.messaging.JoynrMessageProcessor in project joynr by bmwcarit.

the class MutableMessageFactory method createMessage.

private MutableMessage createMessage(String joynrMessageType, String fromParticipantId, String toParticipantId, Object payload, MessagingQos messagingQos, boolean upliftTtl) {
    ExpiryDate expiryDate;
    if (!upliftTtl) {
        expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
    } else if (messagingQos.getRoundTripTtl_ms() > (Long.MAX_VALUE - ttlUpliftMs)) {
        expiryDate = DispatcherUtils.convertTtlToExpirationDate(Long.MAX_VALUE);
    } else {
        expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms() + ttlUpliftMs);
    }
    MutableMessage message = new MutableMessage();
    message.setType(joynrMessageType);
    if (messagingQos.getEffort() != null && !MessagingQosEffort.NORMAL.equals(messagingQos.getEffort())) {
        message.setEffort(String.valueOf(messagingQos.getEffort()));
    }
    message.setSender(fromParticipantId);
    message.setRecipient(toParticipantId);
    message.setTtlAbsolute(true);
    message.setTtlMs(expiryDate.getValue());
    message.setPayload(serializePayload(payload));
    message.setCustomHeaders(messagingQos.getCustomMessageHeaders());
    message.setCompressed(messagingQos.getCompress());
    for (JoynrMessageProcessor processor : messageProcessors) {
        message = processor.processOutgoing(message);
    }
    logger.debug("Message {} has expiry date: {}", message.getId(), expiryDate);
    return message;
}
Also used : ExpiryDate(io.joynr.common.ExpiryDate) MutableMessage(joynr.MutableMessage) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor)

Example 5 with JoynrMessageProcessor

use of io.joynr.messaging.JoynrMessageProcessor in project joynr by bmwcarit.

the class DefaultJoynrRuntimeFactoryTest method createFixture.

@SuppressWarnings("unchecked")
private void createFixture(Instance<Properties> joynrProperties, Instance<String> joynrLocalDomain) throws Exception {
    Instance<RawMessagingPreprocessor> rawMessageProcessor = mock(Instance.class);
    when(rawMessageProcessor.get()).thenReturn(new NoOpRawMessagingPreprocessor());
    BeanManager beanManager = mock(BeanManager.class);
    Bean<JoynrMessageProcessor> bean = mock(Bean.class);
    when(bean.create(Mockito.any())).thenReturn(new JoynrMessageProcessorTest());
    when(beanManager.getBeans(Mockito.<Type>eq(JoynrMessageProcessor.class), Mockito.<Annotation>any())).thenReturn(Sets.newHashSet(bean));
    final String mqttClientId = "someTestMqttClientId";
    MqttClientIdProvider mqttClientIdProvider = mock(MqttClientIdProvider.class);
    when(mqttClientIdProvider.getClientId()).thenReturn(mqttClientId);
    Instance<MqttClientIdProvider> mqttClientIdProviderInstance = mock(Instance.class);
    when(mqttClientIdProviderInstance.get()).thenReturn(mqttClientIdProvider);
    fixture = new DefaultJoynrRuntimeFactory(joynrProperties, joynrLocalDomain, rawMessageProcessor, mqttClientIdProviderInstance, beanManager, mock(StatusReceiver.class), mock(MqttStatusReceiver.class));
    scheduledExecutorService = mock(ScheduledExecutorService.class);
    Field executorField = DefaultJoynrRuntimeFactory.class.getDeclaredField("scheduledExecutorService");
    executorField.setAccessible(true);
    executorField.set(fixture, scheduledExecutorService);
}
Also used : NoOpRawMessagingPreprocessor(io.joynr.messaging.NoOpRawMessagingPreprocessor) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MqttClientIdProvider(io.joynr.messaging.mqtt.MqttClientIdProvider) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) NoOpRawMessagingPreprocessor(io.joynr.messaging.NoOpRawMessagingPreprocessor) RawMessagingPreprocessor(io.joynr.messaging.RawMessagingPreprocessor) Field(java.lang.reflect.Field) DefaultJoynrRuntimeFactory(io.joynr.jeeintegration.DefaultJoynrRuntimeFactory) BeanManager(javax.enterprise.inject.spi.BeanManager)

Aggregations

JoynrMessageProcessor (io.joynr.messaging.JoynrMessageProcessor)13 ImmutableMessage (joynr.ImmutableMessage)6 NoOpRawMessagingPreprocessor (io.joynr.messaging.NoOpRawMessagingPreprocessor)5 AbstractModule (com.google.inject.AbstractModule)4 JoynrPropertiesModule (io.joynr.common.JoynrPropertiesModule)4 RawMessagingPreprocessor (io.joynr.messaging.RawMessagingPreprocessor)4 Test (org.junit.Test)4 Injector (com.google.inject.Injector)3 TypeLiteral (com.google.inject.TypeLiteral)3 JsonMessageSerializerModule (io.joynr.messaging.JsonMessageSerializerModule)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 MutableMessage (joynr.MutableMessage)3 Multibinder (com.google.inject.multibindings.Multibinder)2 MessagingQos (io.joynr.messaging.MessagingQos)2 JoynrMqttClient (io.joynr.messaging.mqtt.JoynrMqttClient)2 MqttClientIdProvider (io.joynr.messaging.mqtt.MqttClientIdProvider)2 MessageRouter (io.joynr.messaging.routing.MessageRouter)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Binding (com.google.inject.Binding)1