Search in sources :

Example 16 with ChannelAddress

use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.

the class ArbitrationTest method testPriorityArbitratorOnChangeSubscriptions.

@Test
public void testPriorityArbitratorOnChangeSubscriptions() throws InterruptedException {
    // Expected provider supports onChangeSubscriptions
    ProviderQos providerQos = new ProviderQos();
    providerQos.setPriority(testPriority);
    providerQos.setSupportsOnChangeSubscriptions(true);
    expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
    DiscoveryEntryWithMetaInfo expectedDiscoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, expectedParticipantId, providerQos, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true);
    capabilitiesList.add(expectedDiscoveryEntry);
    // A provider with a higher priority that does not support onChangeSubscriptions
    ProviderQos providerQos2 = new ProviderQos();
    providerQos2.setPriority(testPriority + 1);
    providerQos2.setSupportsOnChangeSubscriptions(false);
    Address otherEndpointAddress = new ChannelAddress("http://testUrl", "otherChannelId");
    ArrayList<Address> otherEndpointAddresses = new ArrayList<Address>();
    otherEndpointAddresses.add(otherEndpointAddress);
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "wrongParticipantId", providerQos2, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    // A provider with a higher priority that does not support onChangeSubscriptions
    ProviderQos providerQos3 = new ProviderQos();
    providerQos3.setPriority(testPriority + 2);
    providerQos3.setSupportsOnChangeSubscriptions(false);
    Address thirdEndpointAddress = new ChannelAddress("http://testUrl", "thirdChannelId");
    ArrayList<Address> thirdEndpointAddresses = new ArrayList<Address>();
    thirdEndpointAddresses.add(thirdEndpointAddress);
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "thirdParticipantId", providerQos3, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    discoveryQos = new DiscoveryQos(ARBITRATION_TIMEOUT, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE);
    discoveryQos.setProviderMustSupportOnChange(true);
    try {
        Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
        arbitrator.setArbitrationListener(arbitrationCallback);
        arbitrator.scheduleArbitration();
        assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
        ArbitrationResult expectedArbitrationResult = new ArbitrationResult(expectedDiscoveryEntry);
        verify(arbitrationCallback, times(1)).onSuccess(eq(expectedArbitrationResult));
    } catch (DiscoveryException e) {
        fail("A Joyn Arbitration Exception has been thrown");
    }
}
Also used : Address(joynr.system.RoutingTypes.Address) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) Version(joynr.types.Version) ArrayList(java.util.ArrayList) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryException(io.joynr.exceptions.DiscoveryException) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 17 with ChannelAddress

use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.

the class StaticCapabilitiesProvisioning method substituteInProcessAddressIfLocal.

private void substituteInProcessAddressIfLocal(ObjectMapper objectMapper, String localChannelId, GlobalDiscoveryEntry globalDiscoveryEntry, Address address) throws JsonProcessingException {
    if ((address instanceof ChannelAddress && localChannelId.equals(((ChannelAddress) address).getChannelId())) || (address instanceof MqttAddress && localChannelId.equals(((MqttAddress) address).getTopic()))) {
        Address localAddress = new InProcessAddress();
        globalDiscoveryEntry.setAddress(objectMapper.writeValueAsString(localAddress));
    }
}
Also used : ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Address(joynr.system.RoutingTypes.Address) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) MqttAddress(joynr.system.RoutingTypes.MqttAddress)

Example 18 with ChannelAddress

use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.

the class LegacyCapabilitiesProvisioning method createDiscoveryEntryFor.

private void createDiscoveryEntryFor(Class<?> interfaceClass, String interfaceName, String channelId, String participantId, String urlForAddress, String localChannelId, String domain) {
    boolean hasUrl = isPresent(urlForAddress);
    boolean hasParticipantId = isPresent(participantId);
    if (hasUrl && !hasParticipantId) {
        throw new IllegalArgumentException(format("When configuring the discovery directory or domain access controller " + "via properties, you must provide both a URL and a participant ID per service.%n" + "You provided the URL '%s' and the participant ID '%s' for the service %s.%n" + "Please complete the configuration and restart the application.", urlForAddress, participantId, interfaceName));
    }
    if (hasParticipantId && hasUrl && isPresent(channelId) && isPresent(domain)) {
        Address address;
        if (localChannelId.equals(channelId)) {
            address = new InProcessAddress();
        } else if (urlForAddress.startsWith("tcp") || urlForAddress.startsWith("mqtt")) {
            address = new MqttAddress(urlForAddress, channelId);
        } else {
            address = new ChannelAddress(urlForAddress, channelId);
        }
        DiscoveryEntry discoveryEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), domain, interfaceName, participantId, new ProviderQos(), System.currentTimeMillis(), Long.MAX_VALUE, "", address);
        logger.debug("Created legacy discovery entry: {}", discoveryEntry);
        legacyDiscoveryEntries.put(interfaceClass, discoveryEntry);
        legacyAddresses.put(interfaceClass, address);
    } else {
        logger.trace("Insufficient properties data to create entry for interface {}", interfaceName);
    }
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Address(joynr.system.RoutingTypes.Address) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) Version(joynr.types.Version) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) ProviderQos(joynr.types.ProviderQos) MqttAddress(joynr.system.RoutingTypes.MqttAddress)

