Search in sources :

Example 1 with SubscriptionRequest

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);
}
Also used : MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) SubscriptionRequest(joynr.SubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos)

Example 2 with SubscriptionRequest

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());
            }
        });
    }
}
Also used : Pattern(java.util.regex.Pattern) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) SubscriptionRequest(joynr.SubscriptionRequest) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest)

Example 3 with SubscriptionRequest

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

Example 4 with SubscriptionRequest

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);
}
Also used : SubscriptionRequest(joynr.SubscriptionRequest) PersistedSubscriptionRequest(io.joynr.dispatching.subscription.PersistedSubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) Test(org.junit.Test)

Example 5 with SubscriptionRequest

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);
}
Also used : SubscriptionRequest(joynr.SubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) MutableMessage(joynr.MutableMessage) Test(org.junit.Test)

Aggregations

SubscriptionRequest (joynr.SubscriptionRequest)32 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)24 Test (org.junit.Test)24 MessagingQos (io.joynr.messaging.MessagingQos)23 SubscriptionPublication (joynr.SubscriptionPublication)22 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)19 Matchers.anyString (org.mockito.Matchers.anyString)18 PeriodicSubscriptionQos (joynr.PeriodicSubscriptionQos)8 SubscriptionQos (io.joynr.pubsub.SubscriptionQos)7 BroadcastFilter (io.joynr.pubsub.publication.BroadcastFilter)6 joynr.tests.testLocationUpdateSelectiveBroadcastFilter (joynr.tests.testLocationUpdateSelectiveBroadcastFilter)6 joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter (joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter)6 ProviderDirectory (io.joynr.dispatching.ProviderDirectory)5 MulticastSubscriptionRequest (joynr.MulticastSubscriptionRequest)5 ArrayList (java.util.ArrayList)4 SubscriptionReply (joynr.SubscriptionReply)4 joynr.tests.testBroadcastInterface (joynr.tests.testBroadcastInterface)4 GpsLocation (joynr.types.Localisation.GpsLocation)4 MutableMessage (joynr.MutableMessage)3 OnChangeWithKeepAliveSubscriptionQos (joynr.OnChangeWithKeepAliveSubscriptionQos)3