use of joynr.PeriodicSubscriptionQos 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 joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.
the class ConnectorTest method subscriptionMethodCallWithNoExpiryDate.
@Test
public void subscriptionMethodCallWithNoExpiryDate() throws JoynrIllegalStateException {
ConnectorInvocationHandler connector = createConnector();
assertNotNull(connector);
try {
Future<String> future = new Future<String>();
String subscriptionId = "subscriptionId";
PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
subscriptionQos.setPeriodMs(1000).setExpiryDateMs(0).setAlertAfterIntervalMs(1000);
AttributeSubscriptionListener<GpsPosition> listener = new AttributeSubscriptionAdapter<GpsPosition>();
Object[] args = new Object[] { listener, subscriptionQos, subscriptionId };
Method method = LocalisationSubscriptionInterface.class.getDeclaredMethod("subscribeToGPSPosition", String.class, AttributeSubscriptionListener.class, SubscriptionQos.class);
AttributeSubscribeInvocation attributeSubscription = new AttributeSubscribeInvocation(method, args, future);
connector.executeSubscriptionMethod(attributeSubscription);
verify(subscriptionManager, times(1)).registerAttributeSubscription(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), eq(attributeSubscription));
} catch (Exception e) {
// This is what is supposed to happen -> no error handling
fail("Calling a subscription method with no expiry date throws an exception.");
}
}
use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.
the class AbstractSubscriptionEnd2EndTest method registerSubscriptionForComplexDatatype.
@SuppressWarnings("unchecked")
@Test
public void registerSubscriptionForComplexDatatype() throws InterruptedException, ApplicationException {
final Semaphore onReceiveSemaphore = new Semaphore(0);
AttributeSubscriptionListener<GpsLocation> gpsListener = mock(AttributeSubscriptionListener.class);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
onReceiveSemaphore.release();
return null;
}
}).when(gpsListener).onReceive(eq(provider.getComplexTestAttributeSync()));
int periods = 2;
long subscriptionDuration = (PERIOD_MS * periods) + EXPECTED_LATENCY_MS;
PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
subscriptionQos.setPeriodMs(PERIOD_MS);
subscriptionQos.setValidityMs(subscriptionDuration);
subscriptionQos.setAlertAfterIntervalMs(500);
subscriptionQos.setPublicationTtlMs(0);
Future<String> subscriptionId = proxy.subscribeToComplexTestAttribute(gpsListener, subscriptionQos);
assertTrue(onReceiveSemaphore.tryAcquire(periods, subscriptionDuration + 1000, TimeUnit.MILLISECONDS));
verify(gpsListener, times(0)).onError(null);
proxy.unsubscribeFromComplexTestAttribute(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
}
use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.
the class AbstractSubscriptionEnd2EndTest method subscribeToEnumAttribute.
@SuppressWarnings("unchecked")
@Test
public void subscribeToEnumAttribute() throws InterruptedException, ApplicationException {
final Semaphore onReceiveSemaphore = new Semaphore(0);
AttributeSubscriptionListener<TestEnum> testEnumListener = mock(AttributeSubscriptionListener.class);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
onReceiveSemaphore.release();
return null;
}
}).when(testEnumListener).onReceive(any(TestEnum.class));
TestEnum expectedTestEnum = TestEnum.TWO;
provider.setEnumAttribute(expectedTestEnum);
int periods = 2;
long subscriptionDuration = (PERIOD_MS * periods) + EXPECTED_LATENCY_MS;
PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
subscriptionQos.setPeriodMs(PERIOD_MS);
subscriptionQos.setValidityMs(subscriptionDuration);
subscriptionQos.setAlertAfterIntervalMs(500);
subscriptionQos.setPublicationTtlMs(0);
Future<String> subscriptionId = proxy.subscribeToEnumAttribute(testEnumListener, subscriptionQos);
assertTrue(onReceiveSemaphore.tryAcquire(periods, subscriptionDuration + 1000, TimeUnit.MILLISECONDS));
verify(testEnumListener, times(0)).onError(null);
proxy.unsubscribeFromEnumAttribute(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
}
use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.
the class PublicationManagerTest method restorePublications.
@SuppressWarnings("unchecked")
@Test(timeout = 3000)
public void restorePublications() throws Exception {
int period = 200;
String subscriptionId1 = "subscriptionid1";
String subscriptionId2 = "subscriptionid2";
long validityMs = 3000;
SubscriptionQos qosNoExpiry = new PeriodicSubscriptionQos().setPeriodMs(100).setExpiryDateMs(SubscriptionQos.NO_EXPIRY_DATE).setAlertAfterIntervalMs(500).setPublicationTtlMs(1000);
SubscriptionQos qosExpires = new PeriodicSubscriptionQos().setPeriodMs(100).setValidityMs(validityMs).setAlertAfterIntervalMs(500).setPublicationTtlMs(1000);
SubscriptionRequest subscriptionRequest1 = new SubscriptionRequest(subscriptionId1, "location", qosNoExpiry);
SubscriptionRequest subscriptionRequest2 = new SubscriptionRequest(subscriptionId2, "location", qosExpires);
publicationManager.addSubscriptionRequest(PROXY_PARTICIPANT_ID, PROVIDER_PARTICIPANT_ID, subscriptionRequest1);
publicationManager.addSubscriptionRequest(PROXY_PARTICIPANT_ID, PROVIDER_PARTICIPANT_ID, subscriptionRequest2);
Thread.sleep(period);
verify(dispatcher, times(0)).sendSubscriptionPublication(eq(PROVIDER_PARTICIPANT_ID), (Set<String>) argThat(contains(PROXY_PARTICIPANT_ID)), any(SubscriptionPublication.class), any(MessagingQos.class));
publicationManager.entryAdded(PROVIDER_PARTICIPANT_ID, providerContainer);
verify(dispatcher, timeout(period * 5).times(12)).sendSubscriptionPublication(eq(PROVIDER_PARTICIPANT_ID), (Set<String>) argThat(contains(PROXY_PARTICIPANT_ID)), any(SubscriptionPublication.class), any(MessagingQos.class));
}
Aggregations