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);
}
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);
}
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);
}
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());
}
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());
}
Aggregations