Search in sources :

Example 61 with DiscoveryEntryWithMetaInfo

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

the class LocalCapabilitiesDirectoryTest method testLookupByParticipantId_globalEntry_DiscoveryEntryWithMetaInfoContainsExpectedIsLocalValue.

@Test
public void testLookupByParticipantId_globalEntry_DiscoveryEntryWithMetaInfoContainsExpectedIsLocalValue() {
    String participantId = "participantId";
    String interfaceName = "interfaceName";
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_THEN_GLOBAL);
    // remote global DiscoveryEntry
    String remoteGlobalDomain = "remoteglobaldomain";
    final GlobalDiscoveryEntry remoteGlobalEntry = new GlobalDiscoveryEntry(new Version(0, 0), remoteGlobalDomain, interfaceName, participantId, new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 10000L, "publicKeyId", channelAddressSerialized);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            Callback<GlobalDiscoveryEntry> callback = (Callback<GlobalDiscoveryEntry>) invocation.getArguments()[0];
            callback.onSuccess(remoteGlobalEntry);
            return null;
        }
    }).when(globalCapabilitiesClient).lookup(any(Callback.class), eq(participantId), anyLong());
    DiscoveryEntryWithMetaInfo capturedRemoteGlobalEntry = localCapabilitiesDirectory.lookup(participantId, discoveryQos);
    DiscoveryEntryWithMetaInfo remoteGlobalEntryWithMetaInfo = CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(false, remoteGlobalEntry);
    assertEquals(remoteGlobalEntryWithMetaInfo, capturedRemoteGlobalEntry);
}
Also used : Callback(io.joynr.proxy.Callback) Version(joynr.types.Version) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Matchers.anyString(org.mockito.Matchers.anyString) DeferredVoid(io.joynr.provider.DeferredVoid) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 62 with DiscoveryEntryWithMetaInfo

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

the class LocalCapabilitiesDirectoryImpl method lookup.

@Override
public Promise<Lookup1Deferred> lookup(String[] domains, String interfaceName, joynr.types.DiscoveryQos discoveryQos) {
    final Lookup1Deferred deferred = new Lookup1Deferred();
    CapabilitiesCallback callback = new CapabilitiesCallback() {

        @Override
        public void processCapabilitiesReceived(@CheckForNull Collection<DiscoveryEntryWithMetaInfo> capabilities) {
            if (capabilities == null) {
                deferred.reject(new ProviderRuntimeException("Received capablities collection was null"));
            } else {
                deferred.resolve(capabilities.toArray(new DiscoveryEntryWithMetaInfo[capabilities.size()]));
            }
        }

        @Override
        public void onError(Throwable e) {
            deferred.reject(new ProviderRuntimeException(e.toString()));
        }
    };
    DiscoveryScope discoveryScope = DiscoveryScope.valueOf(discoveryQos.getDiscoveryScope().name());
    lookup(domains, interfaceName, new DiscoveryQos(discoveryQos.getDiscoveryTimeout(), defaultDiscoveryRetryInterval, ArbitrationStrategy.NotSet, discoveryQos.getCacheMaxAge(), discoveryScope), callback);
    return new Promise<>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DiscoveryScope(io.joynr.arbitration.DiscoveryScope) CheckForNull(javax.annotation.CheckForNull) Collection(java.util.Collection) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos)

Example 63 with DiscoveryEntryWithMetaInfo

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

the class LocalCapabilitiesDirectoryImpl method lookup.

@Override
public void lookup(final String[] domains, final String interfaceName, final DiscoveryQos discoveryQos, final CapabilitiesCallback capabilitiesCallback) {
    DiscoveryScope discoveryScope = discoveryQos.getDiscoveryScope();
    Set<DiscoveryEntry> localDiscoveryEntries = getLocalEntriesIfRequired(discoveryScope, domains, interfaceName);
    Set<DiscoveryEntryWithMetaInfo> globalDiscoveryEntries = getGloballyCachedEntriesIfRequired(discoveryScope, domains, interfaceName, discoveryQos.getCacheMaxAgeMs());
    switch(discoveryScope) {
        case LOCAL_ONLY:
            capabilitiesCallback.processCapabilitiesReceived(CapabilityUtils.convertToDiscoveryEntryWithMetaInfoSet(true, localDiscoveryEntries));
            break;
        case LOCAL_THEN_GLOBAL:
            handleLocalThenGlobal(domains, interfaceName, discoveryQos, capabilitiesCallback, CapabilityUtils.convertToDiscoveryEntryWithMetaInfoSet(true, localDiscoveryEntries), globalDiscoveryEntries);
            break;
        case GLOBAL_ONLY:
            handleGlobalOnly(domains, interfaceName, discoveryQos, capabilitiesCallback, globalDiscoveryEntries);
            break;
        case LOCAL_AND_GLOBAL:
            handleLocalAndGlobal(domains, interfaceName, discoveryQos, capabilitiesCallback, CapabilityUtils.convertToDiscoveryEntryWithMetaInfoSet(true, localDiscoveryEntries), globalDiscoveryEntries);
            break;
        default:
            throw new IllegalStateException("Unknown or illegal DiscoveryScope value: " + discoveryScope);
    }
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) DiscoveryScope(io.joynr.arbitration.DiscoveryScope) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo)

