use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.
the class LocalCapabilitiesDirectoryImpl method shutdown.
@Override
public void shutdown(boolean unregisterAllRegisteredCapabilities) {
freshnessUpdateScheduler.shutdownNow();
if (unregisterAllRegisteredCapabilities) {
Set<DiscoveryEntry> allDiscoveryEntries = localDiscoveryEntryStore.getAllDiscoveryEntries();
List<DiscoveryEntry> discoveryEntries = new ArrayList<>(allDiscoveryEntries.size());
for (DiscoveryEntry capabilityEntry : allDiscoveryEntries) {
if (capabilityEntry.getQos().getScope() == ProviderScope.GLOBAL) {
discoveryEntries.add(capabilityEntry);
}
}
if (discoveryEntries.size() > 0) {
try {
Function<? super DiscoveryEntry, String> transfomerFct = new Function<DiscoveryEntry, String>() {
@Override
public String apply(DiscoveryEntry input) {
return input != null ? input.getParticipantId() : null;
}
};
Callback<Void> callback = new Callback<Void>() {
@Override
public void onFailure(JoynrRuntimeException error) {
}
@Override
public void onSuccess(Void result) {
}
};
globalCapabilitiesDirectoryClient.remove(callback, Lists.newArrayList(Collections2.transform(discoveryEntries, transfomerFct)));
} catch (DiscoveryException e) {
logger.debug("error removing discovery entries", e);
}
}
}
}
use of joynr.types.DiscoveryEntry 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.DiscoveryEntry in project joynr by bmwcarit.
the class LocalCapabilitiesDirectoryImpl method lookup.
@Override
@CheckForNull
public void lookup(final String participantId, final DiscoveryQos discoveryQos, final CapabilityCallback capabilityCallback) {
final DiscoveryEntry localDiscoveryEntry = localDiscoveryEntryStore.lookup(participantId, discoveryQos.getCacheMaxAgeMs());
DiscoveryScope discoveryScope = discoveryQos.getDiscoveryScope();
switch(discoveryScope) {
case LOCAL_ONLY:
if (localDiscoveryEntry != null) {
capabilityCallback.processCapabilityReceived(CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(true, localDiscoveryEntry));
} else {
capabilityCallback.processCapabilityReceived(null);
}
break;
case LOCAL_THEN_GLOBAL:
case LOCAL_AND_GLOBAL:
if (localDiscoveryEntry != null) {
capabilityCallback.processCapabilityReceived(CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(true, localDiscoveryEntry));
} else {
asyncGetGlobalCapabilitity(participantId, discoveryQos, capabilityCallback);
}
break;
case GLOBAL_ONLY:
asyncGetGlobalCapabilitity(participantId, discoveryQos, capabilityCallback);
break;
default:
break;
}
}
use of joynr.types.DiscoveryEntry 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;
}
use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.
the class ExpiredDiscoveryEntryCacheCleaner method doCleanupFor.
private void doCleanupFor(CleanupAction cleanupAction, DiscoveryEntryStore... caches) {
Set<DiscoveryEntry> expiredDiscoveryEntries = new HashSet<>();
long now = System.currentTimeMillis();
for (DiscoveryEntryStore cache : caches) {
for (DiscoveryEntry discoveryEntry : cache.getAllDiscoveryEntries()) {
if (discoveryEntry.getExpiryDateMs() < now) {
expiredDiscoveryEntries.add(discoveryEntry);
}
}
}
logger.debug("The following expired participant IDs will be cleaned from the caches {}:\n{}", Arrays.toString(caches), expiredDiscoveryEntries);
cleanupAction.cleanup(expiredDiscoveryEntries);
}
Aggregations