Search in sources :

Example 1 with SubscriptionQos

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

the class CreateSubscriptionTask method subscribeToLocation.

private void subscribeToLocation(GpsProxy proxy) {
    // defines how often an update may be sent
    long minInterval_ms = 1000;
    // defines how long to wait before sending an update even if the value did not
    long periodMs = 10000;
    // change or when onChange is false
    // subscribe for one hour
    long validityMs = 1 * 60 * 60 * 1000;
    // defines how long to wait for an update before publicationMissed is called
    long alertIntervalMs = 20000;
    // time to live for publication messages
    long publicationTtlMs = 20000;
    SubscriptionQos subscriptionQos = new PeriodicSubscriptionQos().setPeriodMs(periodMs).setValidityMs(validityMs).setAlertAfterIntervalMs(alertIntervalMs).setPublicationTtlMs(publicationTtlMs);
    AttributeSubscriptionAdapter<GpsLocation> listener = new AttributeSubscriptionAdapter<GpsLocation>() {

        @Override
        public void onReceive(GpsLocation value) {
            logToOutput("Received subscription update: " + value.toString());
        }

        @Override
        public void onError(JoynrRuntimeException error) {
            logToOutput("error in subscription: " + error.getMessage());
        }
    };
    proxy.subscribeToLocation(listener, subscriptionQos);
}
Also used : AttributeSubscriptionAdapter(io.joynr.pubsub.subscription.AttributeSubscriptionAdapter) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) GpsLocation(joynr.types.Localisation.GpsLocation) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos)

Example 2 with SubscriptionQos

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

the class SubscriptionManagerImpl method registerSubscription.

private void registerSubscription(String fromParticipantId, Set<DiscoveryEntryWithMetaInfo> toDiscoveryEntries, SubscriptionInvocation subscriptionInvocation, RegisterDataAndCreateSubscriptionRequest registerDataAndCreateSubscriptionRequest) {
    if (!subscriptionInvocation.hasSubscriptionId()) {
        subscriptionInvocation.setSubscriptionId(UUID.randomUUID().toString());
    }
    String subscriptionId = subscriptionInvocation.getSubscriptionId();
    subscriptionFutureMap.put(subscriptionId, subscriptionInvocation.getFuture());
    registerSubscription(subscriptionInvocation.getQos(), subscriptionId);
    SubscriptionRequest subscriptionRequest = registerDataAndCreateSubscriptionRequest.execute();
    MessagingQos messagingQos = new MessagingQos();
    SubscriptionQos qos = subscriptionRequest.getQos();
    if (qos.getExpiryDateMs() == SubscriptionQos.NO_EXPIRY_DATE) {
        messagingQos.setTtl_ms(SubscriptionQos.INFINITE_SUBSCRIPTION);
    } else {
        messagingQos.setTtl_ms(qos.getExpiryDateMs() - System.currentTimeMillis());
    }
    dispatcher.sendSubscriptionRequest(fromParticipantId, toDiscoveryEntries, subscriptionRequest, messagingQos);
}
Also used : MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) SubscriptionRequest(joynr.SubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos)

Example 3 with SubscriptionQos

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

the class PublicationManagerImpl method isExpired.

private boolean isExpired(PublicationInformation publicationInformation) {
    SubscriptionQos subscriptionQos = publicationInformation.subscriptionRequest.getQos();
    long subscriptionEndDelay = getSubscriptionEndDelay(subscriptionQos);
    logger.trace("ExpiryDate - System.currentTimeMillis: " + subscriptionEndDelay);
    return (subscriptionEndDelay != SubscriptionQos.NO_EXPIRY_DATE && subscriptionEndDelay <= 0);
}
Also used : OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) UnicastSubscriptionQos(joynr.UnicastSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos)

Example 4 with SubscriptionQos

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

the class ProxyTest method createProxySubscribeToAttributeWithSubscriptionId.

@Test
public void createProxySubscribeToAttributeWithSubscriptionId() throws Exception {
    NavigationProxy proxy = getNavigationProxy();
    long minInterval_ms = 0;
    long expiryDate = System.currentTimeMillis() + 30000;
    long publicationTtl_ms = 5000;
    SubscriptionQos subscriptionQos = new OnChangeSubscriptionQos().setMinIntervalMs(minInterval_ms).setExpiryDateMs(expiryDate).setPublicationTtlMs(publicationTtl_ms);
    abstract class BooleanSubscriptionListener implements AttributeSubscriptionListener<Boolean> {
    }
    String subscriptionId = UUID.randomUUID().toString();
    Future<String> subscriptionId2 = proxy.subscribeToGuidanceActive(subscriptionId, mock(BooleanSubscriptionListener.class), subscriptionQos);
    assertEquals(subscriptionId, subscriptionId2.get());
    ArgumentCaptor<AttributeSubscribeInvocation> subscriptionRequest = ArgumentCaptor.forClass(AttributeSubscribeInvocation.class);
    verify(subscriptionManager, times(1)).registerAttributeSubscription(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), subscriptionRequest.capture());
    assertEquals("guidanceActive", subscriptionRequest.getValue().getAttributeName());
    assertEquals(subscriptionId, subscriptionRequest.getValue().getSubscriptionId());
}
Also used : OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) MulticastSubscriptionQos(joynr.MulticastSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) NavigationProxy(joynr.vehicle.NavigationProxy) Matchers.anyString(org.mockito.Matchers.anyString) AttributeSubscribeInvocation(io.joynr.proxy.invocation.AttributeSubscribeInvocation) AttributeSubscriptionListener(io.joynr.pubsub.subscription.AttributeSubscriptionListener) Test(org.junit.Test)

Example 5 with SubscriptionQos

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

the class SerializationTest method serializeDeserializeSubscriptionRequests.

@Test
public void serializeDeserializeSubscriptionRequests() throws Exception {
    String persistenceFileName = "target/test_persistenceSubscriptionRequests_" + UUID.randomUUID().toString();
    String proxyPid = "proxyPid";
    String providerPid = "providerPid";
    String subscriptionId = "subscriptionId";
    String subscribedToName = "subscribedToName";
    SubscriptionQos qos = new OnChangeSubscriptionQos();
    SubscriptionRequest subscriptionRequest = new SubscriptionRequest(subscriptionId, subscribedToName, qos);
    new File(persistenceFileName).delete();
    FileSubscriptionRequestStorage fileSubscriptionRequestStorage = new FileSubscriptionRequestStorage(persistenceFileName);
    fileSubscriptionRequestStorage.persistSubscriptionRequest(proxyPid, providerPid, subscriptionRequest);
    SetMultimap<String, PersistedSubscriptionRequest> savedSubscriptionRequests = fileSubscriptionRequestStorage.getSavedSubscriptionRequests();
    assertEquals(1, savedSubscriptionRequests.get(providerPid).size());
    PersistedSubscriptionRequest persistedSubscriptionRequest = savedSubscriptionRequests.get(providerPid).iterator().next();
    assertEquals(subscriptionRequest, persistedSubscriptionRequest.getSubscriptonRequest());
    assertEquals(proxyPid, persistedSubscriptionRequest.getProxyParticipantId());
}
Also used : SubscriptionRequest(joynr.SubscriptionRequest) PersistedSubscriptionRequest(io.joynr.dispatching.subscription.PersistedSubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) PersistedSubscriptionRequest(io.joynr.dispatching.subscription.PersistedSubscriptionRequest) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) FileSubscriptionRequestStorage(io.joynr.dispatching.subscription.FileSubscriptionRequestStorage) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) File(java.io.File) 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