Search in sources :

Example 16 with SubscriptionQos

use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.

the class PublicationManagerImpl method validateAndGetSubscriptionEndDelay.

private long validateAndGetSubscriptionEndDelay(SubscriptionRequest subscriptionRequest) {
    SubscriptionQos subscriptionQos = subscriptionRequest.getQos();
    long subscriptionEndDelay = getSubscriptionEndDelay(subscriptionQos);
    if (subscriptionEndDelay < 0) {
        throw new SubscriptionException(subscriptionRequest.getSubscriptionId(), "Subscription expired.");
    }
    return subscriptionEndDelay;
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) UnicastSubscriptionQos(joynr.UnicastSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos)

Example 17 with SubscriptionQos

use of io.joynr.pubsub.SubscriptionQos 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 18 with SubscriptionQos

use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.

the class SubscriptionQosTest method createPeriodicSubscriptionQosWithValidity.

@Test
public void createPeriodicSubscriptionQosWithValidity() throws Exception {
    long validityMs = 1000;
    long lowerBound = System.currentTimeMillis() + validityMs;
    SubscriptionQos periodicSubscriptionQos = new PeriodicSubscriptionQos().setValidityMs(validityMs);
    long upperBound = System.currentTimeMillis() + validityMs;
    assertTrue(periodicSubscriptionQos.getExpiryDateMs() >= lowerBound);
    assertTrue(periodicSubscriptionQos.getExpiryDateMs() <= upperBound);
}
Also used : SubscriptionQos(io.joynr.pubsub.SubscriptionQos) Test(org.junit.Test)

Example 19 with SubscriptionQos

use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.

the class ConnectorTest method subscribeToAttributeCallCallsSubscriptionManagerWithCorrectArguments.

@Test
public void subscribeToAttributeCallCallsSubscriptionManagerWithCorrectArguments() {
    AttributeSubscriptionListener<String> listener = new AttributeSubscriptionAdapter<>();
    SubscriptionQos subscriptionQos = new OnChangeSubscriptionQos();
    ConnectorInvocationHandler connector = createConnector();
    assertNotNull(connector);
    try {
        Method method = TestSubscriptionInterface.class.getDeclaredMethod("subscribeToTestAttribute", AttributeSubscriptionListener.class, SubscriptionQos.class);
        AttributeSubscribeInvocation invocation = new AttributeSubscribeInvocation(method, new Object[] { listener, subscriptionQos }, null);
        connector.executeSubscriptionMethod(invocation);
        verify(subscriptionManager, times(1)).registerAttributeSubscription(fromParticipantId, toDiscoveryEntries, invocation);
    } catch (Exception e) {
        fail("Unexpected exception from attribute subscribe call: " + e);
    }
}
Also used : AttributeSubscriptionAdapter(io.joynr.pubsub.subscription.AttributeSubscriptionAdapter) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) Method(java.lang.reflect.Method) AttributeSubscribeInvocation(io.joynr.proxy.invocation.AttributeSubscribeInvocation) SubscriptionException(io.joynr.exceptions.SubscriptionException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) Test(org.junit.Test)

Example 20 with SubscriptionQos

use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.

the class ProxyInvocationHandlerTest method testPartitionsPassedToMulticastSubscription.

@Test
public void testPartitionsPassedToMulticastSubscription() throws NoSuchMethodException, ApplicationException {
    ConnectorInvocationHandler connectorInvocationHandler = mock(ConnectorInvocationHandler.class);
    when(connectorFactory.create(Mockito.anyString(), Mockito.<ArbitrationResult>any(), Mockito.eq(messagingQos))).thenReturn(connectorInvocationHandler);
    MyBroadcastSubscriptionListener broadcastSubscriptionListener = mock(MyBroadcastSubscriptionListener.class);
    SubscriptionQos subscriptionQos = mock(SubscriptionQos.class);
    Method subscribeMethod = MyBroadcastInterface.class.getMethod("subscribeToMyMulticast", MyBroadcastSubscriptionListener.class, SubscriptionQos.class, String[].class);
    Object[] args = new Object[] { broadcastSubscriptionListener, subscriptionQos, new String[] { "one", "two", "three" } };
    ArbitrationResult arbitrationResult = new ArbitrationResult();
    DiscoveryEntryWithMetaInfo discoveryEntry = new DiscoveryEntryWithMetaInfo();
    discoveryEntry.setParticipantId("participantId");
    arbitrationResult.setDiscoveryEntries(Sets.newHashSet(discoveryEntry));
    proxyInvocationHandler.createConnector(arbitrationResult);
    proxyInvocationHandler.invoke(subscribeMethod, args);
    ArgumentCaptor<MulticastSubscribeInvocation> captor = ArgumentCaptor.forClass(MulticastSubscribeInvocation.class);
    verify(connectorInvocationHandler).executeSubscriptionMethod(captor.capture());
    MulticastSubscribeInvocation multicastSubscribeInvocation = captor.getValue();
    assertNotNull(multicastSubscribeInvocation);
    assertArrayEquals(new String[] { "one", "two", "three" }, multicastSubscribeInvocation.getPartitions());
}
Also used : ArbitrationResult(io.joynr.arbitration.ArbitrationResult) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) MulticastSubscribeInvocation(io.joynr.proxy.invocation.MulticastSubscribeInvocation) Method(java.lang.reflect.Method) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) Test(org.junit.Test)

Aggregations

SubscriptionQos (io.joynr.pubsub.SubscriptionQos)25 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)18 Test (org.junit.Test)17 MessagingQos (io.joynr.messaging.MessagingQos)10 PeriodicSubscriptionQos (joynr.PeriodicSubscriptionQos)10 SubscriptionRequest (joynr.SubscriptionRequest)8 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)7 Matchers.anyString (org.mockito.Matchers.anyString)7 OnChangeWithKeepAliveSubscriptionQos (joynr.OnChangeWithKeepAliveSubscriptionQos)5 UnicastSubscriptionQos (joynr.UnicastSubscriptionQos)5 Method (java.lang.reflect.Method)4 SubscriptionPublication (joynr.SubscriptionPublication)4 SubscriptionException (io.joynr.exceptions.SubscriptionException)3 AttributeSubscribeInvocation (io.joynr.proxy.invocation.AttributeSubscribeInvocation)3 MulticastSubscriptionQos (joynr.MulticastSubscriptionQos)3 SubscriptionReply (joynr.SubscriptionReply)3 PersistedSubscriptionRequest (io.joynr.dispatching.subscription.PersistedSubscriptionRequest)2 MulticastSubscribeInvocation (io.joynr.proxy.invocation.MulticastSubscribeInvocation)2 AttributeSubscriptionAdapter (io.joynr.pubsub.subscription.AttributeSubscriptionAdapter)2 AttributeSubscriptionListener (io.joynr.pubsub.subscription.AttributeSubscriptionListener)2