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);
}
}
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());
}
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));
}
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;
}
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);
}
Aggregations