Search in sources :

Example 11 with JoynrMessageProcessor

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

the class MqttMessagingSkeleton method transmit.

@Override
public void transmit(byte[] serializedMessage, FailureAction failureAction) {
    try {
        HashMap<String, Serializable> context = new HashMap<String, Serializable>();
        byte[] processedMessage = rawMessagingPreprocessor.process(serializedMessage, context);
        ImmutableMessage message = new ImmutableMessage(processedMessage);
        message.setContext(context);
        LOG.debug("<<< INCOMING <<< {}", message);
        if (messageProcessors != null) {
            for (JoynrMessageProcessor processor : messageProcessors) {
                message = processor.processIncoming(message);
            }
        }
        if (dropMessage(message)) {
            droppedMessagesCount.incrementAndGet();
            mqttStatusReceiver.notifyMessageDropped();
            return;
        }
        message.setReceivedFromGlobal(true);
        if (isRequestMessageTypeThatCanBeDropped(message.getType())) {
            requestAccepted(message.getId());
        }
        try {
            messageRouter.route(message);
        } catch (Exception e) {
            LOG.error("Error processing incoming message. Message will be dropped: {} ", e.getMessage());
            messageProcessed(message.getId());
            failureAction.execute(e);
        }
    } catch (UnsuppportedVersionException | EncodingException | NullPointerException e) {
        LOG.error("Message: \"{}\", could not be deserialized, exception: {}", serializedMessage, e.getMessage());
        failureAction.execute(e);
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) EncodingException(io.joynr.smrf.EncodingException) ImmutableMessage(joynr.ImmutableMessage) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) UnsuppportedVersionException(io.joynr.smrf.UnsuppportedVersionException) EncodingException(io.joynr.smrf.EncodingException) UnsuppportedVersionException(io.joynr.smrf.UnsuppportedVersionException)

Example 12 with JoynrMessageProcessor

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

the class MutableMessageFactoryTest method setUp.

@Before
public void setUp() throws NoSuchMethodException, SecurityException {
    fromParticipantId = "sender";
    toParticipantId = "receiver";
    Injector injector = Guice.createInjector(new JoynrPropertiesModule(new Properties()), 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) {
                    joynrMessage.getCustomHeaders().put("test", "test");
                    return joynrMessage;
                }

                @Override
                public ImmutableMessage processIncoming(ImmutableMessage joynrMessage) {
                    return joynrMessage;
                }
            });
        }
    });
    objectMapper = injector.getInstance(ObjectMapper.class);
    payload = "payload";
    Method method = TestProvider.class.getMethod("methodWithStrings", new Class[] { String.class });
    request = new Request(method.getName(), new String[] { payload }, method.getParameterTypes());
    String requestReplyId = request.getRequestReplyId();
    reply = new Reply(requestReplyId, objectMapper.<JsonNode>valueToTree(payload));
    messagingQos = new MessagingQos(TTL);
    expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
    String subscriptionId = "subscription";
    String attributeName = "attribute";
    PeriodicSubscriptionQos subscriptionqos = new PeriodicSubscriptionQos();
    subscriptionqos.setPeriodMs(1000).setValidityMs(10).setAlertAfterIntervalMs(1500).setPublicationTtlMs(1000);
    subscriptionRequest = new SubscriptionRequest(subscriptionId, attributeName, subscriptionqos);
    String response = "response";
    publication = new SubscriptionPublication(Arrays.asList(response), subscriptionId);
    mutableMessageFactory = injector.getInstance(MutableMessageFactory.class);
}
Also used : Multibinder(com.google.inject.multibindings.Multibinder) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) SubscriptionRequest(joynr.SubscriptionRequest) Request(joynr.Request) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) JsonNode(com.fasterxml.jackson.databind.JsonNode) Method(java.lang.reflect.Method) Properties(java.util.Properties) AbstractModule(com.google.inject.AbstractModule) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) MessagingQos(io.joynr.messaging.MessagingQos) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) SubscriptionRequest(joynr.SubscriptionRequest) TypeLiteral(com.google.inject.TypeLiteral) MutableMessage(joynr.MutableMessage) Injector(com.google.inject.Injector) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) SubscriptionPublication(joynr.SubscriptionPublication) ImmutableMessage(joynr.ImmutableMessage) Reply(joynr.Reply) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 13 with JoynrMessageProcessor

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

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