Search in sources :

Example 6 with JoynrMessageProcessor

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

the class DefaultJoynrRuntimeFactoryTest method testJoynrMessageProcessorAdded.

@Test
public void testJoynrMessageProcessorAdded() throws Exception {
    createFixture();
    Injector injector = fixture.getInjector();
    List<Binding<JoynrMessageProcessor>> bindings = injector.findBindingsByType(new TypeLiteral<JoynrMessageProcessor>() {
    });
    assertEquals(1, bindings.size());
}
Also used : Binding(com.google.inject.Binding) Injector(com.google.inject.Injector) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) Test(org.junit.Test)

Example 7 with JoynrMessageProcessor

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

the class MqttMessagingSkeletonTest method testJoynrMessageProcessorIsCalled.

@Test
public void testJoynrMessageProcessorIsCalled() throws Exception {
    JoynrMessageProcessor processorMock = mock(JoynrMessageProcessor.class);
    when(processorMock.processIncoming(any(ImmutableMessage.class))).then(returnsFirstArg());
    subject = new MqttMessagingSkeleton(ownAddress, maxIncomingMqttRequests, messageRouter, mqttClientFactory, mqttTopicPrefixProvider, new NoOpRawMessagingPreprocessor(), Sets.newHashSet(processorMock), mqttStatusReceiver);
    ImmutableMessage rqMessage = createTestRequestMessage();
    subject.transmit(rqMessage.getSerializedMessage(), failIfCalledAction);
    ArgumentCaptor<ImmutableMessage> argCaptor = ArgumentCaptor.forClass(ImmutableMessage.class);
    verify(processorMock).processIncoming(argCaptor.capture());
    Assert.assertArrayEquals(rqMessage.getSerializedMessage(), argCaptor.getValue().getSerializedMessage());
}
Also used : NoOpRawMessagingPreprocessor(io.joynr.messaging.NoOpRawMessagingPreprocessor) ImmutableMessage(joynr.ImmutableMessage) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) Test(org.junit.Test)

Example 8 with JoynrMessageProcessor

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

the class MqttPahoClientTest method mqttClientTestResubscriptionWithCleanRestartEnabled.

@Test
public void mqttClientTestResubscriptionWithCleanRestartEnabled() throws Exception {
    properties.put(MqttModule.PROPERTY_KEY_MQTT_BROKER_URI, "tcp://localhost:1883");
    injector = Guice.createInjector(new MqttPahoModule(), new JoynrPropertiesModule(properties), new AbstractModule() {

        @Override
        protected void configure() {
            bind(MessageRouter.class).toInstance(mockMessageRouter);
            bind(ScheduledExecutorService.class).annotatedWith(Names.named(MessageRouter.SCHEDULEDTHREADPOOL)).toInstance(Executors.newScheduledThreadPool(10));
            bind(RawMessagingPreprocessor.class).to(NoOpRawMessagingPreprocessor.class);
            Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
            });
        }
    });
    ownTopic = injector.getInstance((Key.get(MqttAddress.class, Names.named(MqttModule.PROPERTY_MQTT_GLOBAL_ADDRESS))));
    ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);
    MqttClientIdProvider mqttClientIdProvider = injector.getInstance(MqttClientIdProvider.class);
    String clientId = mqttClientIdProvider.getClientId();
    String brokerUri = "tcp://localhost:1883";
    int reconnectSleepMs = 100;
    int keepAliveTimerSec = 60;
    int connectionTimeoutSec = 60;
    int timeToWaitMs = -1;
    int maxMsgsInflight = 100;
    int maxMsgSizeBytes = 0;
    boolean cleanSession = true;
    MqttClient mqttClient = new MqttClient(brokerUri, clientId, new MemoryPersistence(), scheduledExecutorService);
    joynrMqttClient = new MqttPahoClient(mqttClient, reconnectSleepMs, keepAliveTimerSec, connectionTimeoutSec, timeToWaitMs, maxMsgsInflight, maxMsgSizeBytes, cleanSession, "", "", "", "", mock(MqttStatusReceiver.class));
    joynrMqttClient.start();
    joynrMqttClient.setMessageListener(mockReceiver);
    joynrMqttClient.subscribe(ownTopic.getTopic());
    // manually call disconnect and connectionLost
    mqttClient.disconnect(500);
    MqttException exeption = new MqttException(MqttException.REASON_CODE_CLIENT_TIMEOUT);
    MqttPahoClient mqttPahoClient = (MqttPahoClient) joynrMqttClient;
    mqttPahoClient.connectionLost(exeption);
    joynrMqttClientPublishAndVerifyReceivedMessage(serializedMessage);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MemoryPersistence(org.eclipse.paho.client.mqttv3.persist.MemoryPersistence) MessageRouter(io.joynr.messaging.routing.MessageRouter) MqttClientIdProvider(io.joynr.messaging.mqtt.MqttClientIdProvider) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) NoOpRawMessagingPreprocessor(io.joynr.messaging.NoOpRawMessagingPreprocessor) RawMessagingPreprocessor(io.joynr.messaging.RawMessagingPreprocessor) AbstractModule(com.google.inject.AbstractModule) JoynrMqttClient(io.joynr.messaging.mqtt.JoynrMqttClient) MqttClient(org.eclipse.paho.client.mqttv3.MqttClient) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) MqttException(org.eclipse.paho.client.mqttv3.MqttException) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Test(org.junit.Test)

