use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.
the class CapabilityUtils method getAddressFromGlobalDiscoveryEntry.
public static Address getAddressFromGlobalDiscoveryEntry(GlobalDiscoveryEntry globalDiscoveryEntry) {
if (globalDiscoveryEntry == null || globalDiscoveryEntry.getAddress() == null) {
throw new IllegalArgumentException("Neither globalDiscoveryEntry nor its address can be null.");
}
logger.trace("Attempting to deserialize {} as an Address.", globalDiscoveryEntry.getAddress());
Address result;
try {
result = objectMapper.readValue(globalDiscoveryEntry.getAddress(), Address.class);
} catch (IOException e) {
throw new IllegalArgumentException(format("Global discovery entry address value %s cannot be deserialized as an Address.", globalDiscoveryEntry.getAddress()), e);
}
return result;
}
use of joynr.system.RoutingTypes.Address 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.system.RoutingTypes.Address 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);
}
}
Aggregations