Search in sources :

Example 6 with SubscriptionReply

use of joynr.SubscriptionReply in project joynr by bmwcarit.

the class PublicationManagerImpl method sendSubscriptionReplyWithError.

private void sendSubscriptionReplyWithError(SubscriptionException e, PublicationInformation publicationInformation, SubscriptionRequest subscriptionRequest) {
    SubscriptionQos subscriptionQos = subscriptionRequest.getQos();
    MessagingQos messagingQos = new MessagingQos();
    if (subscriptionQos.getExpiryDateMs() == SubscriptionQos.NO_EXPIRY_DATE) {
        messagingQos.setTtl_ms(SubscriptionQos.INFINITE_SUBSCRIPTION);
    } else {
        // TTL uplift will be done in JoynrMessageFactory
        messagingQos.setTtl_ms(subscriptionQos.getExpiryDateMs() - System.currentTimeMillis());
    }
    SubscriptionReply subscriptionReply = new SubscriptionReply(publicationInformation.getSubscriptionId(), e);
    dispatcher.sendSubscriptionReply(publicationInformation.providerParticipantId, publicationInformation.proxyParticipantId, subscriptionReply, messagingQos);
}
Also used : SubscriptionReply(joynr.SubscriptionReply) MessagingQos(io.joynr.messaging.MessagingQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) UnicastSubscriptionQos(joynr.UnicastSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos)

Example 7 with SubscriptionReply

use of joynr.SubscriptionReply in project joynr by bmwcarit.

the class PublicationManagerImpl method sendSubscriptionReplyWithError.

private void sendSubscriptionReplyWithError(PublicationInformation publicationInformation, String subscriptionId, Exception exception, MessagingQos messagingQos) {
    SubscriptionException subscriptionException = new SubscriptionException(subscriptionId, exception.getMessage());
    SubscriptionReply subscriptionReply = new SubscriptionReply(subscriptionId, subscriptionException);
    dispatcher.sendSubscriptionReply(publicationInformation.providerParticipantId, publicationInformation.proxyParticipantId, subscriptionReply, messagingQos);
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) SubscriptionReply(joynr.SubscriptionReply)

Example 8 with SubscriptionReply

use of joynr.SubscriptionReply in project joynr by bmwcarit.

the class PublicationManagerImpl method handleBroadcastSubscriptionRequest.

private void handleBroadcastSubscriptionRequest(String proxyParticipantId, String providerParticipantId, BroadcastSubscriptionRequest subscriptionRequest, ProviderContainer providerContainer) {
    logger.trace("adding broadcast publication: {}", subscriptionRequest);
    BroadcastListener broadcastListener = new BroadcastListenerImpl(subscriptionRequest.getSubscriptionId(), this);
    String broadcastName = subscriptionRequest.getSubscribedToName();
    providerContainer.getSubscriptionPublisher().registerBroadcastListener(broadcastName, broadcastListener);
    unregisterBroadcastListeners.put(subscriptionRequest.getSubscriptionId(), new UnregisterBroadcastListener(providerContainer.getSubscriptionPublisher(), broadcastName, broadcastListener));
    final String subscriptionId = subscriptionRequest.getSubscriptionId();
    SubscriptionQos subscriptionQos = subscriptionRequest.getQos();
    MessagingQos messagingQos = createMessagingQos(subscriptionQos);
    SubscriptionReply subscriptionReply = new SubscriptionReply(subscriptionId);
    dispatcher.sendSubscriptionReply(providerParticipantId, proxyParticipantId, subscriptionReply, messagingQos);
}
Also used : SubscriptionReply(joynr.SubscriptionReply) MessagingQos(io.joynr.messaging.MessagingQos) BroadcastListener(io.joynr.pubsub.publication.BroadcastListener) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) UnicastSubscriptionQos(joynr.UnicastSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos)

Example 9 with SubscriptionReply

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

use of joynr.SubscriptionReply in project joynr by bmwcarit.

the class TtlUpliftTest method verifySubscriptionReplyTtl.

private void verifySubscriptionReplyTtl(long expectedSubscriptionReplyTtl, long toleranceMs) {
    verify(dispatcher, times(1)).sendSubscriptionReply(eq(PROVIDER_PARTICIPANT_ID), eq(PROXY_PARTICIPANT_ID), any(SubscriptionReply.class), messagingQosCaptor.capture());
    MessagingQos capturedMessagingQos = messagingQosCaptor.getValue();
    long diff = Math.abs(expectedSubscriptionReplyTtl - capturedMessagingQos.getRoundTripTtl_ms());
    assertTrue("TTL of subscriptionReply=" + capturedMessagingQos.getRoundTripTtl_ms() + " differs " + diff + "ms (more than " + toleranceMs + "ms) from the expected value=" + expectedSubscriptionReplyTtl, (diff <= toleranceMs));
}
Also used : SubscriptionReply(joynr.SubscriptionReply) MessagingQos(io.joynr.messaging.MessagingQos)

Aggregations

SubscriptionReply (joynr.SubscriptionReply)14 Test (org.junit.Test)7 Matchers.anyString (org.mockito.Matchers.anyString)6 SubscriptionException (io.joynr.exceptions.SubscriptionException)4 MessagingQos (io.joynr.messaging.MessagingQos)4 SubscriptionQos (io.joynr.pubsub.SubscriptionQos)3 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)3 UnicastSubscriptionQos (joynr.UnicastSubscriptionQos)3 BroadcastSubscriptionListener (io.joynr.pubsub.subscription.BroadcastSubscriptionListener)2 HeartbeatSubscriptionInformation (io.joynr.pubsub.HeartbeatSubscriptionInformation)1 BroadcastListener (io.joynr.pubsub.publication.BroadcastListener)1 EncodingException (io.joynr.smrf.EncodingException)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 MulticastPublication (joynr.MulticastPublication)1 MulticastSubscriptionRequest (joynr.MulticastSubscriptionRequest)1 MutableMessage (joynr.MutableMessage)1 OneWayRequest (joynr.OneWayRequest)1 Reply (joynr.Reply)1 Request (joynr.Request)1