Search in sources :

Example 41 with DiscoveryEntry

use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.

the class StaticCapabilitiesProvisioningTest method testLoadingSerializedDiscoveryEntriesNoLegacy.

@Test
public void testLoadingSerializedDiscoveryEntriesNoLegacy() throws Exception {
    Set<DiscoveryEntry> discoveryEntries = createDiscoveryEntries("io.joynr", GlobalCapabilitiesDirectory.INTERFACE_NAME, GlobalDomainAccessController.INTERFACE_NAME);
    final String serializedDiscoveryEntries = objectMapper.writeValueAsString(discoveryEntries);
    Injector injector = createInjectorForJsonValue(serializedDiscoveryEntries);
    CapabilitiesProvisioning subject = injector.getInstance(CapabilitiesProvisioning.class);
    Collection<DiscoveryEntry> provisionedDiscoveryEntries = subject.getDiscoveryEntries();
    assertEquals(2, provisionedDiscoveryEntries.size());
    assertContainsEntryFor(provisionedDiscoveryEntries, GlobalCapabilitiesDirectory.INTERFACE_NAME);
    assertContainsEntryFor(provisionedDiscoveryEntries, GlobalDomainAccessController.INTERFACE_NAME);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Injector(com.google.inject.Injector) Test(org.junit.Test)

Example 42 with DiscoveryEntry

use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.

the class StaticCapabilitiesProvisioningTest method testLoadingExtraSerializedDiscoveryEntriesPlusLegacy.

@Test
public void testLoadingExtraSerializedDiscoveryEntriesPlusLegacy() throws Exception {
    Set<DiscoveryEntry> discoveryEntries = createDiscoveryEntries("domain", "interfaceName1", "interfaceName2");
    LegacyCapabilitiesProvisioning.LegacyProvisioningPropertiesHolder properties = createLegacyProvisioningPropertiesHolder();
    final String serializedDiscoveryEntries = objectMapper.writeValueAsString(discoveryEntries);
    logger.debug("Serialised entries: " + serializedDiscoveryEntries);
    Injector injector = createInjectorForJsonValue(serializedDiscoveryEntries, properties);
    CapabilitiesProvisioning subject = injector.getInstance(CapabilitiesProvisioning.class);
    Collection<DiscoveryEntry> provisionedDiscoveryEntries = subject.getDiscoveryEntries();
    assertEquals(4, provisionedDiscoveryEntries.size());
    assertContainsEntryFor(provisionedDiscoveryEntries, "interfaceName1");
    assertContainsEntryFor(provisionedDiscoveryEntries, "interfaceName2");
    assertContainsEntryFor(provisionedDiscoveryEntries, GlobalCapabilitiesDirectory.INTERFACE_NAME);
    assertContainsEntryFor(provisionedDiscoveryEntries, GlobalDomainAccessController.INTERFACE_NAME);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Injector(com.google.inject.Injector) Test(org.junit.Test)

Example 43 with DiscoveryEntry

use of joynr.types.DiscoveryEntry 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 44 with DiscoveryEntry

use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.

the class DiscoveryEntryStoreInMemory method removeDiscoveryEntryFromStore.

private boolean removeDiscoveryEntryFromStore(String participantId) {
    String discoveryEntryId = participantIdToCapabilityMapping.get(participantId);
    if (discoveryEntryId == null) {
        return false;
    }
    DiscoveryEntry capability = capabilityKeyToCapabilityMapping.get(discoveryEntryId);
    if (capability == null) {
        return false;
    }
    String domainInterfaceId = domainInterfaceKey(capability.getDomain(), capability.getInterfaceName());
    DiscoveryEntry entry = capabilityKeyToCapabilityMapping.remove(discoveryEntryId);
    // check if a discoveryEntry with the same ID already exists
    if (entry == null) {
        return false;
    }
    // update time mapping
    registeredCapabilitiesTime.remove(discoveryEntryId);
    // update interfaceDomain to capability mapping
    List<String> mapping = interfaceAddressToCapabilityMapping.get(domainInterfaceId);
    if (mapping != null) {
        if (!mapping.remove(discoveryEntryId)) {
            logger.error("Could not find capability to remove from interfaceDomainToCapabilityMapping: {}", discoveryEntryId);
        }
        if (mapping.isEmpty()) {
            interfaceAddressToCapabilityMapping.remove(domainInterfaceId);
        }
    } else {
        logger.error("Could not find capability to remove from interfaceDomainToCapabilityMapping: {}", discoveryEntryId);
    }
    // update participantId to capability mapping
    if (participantIdToCapabilityMapping.remove(participantId) == null) {
        logger.error("Could not find capability to remove from participantIdToCapabilityMapping: {}", discoveryEntryId);
    }
    return true;
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry)

Example 45 with DiscoveryEntry

use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.

the class DiscoveryEntryStoreInMemory method lookup.

@Override
@CheckForNull
public DiscoveryEntry lookup(String participantId, long cacheMaxAge) {
    synchronized (storeLock) {
        String discoveryEntryId = participantIdToCapabilityMapping.get(participantId);
        if (discoveryEntryId == null) {
            return null;
        }
        DiscoveryEntry discoveryEntry = capabilityKeyToCapabilityMapping.get(discoveryEntryId);
        logger.debug("Capability for participantId {} found: {}", participantId, discoveryEntry);
        if (discoveryEntry instanceof GlobalDiscoveryEntry && !checkAge(registeredCapabilitiesTime.get(discoveryEntryId), cacheMaxAge)) {
            return null;
        }
        return discoveryEntry;
    }
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) CheckForNull(javax.annotation.CheckForNull)

Aggregations

DiscoveryEntry (joynr.types.DiscoveryEntry)60 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)43 Test (org.junit.Test)30 ProviderQos (joynr.types.ProviderQos)25 Version (joynr.types.Version)22 Callback (io.joynr.proxy.Callback)18 Matchers.anyString (org.mockito.Matchers.anyString)17 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)16 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)15 ArrayList (java.util.ArrayList)14 HashSet (java.util.HashSet)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)9 DeferredVoid (io.joynr.provider.DeferredVoid)7 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)6 MqttAddress (joynr.system.RoutingTypes.MqttAddress)6 Injector (com.google.inject.Injector)5 MessagingQos (io.joynr.messaging.MessagingQos)4 Future (io.joynr.proxy.Future)4 CheckForNull (javax.annotation.CheckForNull)4 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)4