Example 9 with JoynrMessageProcessor

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

the class MqttPahoClientTest method createMqttClientInternal.

private JoynrMqttClient createMqttClientInternal(final MqttStatusReceiver mqttStatusReceiver) {
    injector = Guice.createInjector(override(new MqttPahoModule()).with(new AbstractModule() {

        @Override
        protected void configure() {
            if (mqttStatusReceiver != null) {
                bind(MqttStatusReceiver.class).toInstance(mqttStatusReceiver);
            }
        }
    }), new JoynrPropertiesModule(properties), new AbstractModule() {

        @Override
        protected void configure() {
            bind(MessageRouter.class).toInstance(mockMessageRouter);
            bind(ScheduledExecutorService.class).annotatedWith(Names.named(MessageRouter.SCHEDULEDTHREADPOOL)).toInstance(Executors.newScheduledThreadPool(10));
            bind(RawMessagingPreprocessor.class).to(NoOpRawMessagingPreprocessor.class);
            Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
            });
        }
    });
    // create a new Factory because the factory caches its client.
    mqttClientFactory = injector.getInstance(MqttClientFactory.class);
    JoynrMqttClient client = mqttClientFactory.create();
    client.setMessageListener(mockReceiver);
    return client;
}
Also used : JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) MessageRouter(io.joynr.messaging.routing.MessageRouter) MqttClientFactory(io.joynr.messaging.mqtt.MqttClientFactory) JoynrMqttClient(io.joynr.messaging.mqtt.JoynrMqttClient) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) NoOpRawMessagingPreprocessor(io.joynr.messaging.NoOpRawMessagingPreprocessor) RawMessagingPreprocessor(io.joynr.messaging.RawMessagingPreprocessor) AbstractModule(com.google.inject.AbstractModule)

Example 10 with JoynrMessageProcessor

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

the class WebSocketMessagingSkeleton method transmit.

@Override
public void transmit(byte[] serializedMessage, FailureAction failureAction) {
    try {
        ImmutableMessage message = new ImmutableMessage(serializedMessage);
        LOG.debug("<<< INCOMING <<< {}", message);
        if (messageProcessors != null) {
            for (JoynrMessageProcessor processor : messageProcessors) {
                message = processor.processIncoming(message);
            }
        }
        if (Message.VALUE_MESSAGE_TYPE_MULTICAST.equals(message.getType()) && this.isMainTransport()) {
            message.setReceivedFromGlobal(true);
        }
        messageRouter.route(message);
    } catch (Exception error) {
        failureAction.execute(error);
    }
}
Also used : ImmutableMessage(joynr.ImmutableMessage) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor)

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