Example 64 with DiscoveryEntryWithMetaInfo

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

the class FixedParticipantArbitrationStrategyFunction method select.

@Override
public Set<DiscoveryEntryWithMetaInfo> select(Map<String, String> parameters, Collection<DiscoveryEntryWithMetaInfo> capabilities) {
    String participantId = parameters.get(ArbitrationConstants.FIXEDPARTICIPANT_KEYWORD);
    logger.trace("starting select Provider by participant Id: {}", participantId);
    DiscoveryEntryWithMetaInfo capabilityWithParticipantId = null;
    for (DiscoveryEntryWithMetaInfo discoveryEntry : capabilities) {
        if (discoveryEntry.getParticipantId().equals(participantId)) {
            capabilityWithParticipantId = discoveryEntry;
            break;
        }
    }
    logger.trace("capability with participantId: {}: {}" + participantId, capabilityWithParticipantId);
    return capabilityWithParticipantId == null ? null : Sets.newHashSet(capabilityWithParticipantId);
}
Also used : DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo)

Example 65 with DiscoveryEntryWithMetaInfo

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

the class DiscoveryEntryVersionFilter method filter.

/**
 * Reduces the passed in set of {@link DiscoveryEntry discovery entries} by
 * removing all of those entries which are incompatible with the specified
 * caller {@link Version}.
 *
 * @param callerVersion the version of the caller. Must not be <code>null</code>.
 * @param discoveryEntries the discovery entries which are to be filtered by versions.
 * Must not be <code>null</code>.
 * @param discoveredVersions a container into which the method will write all
 * versions it comes across during the filtering keyed by the domain for which the version was found.
 * Mainly provided so that the iteration only occurs once.
 * If <code>null</code>, then it is ignored.
 *
 * @return the filtered discovery entry set.
 */
public Set<DiscoveryEntryWithMetaInfo> filter(Version callerVersion, Set<DiscoveryEntryWithMetaInfo> discoveryEntries, Map<String, Set<Version>> discoveredVersions) {
    if (callerVersion == null || discoveryEntries == null) {
        throw new IllegalArgumentException(String.format("Neither callerVersion (%s) nor discoveryEntries (%s) can be null.", callerVersion, discoveryEntries));
    }
    Iterator<DiscoveryEntryWithMetaInfo> iterator = discoveryEntries.iterator();
    while (iterator.hasNext()) {
        DiscoveryEntry discoveryEntry = iterator.next();
        if (discoveredVersions != null) {
            Set<Version> versionsByDomain = discoveredVersions.get(discoveryEntry.getDomain());
            if (versionsByDomain == null) {
                versionsByDomain = new HashSet<>();
                discoveredVersions.put(discoveryEntry.getDomain(), versionsByDomain);
            }
            versionsByDomain.add(discoveryEntry.getProviderVersion());
        }
        if (!versionCompatibilityChecker.check(callerVersion, discoveryEntry.getProviderVersion())) {
            iterator.remove();
        }
    }
    return discoveryEntries;
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) Version(joynr.types.Version) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo)

Aggregations

DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)66 Test (org.junit.Test)32 Version (joynr.types.Version)29 ProviderQos (joynr.types.ProviderQos)24 DiscoveryEntry (joynr.types.DiscoveryEntry)16 HashSet (java.util.HashSet)14 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)13 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)11 Matchers.anyString (org.mockito.Matchers.anyString)10 InvocationOnMock (org.mockito.invocation.InvocationOnMock)10 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)9 Before (org.junit.Before)9 DiscoveryException (io.joynr.exceptions.DiscoveryException)7 MessagingQos (io.joynr.messaging.MessagingQos)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 Set (java.util.Set)7 Callback (io.joynr.proxy.Callback)6 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)5 Collection (java.util.Collection)5