Search in sources :

Example 1 with MulticastPublication

use of joynr.MulticastPublication in project joynr by bmwcarit.

the class CcMessageRouterTest method testMulticastMessageIsDroppedIfNoAddressIsFound.

@Test
public void testMulticastMessageIsDroppedIfNoAddressIsFound() throws Exception {
    final Semaphore semaphore = new Semaphore(0);
    final MulticastPublication multicastPublication = new MulticastPublication(new JoynrRuntimeException("Test Exception"), "multicastId");
    final MutableMessage mutableMessage = messageFactory.createMulticast("fromParticipantId", multicastPublication, new MessagingQos());
    final ImmutableMessage immutableMessage = mutableMessage.getImmutableMessage();
    MessageProcessedListener mockMsgProcessedListener = Mockito.mock(MessageProcessedListener.class);
    messageRouter.registerMessageProcessedListener(mockMsgProcessedListener);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            semaphore.release();
            return null;
        }
    }).when(mockMsgProcessedListener).messageProcessed(anyString());
    messageRouter.route(immutableMessage);
    semaphore.tryAcquire(1000, TimeUnit.MILLISECONDS);
    verify(mockMsgProcessedListener).messageProcessed(immutableMessage.getId());
    verifyNoMoreInteractions(messagingStubMock);
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) MulticastPublication(joynr.MulticastPublication) MutableMessage(joynr.MutableMessage) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ImmutableMessage(joynr.ImmutableMessage) Semaphore(java.util.concurrent.Semaphore) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 2 with MulticastPublication

use of joynr.MulticastPublication in project joynr by bmwcarit.

the class TtlUpliftTest method testTtlUpliftMs_Multicast.

@Test
public void testTtlUpliftMs_Multicast() {
    MulticastPublication multicastPublication = new MulticastPublication();
    expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
    MutableMessage message = messageFactoryWithTtlUplift.createMulticast(fromParticipantId, multicastPublication, messagingQos);
    long expiryDateValue = expiryDate.getValue() + TTL_UPLIFT_MS;
    MutableMessageFactoryTest.assertExpiryDateEquals(expiryDateValue, message);
}
Also used : MulticastPublication(joynr.MulticastPublication) MutableMessage(joynr.MutableMessage) Test(org.junit.Test)

Example 3 with MulticastPublication

use of joynr.MulticastPublication in project joynr by bmwcarit.

the class SerializationTest method serializeMulticast.

@Test
public void serializeMulticast() throws JsonGenerationException, JsonMappingException, IOException {
    Object response = new GpsPosition(49.0065, 11.65);
    String multicastId = "1234";
    MulticastPublication publication = new MulticastPublication(Arrays.asList(response), multicastId);
    String writeValueAsString = objectMapper.writeValueAsString(publication);
    MulticastPublication receivedPublication = objectMapper.readValue(writeValueAsString, MulticastPublication.class);
    Assert.assertEquals(publication, receivedPublication);
}
Also used : MulticastPublication(joynr.MulticastPublication) GpsPosition(joynr.types.Localisation.GpsPosition) Test(org.junit.Test)

Example 4 with MulticastPublication

use of joynr.MulticastPublication in project joynr by bmwcarit.

the class PublicationManagerImpl method multicastOccurred.

@Override
public void multicastOccurred(String providerParticipantId, String multicastName, String[] partitions, Object... values) {
    logger.trace("Multicast occurred for {} / {} / {} / {}", providerParticipantId, multicastName, Arrays.toString(partitions), Arrays.toString(values));
    String multicastId = MulticastIdUtil.createMulticastId(providerParticipantId, multicastName, partitions);
    MulticastPublication multicastPublication = new MulticastPublication(Arrays.asList(values), multicastId);
    MessagingQos messagingQos = new MessagingQos();
    dispatcher.sendMulticast(providerParticipantId, multicastPublication, messagingQos);
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) MulticastPublication(joynr.MulticastPublication)

Example 5 with MulticastPublication

use of joynr.MulticastPublication in project joynr by bmwcarit.

the class DispatcherImpl method messageArrived.

