use of joynr.SubscriptionRequest 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 joynr.SubscriptionRequest in project joynr by bmwcarit.
the class SubscriptionManagerImpl method registerMulticastSubscription.
@Override
public void registerMulticastSubscription(String fromParticipantId, Set<DiscoveryEntryWithMetaInfo> toDiscoveryEntries, final MulticastSubscribeInvocation multicastSubscribeInvocation) {
for (DiscoveryEntryWithMetaInfo toDiscoveryEntry : toDiscoveryEntries) {
final String multicastId = MulticastIdUtil.createMulticastId(toDiscoveryEntry.getParticipantId(), multicastSubscribeInvocation.getSubscriptionName(), multicastSubscribeInvocation.getPartitions());
logger.debug("SUBSCRIPTION call proxy: subscriptionId: {}, multicastId: {}, broadcast: {}, qos: {}," + " proxy participantId: {}, provider participantId: {}", multicastSubscribeInvocation.getSubscriptionId(), multicastId, multicastSubscribeInvocation.getSubscriptionName(), multicastSubscribeInvocation.getQos(), fromParticipantId, toDiscoveryEntry.getParticipantId());
registerSubscription(fromParticipantId, toDiscoveryEntries, multicastSubscribeInvocation, new RegisterDataAndCreateSubscriptionRequest() {
@Override
public SubscriptionRequest execute() {
String subscriptionId = multicastSubscribeInvocation.getSubscriptionId();
logger.trace("Multicast subscription registered with Id: " + subscriptionId);
Pattern multicastIdPattern = multicastWildcardRegexFactory.createIdPattern(multicastId);
if (!multicastSubscribersDirectory.containsKey(multicastIdPattern)) {
multicastSubscribersDirectory.putIfAbsent(multicastIdPattern, Sets.<String>newHashSet());
}
multicastSubscribersDirectory.get(multicastIdPattern).add(subscriptionId);
multicastBroadcastTypes.putIfAbsent(multicastIdPattern, multicastSubscribeInvocation.getOutParameterTypes());
broadcastSubscriptionListenerDirectory.put(subscriptionId, multicastSubscribeInvocation.getListener());
return new MulticastSubscriptionRequest(multicastId, multicastSubscribeInvocation.getSubscriptionId(), multicastSubscribeInvocation.getSubscriptionName(), multicastSubscribeInvocation.getQos());
}
});
}
}
use of joynr.SubscriptionRequest 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());
}
use of joynr.SubscriptionRequest in project joynr by bmwcarit.
the class SerializationTest method serializeSubscriptionRequest.
@Test
public void serializeSubscriptionRequest() throws JsonGenerationException, JsonMappingException, IOException {
String subscriptionId = "1234";
String subscribedToName = "myAttribute";
long expiryDate = System.currentTimeMillis() + 60000;
SubscriptionQos qos = new OnChangeSubscriptionQos().setMinIntervalMs(0).setExpiryDateMs(expiryDate).setPublicationTtlMs(1000);
SubscriptionRequest request = new SubscriptionRequest(subscriptionId, subscribedToName, qos);
String writeValueAsString = objectMapper.writeValueAsString(request);
SubscriptionRequest receivedRequest = objectMapper.readValue(writeValueAsString, SubscriptionRequest.class);
Assert.assertEquals(request, receivedRequest);
}
use of joynr.SubscriptionRequest in project joynr by bmwcarit.
the class TtlUpliftTest method testTtlUpliftMs_SubscriptionRequest.
@Test
public void testTtlUpliftMs_SubscriptionRequest() {
SubscriptionRequest subscriptionRequest = new SubscriptionRequest();
expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
MutableMessage message = messageFactoryWithTtlUplift.createSubscriptionRequest(fromParticipantId, toParticipantId, subscriptionRequest, messagingQos);
long expiryDateValue = expiryDate.getValue() + TTL_UPLIFT_MS;
MutableMessageFactoryTest.assertExpiryDateEquals(expiryDateValue, message);
}
Aggregations