Search in sources :

Example 6 with SubscriptionPublication

use of joynr.SubscriptionPublication 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)

Example 7 with SubscriptionPublication

use of joynr.SubscriptionPublication in project joynr by bmwcarit.

the class PublicationTimer method sendPublicationError.

private void sendPublicationError(JoynrRuntimeException error) {
    SubscriptionPublication publication = new SubscriptionPublication(error, publicationInformation.getSubscriptionId());
    sendPublication(publication);
}
Also used : SubscriptionPublication(joynr.SubscriptionPublication)

Example 8 with SubscriptionPublication

use of joynr.SubscriptionPublication in project joynr by bmwcarit.

the class SerializationTest method serializePublicationWithJoynrRuntimeException.

@Test
public void serializePublicationWithJoynrRuntimeException() throws JsonGenerationException, JsonMappingException, IOException {
    JoynrRuntimeException error = new JoynrRuntimeException("detail message: JoynrRuntimeException");
    String subscriptionId = "12345";
    SubscriptionPublication publication = new SubscriptionPublication(error, subscriptionId);
    String writeValueAsString = objectMapper.writeValueAsString(publication);
    SubscriptionPublication receivedPublication = objectMapper.readValue(writeValueAsString, SubscriptionPublication.class);
    Assert.assertEquals(publication, receivedPublication);
}
Also used : SubscriptionPublication(joynr.SubscriptionPublication) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 9 with SubscriptionPublication

use of joynr.SubscriptionPublication 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 10 with SubscriptionPublication

use of joynr.SubscriptionPublication in project joynr by bmwcarit.

the class PublicationManagerTest method broadcastPublicationIsSentWhenFiltersPass.

@SuppressWarnings("unchecked")
@Test
public void broadcastPublicationIsSentWhenFiltersPass() throws Exception {
    publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, providerDirectory, cleanupScheduler, Mockito.mock(SubscriptionRequestStorage.class), shutdownNotifier);
    long minInterval_ms = 0;
    long ttl = 1000;
    testBroadcastInterface.LocationUpdateWithSpeedSelectiveBroadcastFilterParameters filterParameters = new testBroadcastInterface.LocationUpdateWithSpeedSelectiveBroadcastFilterParameters();
    OnChangeSubscriptionQos qos = new OnChangeSubscriptionQos().setMinIntervalMs(minInterval_ms).setExpiryDateMs(SubscriptionQos.NO_EXPIRY_DATE).setPublicationTtlMs(ttl);
    SubscriptionRequest subscriptionRequest = new BroadcastSubscriptionRequest(SUBSCRIPTION_ID, "subscribedToName", filterParameters, qos);
    when(providerDirectory.get(eq(PROVIDER_PARTICIPANT_ID))).thenReturn(providerContainer);
    when(providerDirectory.contains(eq(PROVIDER_PARTICIPANT_ID))).thenReturn(true);
    publicationManager.addSubscriptionRequest(PROXY_PARTICIPANT_ID, PROVIDER_PARTICIPANT_ID, subscriptionRequest);
    GpsLocation location = new GpsLocation(1.0, 2.0, 3.0, GpsFixEnum.MODE2D, 4.0, 5.0, 6.0, 7.0, 9l, 10l, 11);
    float speed = 100;
    ArrayList<BroadcastFilter> filters = new ArrayList<BroadcastFilter>();
    testLocationUpdateWithSpeedSelectiveBroadcastFilter filterTrue = mock(testLocationUpdateWithSpeedSelectiveBroadcastFilter.class);
    when(filterTrue.filter(any(GpsLocation.class), any(Float.class), any(testBroadcastInterface.LocationUpdateWithSpeedSelectiveBroadcastFilterParameters.class))).thenReturn(true);
    filters.add(filterTrue);
    publicationManager.broadcastOccurred(subscriptionRequest.getSubscriptionId(), filters, location, speed);
    ArgumentCaptor<SubscriptionPublication> publicationCaptured = ArgumentCaptor.forClass(SubscriptionPublication.class);
    ArgumentCaptor<MessagingQos> qosCaptured = ArgumentCaptor.forClass(MessagingQos.class);
    verify(dispatcher).sendSubscriptionPublication(eq(PROVIDER_PARTICIPANT_ID), (Set<String>) argThat(contains(PROXY_PARTICIPANT_ID)), publicationCaptured.capture(), qosCaptured.capture());
    List<?> response = (List<?>) publicationCaptured.getValue().getResponse();
    assertEquals(location, response.get(0));
    assertEquals(speed, response.get(1));
}
Also used : OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) ArrayList(java.util.ArrayList) GpsLocation(joynr.types.Localisation.GpsLocation) joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter(joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter) Matchers.anyString(org.mockito.Matchers.anyString) joynr.tests.testBroadcastInterface(joynr.tests.testBroadcastInterface) SubscriptionRequest(joynr.SubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) SubscriptionPublication(joynr.SubscriptionPublication) List(java.util.List) ArrayList(java.util.ArrayList) BroadcastFilter(io.joynr.pubsub.publication.BroadcastFilter) joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter(joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter) joynr.tests.testLocationUpdateSelectiveBroadcastFilter(joynr.tests.testLocationUpdateSelectiveBroadcastFilter) Test(org.junit.Test)

Aggregations

SubscriptionPublication (joynr.SubscriptionPublication)12 Test (org.junit.Test)6 SubscriptionRequest (joynr.SubscriptionRequest)5 MessagingQos (io.joynr.messaging.MessagingQos)4 BroadcastFilter (io.joynr.pubsub.publication.BroadcastFilter)3 ArrayList (java.util.ArrayList)3 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)3 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)3 joynr.tests.testBroadcastInterface (joynr.tests.testBroadcastInterface)3 joynr.tests.testLocationUpdateSelectiveBroadcastFilter (joynr.tests.testLocationUpdateSelectiveBroadcastFilter)3 joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter (joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter)3 GpsLocation (joynr.types.Localisation.GpsLocation)3 Matchers.anyString (org.mockito.Matchers.anyString)3 List (java.util.List)2 MulticastSubscriptionRequest (joynr.MulticastSubscriptionRequest)2 MutableMessage (joynr.MutableMessage)2 Reply (joynr.Reply)2 Request (joynr.Request)2 Before (org.junit.Before)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1