use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class Utilities method splitSMRF.
public static List<ImmutableMessage> splitSMRF(byte[] combinedSMRFMessages) throws EncodingException, UnsuppportedVersionException {
List<ImmutableMessage> result = Lists.newArrayList();
byte[] remainingData = combinedSMRFMessages;
while (remainingData.length > 0) {
ImmutableMessage currentMessage = new ImmutableMessage(remainingData);
int currentMessageSize = currentMessage.getMessageSize();
// A message size of 0 may lead to an infinite loop
if (currentMessageSize <= 0) {
logger.error("One message in a SMRF message sequence had a size <= 0. Dropping remaining messages.");
break;
}
remainingData = Arrays.copyOfRange(remainingData, currentMessageSize, remainingData.length);
result.add(currentMessage);
}
return result;
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class AbstractMessageSender method routeMutableMessage.
private void routeMutableMessage(MutableMessage mutableMessage) {
ImmutableMessage immutableMessage;
try {
immutableMessage = mutableMessage.getImmutableMessage();
} catch (SecurityException | EncodingException | UnsuppportedVersionException exception) {
throw new JoynrRuntimeException(exception.getMessage());
}
messageRouter.route(immutableMessage);
}
use of joynr.ImmutableMessage in project joynr by bmwcarit.
the class AttachmentTest method testSendAndDownload.
@Test
public void testSendAndDownload() throws Exception {
String channelId = "AttachmentTest_" + UUID.randomUUID().toString();
bpMock.createChannel(channelId);
Response senMsgResponse = sendAttachmentMessage(channelId);
String msgId = senMsgResponse.getHeader("msgId");
Future<Response> response = bpMock.longPollInOwnThread(channelId, 1000000, 200);
Response longPoll = response.get();
List<ImmutableMessage> messages = bpMock.getJoynrMessagesFromResponse(longPoll);
assertEquals(1, messages.size());
ImmutableMessage message = messages.get(0);
assertTrue(message.getUnencryptedBody() != null);
Response attachment = getAttachment(channelId, msgId);
logger.debug("received attachment: " + convertStreamToString(attachment.getBody().asInputStream()));
}
use of joynr.ImmutableMessage 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 joynr.ImmutableMessage in project joynr by bmwcarit.
the class AbstractBounceProxyServerTest method testSendAndReceiveMessagesOnAtmosphereServer.
@Test(timeout = 20000)
@Ignore
public // the server will hang 20 secs
void testSendAndReceiveMessagesOnAtmosphereServer() throws Exception {
final long maxTimePerRun = 5000;
final int maxRuns = 100;
bpMock.createChannel(channelId);
// createChannel(channelIdProvider);
RestAssured.baseURI = getBounceProxyBaseUri();
int index = 1;
List<byte[]> expectedPayloads = new ArrayList<byte[]>();
for (int i = 0; i < maxRuns; i++) {
expectedPayloads.clear();
long startTime_ms = System.currentTimeMillis();
ScheduledFuture<Response> longPollConsumer = bpMock.longPollInOwnThread(channelId, 30000);
byte[] postPayload = (payload + index++ + "-" + UUID.randomUUID().toString()).getBytes(Charsets.UTF_8);
expectedPayloads.add(postPayload);
ScheduledFuture<Response> postMessage = bpMock.postMessageInOwnThread(channelId, 5000, postPayload);
byte[] postPayload2 = (payload + index++ + "-" + UUID.randomUUID().toString()).getBytes(Charsets.UTF_8);
expectedPayloads.add(postPayload2);
ScheduledFuture<Response> postMessage2 = bpMock.postMessageInOwnThread(channelId, 5000, postPayload2);
// wait until the long poll returns
Response responseLongPoll = longPollConsumer.get();
byte[] responseBody = responseLongPoll.getBody().asByteArray();
List<ImmutableMessage> receivedMessages = Utilities.splitSMRF(responseBody);
// wait until the POSTs are finished.
postMessage.get();
postMessage2.get();
long elapsedTime_ms = System.currentTimeMillis() - startTime_ms;
if (receivedMessages.size() < 2 && elapsedTime_ms < maxTimePerRun) {
// Thread.sleep(100);
Response responseLongPoll2 = bpMock.longPollInOwnThread(channelId, 30000).get();
byte[] responseBody2 = responseLongPoll2.getBody().asByteArray();
List<ImmutableMessage> receivedMessages2 = Utilities.splitSMRF(responseBody2);
receivedMessages.addAll(receivedMessages2);
}
ArrayList<byte[]> payloads = new ArrayList<byte[]>();
for (ImmutableMessage message : receivedMessages) {
payloads.add(message.getUnencryptedBody());
}
elapsedTime_ms = System.currentTimeMillis() - startTime_ms;
log.info(i + ": time elapsed to send messages and return long poll:" + elapsedTime_ms);
assertThat("the long poll did not receive the messages in time", elapsedTime_ms, lessThan(maxTimePerRun));
if (payloads.size() == 2) {
assertFalse("Unresolved bug that causes duplicate messages to be sent", payloads.get(0).equals(payloads.get(1)));
}
assertThat(payloads, hasItems(postPayload, postPayload2));
}
}
Aggregations