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