@Override
public void messageArrived(final ImmutableMessage message) {
    if (message == null) {
        logger.error("received message was null");
        return;
    }
    if (!message.isTtlAbsolute()) {
        logger.error("received message with relative ttl (not supported)");
        return;
    }
    final long expiryDate = message.getTtlMs();
    final Map<String, String> customHeaders = message.getCustomHeaders();
    if (DispatcherUtils.isExpired(expiryDate)) {
        logger.debug("TTL expired, discarding message : {}", message);
        return;
    }
    String payload;
    try {
        payload = new String(message.getUnencryptedBody(), Charsets.UTF_8);
    } catch (EncodingException e) {
        logger.error("Error reading SMRF message. msgId: {}. from: {} to: {}. Reason: {}. Discarding joynr message.", new Object[] { message.getSender(), message.getRecipient(), message.getId(), e.getMessage() });
        return;
    }
    String type = message.getType();
    try {
        if (Message.VALUE_MESSAGE_TYPE_REPLY.equals(type)) {
            Reply reply = objectMapper.readValue(payload, Reply.class);
            logger.trace("Parsed reply from message payload :" + payload);
            handle(reply);
        } else if (Message.VALUE_MESSAGE_TYPE_SUBSCRIPTION_REPLY.equals(type)) {
            SubscriptionReply subscriptionReply = objectMapper.readValue(payload, SubscriptionReply.class);
            logger.trace("Parsed subscription reply from message payload :" + payload);
            handle(subscriptionReply);
        } else if (Message.VALUE_MESSAGE_TYPE_REQUEST.equals(type)) {
            final Request request = objectMapper.readValue(payload, Request.class);
            request.setCreatorUserId(message.getCreatorUserId());
            request.setContext(message.getContext());
            logger.trace("Parsed request from message payload :" + payload);
            handle(request, message.getSender(), message.getRecipient(), expiryDate, customHeaders, message.isCompressed());
        } else if (Message.VALUE_MESSAGE_TYPE_ONE_WAY.equals(type)) {
            OneWayRequest oneWayRequest = objectMapper.readValue(payload, OneWayRequest.class);
            oneWayRequest.setCreatorUserId(message.getCreatorUserId());
            oneWayRequest.setContext(message.getContext());
            logger.trace("Parsed one way request from message payload :" + payload);
            handle(oneWayRequest, message.getRecipient(), expiryDate);
        } else if (Message.VALUE_MESSAGE_TYPE_SUBSCRIPTION_REQUEST.equals(type) || Message.VALUE_MESSAGE_TYPE_BROADCAST_SUBSCRIPTION_REQUEST.equals(type) || Message.VALUE_MESSAGE_TYPE_MULTICAST_SUBSCRIPTION_REQUEST.equals(type)) {
            SubscriptionRequest subscriptionRequest = objectMapper.readValue(payload, SubscriptionRequest.class);
            logger.trace("Parsed subscription request from message payload :" + payload);
            handle(subscriptionRequest, message.getSender(), message.getRecipient());
        } else if (Message.VALUE_MESSAGE_TYPE_SUBSCRIPTION_STOP.equals(type)) {
            SubscriptionStop subscriptionStop = objectMapper.readValue(payload, SubscriptionStop.class);
            logger.trace("Parsed subscription stop from message payload :" + payload);
            handle(subscriptionStop);
        } else if (Message.VALUE_MESSAGE_TYPE_PUBLICATION.equals(type)) {
            SubscriptionPublication publication = objectMapper.readValue(payload, SubscriptionPublication.class);
            logger.trace("Parsed publication from message payload :" + payload);
            handle(publication);
        } else if (Message.VALUE_MESSAGE_TYPE_MULTICAST.equals(type)) {
            MulticastPublication multicastPublication = objectMapper.readValue(payload, MulticastPublication.class);
            logger.trace("Parsed multicast publication from message payload: {}", payload);
            handle(multicastPublication);
        }
    } catch (IOException e) {
        logger.error("Error parsing payload. msgId: {}. from: {} to: {}. Reason: {}. Discarding joynr message.", message.getId(), message.getSender(), message.getRecipient(), e.getMessage());
        return;
    }
}
Also used : SubscriptionReply(joynr.SubscriptionReply) EncodingException(io.joynr.smrf.EncodingException) OneWayRequest(joynr.OneWayRequest) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) SubscriptionRequest(joynr.SubscriptionRequest) Request(joynr.Request) IOException(java.io.IOException) OneWayRequest(joynr.OneWayRequest) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) SubscriptionRequest(joynr.SubscriptionRequest) MulticastPublication(joynr.MulticastPublication) SubscriptionPublication(joynr.SubscriptionPublication) SubscriptionReply(joynr.SubscriptionReply) Reply(joynr.Reply) SubscriptionStop(joynr.SubscriptionStop)

Aggregations

MulticastPublication (joynr.MulticastPublication)7 Test (org.junit.Test)5 MessagingQos (io.joynr.messaging.MessagingQos)3 MutableMessage (joynr.MutableMessage)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)1 EncodingException (io.joynr.smrf.EncodingException)1 IOException (java.io.IOException)1 Semaphore (java.util.concurrent.Semaphore)1 ImmutableMessage (joynr.ImmutableMessage)1 MulticastSubscriptionRequest (joynr.MulticastSubscriptionRequest)1 OneWayRequest (joynr.OneWayRequest)1 Reply (joynr.Reply)1 Request (joynr.Request)1 SubscriptionPublication (joynr.SubscriptionPublication)1 SubscriptionReply (joynr.SubscriptionReply)1 SubscriptionRequest (joynr.SubscriptionRequest)1 SubscriptionStop (joynr.SubscriptionStop)1 GpsPosition (joynr.types.Localisation.GpsPosition)1 Matchers.anyString (org.mockito.Matchers.anyString)1