Search in sources :

Example 1 with SubscriptionReply

use of joynr.SubscriptionReply in project joynr by bmwcarit.

the class PublicationManagerImpl method handleMulticastSubscriptionRequest.

private void handleMulticastSubscriptionRequest(String proxyParticipantId, String providerParticipantId, MulticastSubscriptionRequest subscriptionRequest, ProviderContainer providerContainer) {
    logger.trace("Received multicast subscription request {} for provider with participant ID {}", subscriptionRequest, providerParticipantId);
    dispatcher.sendSubscriptionReply(providerParticipantId, proxyParticipantId, new SubscriptionReply(subscriptionRequest.getSubscriptionId()), createMessagingQos(subscriptionRequest.getQos()));
}
Also used : SubscriptionReply(joynr.SubscriptionReply)

Example 2 with SubscriptionReply

use of joynr.SubscriptionReply in project joynr by bmwcarit.

the class SubscriptionManagerTest method testHandleSubscriptionReplyWithSuccessWithBroadcastListener.

@Test
public void testHandleSubscriptionReplyWithSuccessWithBroadcastListener() {
    SubscriptionReply subscriptionReply = new SubscriptionReply(subscriptionId);
    @SuppressWarnings("unchecked") Future<String> futureMock = mock(Future.class);
    subscriptionFutureMap.put(subscriptionId, futureMock);
    BroadcastSubscriptionListener broadcastListener = mock(BroadcastSubscriptionListener.class);
    broadcastSubscriptionDirectory.put(subscriptionId, broadcastListener);
    subscriptionManager.handleSubscriptionReply(subscriptionReply);
    verify(futureMock).onSuccess(eq(subscriptionId));
    verify(broadcastListener).onSubscribed(eq(subscriptionId));
}
Also used : SubscriptionReply(joynr.SubscriptionReply) Matchers.anyString(org.mockito.Matchers.anyString) BroadcastSubscriptionListener(io.joynr.pubsub.subscription.BroadcastSubscriptionListener) Test(org.junit.Test)

Example 3 with SubscriptionReply

use of joynr.SubscriptionReply in project joynr by bmwcarit.

the class SubscriptionManagerTest method testHandleSubscriptionReplyWithErrorWithSubscriptionListener.

@Test
public void testHandleSubscriptionReplyWithErrorWithSubscriptionListener() {
    SubscriptionException subscriptionError = new SubscriptionException(subscriptionId);
    SubscriptionReply subscriptionReply = new SubscriptionReply(subscriptionId, subscriptionError);
    @SuppressWarnings("unchecked") Future<String> futureMock = mock(Future.class);
    subscriptionFutureMap.put(subscriptionId, futureMock);
    AttributeSubscriptionListener<?> subscriptionListener = mock(AttributeSubscriptionListener.class);
    attributeSubscriptionDirectory.put(subscriptionId, subscriptionListener);
    subscriptionManager.handleSubscriptionReply(subscriptionReply);
    verify(futureMock).onFailure(eq(subscriptionError));
    verify(subscriptionListener).onError(eq(subscriptionError));
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) SubscriptionReply(joynr.SubscriptionReply) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 4 with SubscriptionReply

use of joynr.SubscriptionReply in project joynr by bmwcarit.

the class SubscriptionManagerTest method testHandleSubscriptionReplyWithErrorWithBroadcastListener.

@Test
public void testHandleSubscriptionReplyWithErrorWithBroadcastListener() {
    SubscriptionException subscriptionError = new SubscriptionException(subscriptionId);
    SubscriptionReply subscriptionReply = new SubscriptionReply(subscriptionId, subscriptionError);
    @SuppressWarnings("unchecked") Future<String> futureMock = mock(Future.class);
    subscriptionFutureMap.put(subscriptionId, futureMock);
    BroadcastSubscriptionListener broadcastListener = mock(BroadcastSubscriptionListener.class);
    broadcastSubscriptionDirectory.put(subscriptionId, broadcastListener);
    subscriptionManager.handleSubscriptionReply(subscriptionReply);
    verify(futureMock).onFailure(eq(subscriptionError));
    verify(broadcastListener).onError(eq(subscriptionError));
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) SubscriptionReply(joynr.SubscriptionReply) Matchers.anyString(org.mockito.Matchers.anyString) BroadcastSubscriptionListener(io.joynr.pubsub.subscription.BroadcastSubscriptionListener) Test(org.junit.Test)

Example 5 with SubscriptionReply

use of joynr.SubscriptionReply in project joynr by bmwcarit.

the class PublicationManagerImpl method handleSubscriptionRequest.

private void handleSubscriptionRequest(PublicationInformation publicationInformation, SubscriptionRequest subscriptionRequest, ProviderContainer providerContainer) {
    final String subscriptionId = subscriptionRequest.getSubscriptionId();
    SubscriptionQos subscriptionQos = subscriptionRequest.getQos();
    MessagingQos messagingQos = createMessagingQos(subscriptionQos);
    try {
        Method method = findGetterForAttributeName(providerContainer.getProviderProxy().getClass(), subscriptionRequest.getSubscribedToName());
        triggerPublication(publicationInformation, providerContainer, method);
        boolean hasSubscriptionHeartBeat = subscriptionQos instanceof HeartbeatSubscriptionInformation;
        boolean isOnChangeSubscription = subscriptionQos instanceof OnChangeSubscriptionQos;
        if (hasSubscriptionHeartBeat || isOnChangeSubscription) {
            // TODO: send error subscription reply is periodMs < MIN_PERIOD_MS or periodMs > MAX_PERIOD_MS?
            final PublicationTimer timer = new PublicationTimer(publicationInformation, method, providerContainer, this, attributePollInterpreter);
            timer.startTimer();
            publicationTimers.put(subscriptionId, timer);
        }
        if (subscriptionQos instanceof OnChangeSubscriptionQos) {
            handleOnChangeSubscription(subscriptionRequest, providerContainer, subscriptionId);
        }
        dispatcher.sendSubscriptionReply(publicationInformation.providerParticipantId, publicationInformation.proxyParticipantId, new SubscriptionReply(subscriptionId), messagingQos);
    } catch (NoSuchMethodException e) {
        cancelPublicationCreation(subscriptionId);
        logger.error("Error subscribing: {}. The provider does not have the requested attribute", subscriptionRequest);
        sendSubscriptionReplyWithError(publicationInformation, subscriptionId, e, messagingQos);
    }
}
Also used : SubscriptionReply(joynr.SubscriptionReply) MessagingQos(io.joynr.messaging.MessagingQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) UnicastSubscriptionQos(joynr.UnicastSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) Method(java.lang.reflect.Method) HeartbeatSubscriptionInformation(io.joynr.pubsub.HeartbeatSubscriptionInformation)

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