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