Search in sources :

Example 41 with Address

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;
}
Also used : Address(joynr.system.RoutingTypes.Address) IOException(java.io.IOException)

Example 42 with Address

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);
    }
}
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 43 with Address

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

Aggregations

Address (joynr.system.RoutingTypes.Address)43 Test (org.junit.Test)21 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)15 MqttAddress (joynr.system.RoutingTypes.MqttAddress)13 ProviderQos (joynr.types.ProviderQos)9 Version (joynr.types.Version)9 InProcessAddress (io.joynr.messaging.inprocess.InProcessAddress)7 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)6 TypeLiteral (com.google.inject.TypeLiteral)5 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)5 AbstractModule (com.google.inject.AbstractModule)4 HashSet (java.util.HashSet)4 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)4 DiscoveryException (io.joynr.exceptions.DiscoveryException)3 AbstractMiddlewareMessagingStubFactory (io.joynr.messaging.AbstractMiddlewareMessagingStubFactory)3 IMessagingSkeleton (io.joynr.messaging.IMessagingSkeleton)3 IMessagingStub (io.joynr.messaging.IMessagingStub)3 CcMessageRouter (io.joynr.messaging.routing.CcMessageRouter)3 ArrayList (java.util.ArrayList)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2