Example 19 with ChannelAddress

use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.

the class GlobalCapabilitiesDirectoryEjb method add.

@Override
public void add(GlobalDiscoveryEntry globalDiscoveryEntry) {
    logger.debug("Adding global discovery entry {}", globalDiscoveryEntry);
    Address address = CapabilityUtils.getAddressFromGlobalDiscoveryEntry(globalDiscoveryEntry);
    String clusterControllerId;
    if (address instanceof MqttAddress) {
        clusterControllerId = ((MqttAddress) address).getTopic();
    } else if (address instanceof ChannelAddress) {
        clusterControllerId = ((ChannelAddress) address).getChannelId();
    } else {
        clusterControllerId = String.valueOf(address);
    }
    GlobalDiscoveryEntryPersisted entity = new GlobalDiscoveryEntryPersisted(globalDiscoveryEntry, clusterControllerId);
    GlobalDiscoveryEntryPersisted persisted = entityManager.find(GlobalDiscoveryEntryPersisted.class, entity.getParticipantId());
    if (persisted == null) {
        entityManager.persist(entity);
    } else {
        entityManager.merge(entity);
    }
}
Also used : ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Address(joynr.system.RoutingTypes.Address) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) GlobalDiscoveryEntryPersisted(io.joynr.capabilities.GlobalDiscoveryEntryPersisted) MqttAddress(joynr.system.RoutingTypes.MqttAddress)

Example 20 with ChannelAddress

use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.

the class CcMessageRouterTest method testNoMessageDuplicationForMulticastForMultipleAddressesWithErrorFromStub.

@Test
public void testNoMessageDuplicationForMulticastForMultipleAddressesWithErrorFromStub() throws Exception {
    ChannelAddress receiverAddress1 = new ChannelAddress("http://testUrl", "channelId1");
    ChannelAddress receiverAddress2 = new ChannelAddress("http://testUrl", "channelId2");
    prepareMulticastForMultipleAddresses(receiverAddress1, receiverAddress2);
    ImmutableMessage immutableMessage = joynrMessage.getImmutableMessage();
    doAnswer(new Answer<Void>() {

        private int callCount = 0;

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            FailureAction failureAction = invocation.getArgumentAt(2, FailureAction.class);
            if (callCount < 2) {
                callCount++;
                failureAction.execute(new JoynrDelayMessageException(10, "first retry"));
            } else {
                failureAction.execute(new JoynrMessageNotSentException("do not retry twice"));
            }
            return null;
        }
    }).when(messagingStubMock).transmit(eq(immutableMessage), any(SuccessAction.class), any(FailureAction.class));
    messageRouter.route(immutableMessage);
    Thread.sleep(1000);
    verify(messagingStubMock, times(4)).transmit(eq(immutableMessage), any(SuccessAction.class), any(FailureAction.class));
    verify(middlewareMessagingStubFactoryMock, times(2)).create(receiverAddress1);
    verify(middlewareMessagingStubFactoryMock, times(2)).create(receiverAddress2);
}
Also used : FailureAction(io.joynr.messaging.FailureAction) SuccessAction(io.joynr.messaging.SuccessAction) JoynrDelayMessageException(io.joynr.exceptions.JoynrDelayMessageException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ImmutableMessage(joynr.ImmutableMessage) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) JoynrMessageNotSentException(io.joynr.exceptions.JoynrMessageNotSentException) Test(org.junit.Test)

Aggregations

ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)22 ProviderQos (joynr.types.ProviderQos)12 Version (joynr.types.Version)12 Test (org.junit.Test)12 Address (joynr.system.RoutingTypes.Address)10 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)9 DiscoveryException (io.joynr.exceptions.DiscoveryException)6 MqttAddress (joynr.system.RoutingTypes.MqttAddress)6 HashSet (java.util.HashSet)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 CustomParameter (joynr.types.CustomParameter)4 DiscoveryEntry (joynr.types.DiscoveryEntry)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 FailureAction (io.joynr.messaging.FailureAction)3 SuccessAction (io.joynr.messaging.SuccessAction)3 InProcessAddress (io.joynr.messaging.inprocess.InProcessAddress)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3