Search in sources :

Example 56 with DiscoveryEntry

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);
            }
        }
    }
}
Also used : Function(com.google.common.base.Function) DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Callback(io.joynr.proxy.Callback) ArrayList(java.util.ArrayList) DeferredVoid(io.joynr.provider.DeferredVoid) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) DiscoveryException(io.joynr.exceptions.DiscoveryException)

Example 57 with DiscoveryEntry

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);
    }
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) DiscoveryScope(io.joynr.arbitration.DiscoveryScope) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo)

Example 58 with DiscoveryEntry

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;
    }
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) DiscoveryScope(io.joynr.arbitration.DiscoveryScope) CheckForNull(javax.annotation.CheckForNull)

Example 59 with DiscoveryEntry

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;
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) Version(joynr.types.Version) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo)

Example 60 with DiscoveryEntry

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);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) HashSet(java.util.HashSet)

Aggregations

DiscoveryEntry (joynr.types.DiscoveryEntry)60 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)43 Test (org.junit.Test)30 ProviderQos (joynr.types.ProviderQos)25 Version (joynr.types.Version)22 Callback (io.joynr.proxy.Callback)18 Matchers.anyString (org.mockito.Matchers.anyString)17 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)16 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)15 ArrayList (java.util.ArrayList)14 HashSet (java.util.HashSet)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)9 DeferredVoid (io.joynr.provider.DeferredVoid)7 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)6 MqttAddress (joynr.system.RoutingTypes.MqttAddress)6 Injector (com.google.inject.Injector)5 MessagingQos (io.joynr.messaging.MessagingQos)4 Future (io.joynr.proxy.Future)4 CheckForNull (javax.annotation.CheckForNull)4 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)4