Search in sources :

Example 76 with Promise

use of io.joynr.provider.Promise in project joynr by bmwcarit.

the class CapabilitiesDirectoryImpl method remove.

@Override
public Promise<DeferredVoid> remove(String[] participantIds) {
    DeferredVoid deferred = new DeferredVoid();
    discoveryEntryStore.remove(Arrays.asList(participantIds));
    deferred.resolve();
    return new Promise<DeferredVoid>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DeferredVoid(io.joynr.provider.DeferredVoid)

Example 77 with Promise

use of io.joynr.provider.Promise in project joynr by bmwcarit.

the class CapabilitiesDirectoryImpl method lookup.

@Override
public Promise<Lookup1Deferred> lookup(final String[] domains, final String interfaceName) {
    Lookup1Deferred deferred = new Lookup1Deferred();
    logger.debug("Searching channels for domains: {} interfaceName: {}", domains, interfaceName);
    Collection<DiscoveryEntry> discoveryEntries = discoveryEntryStore.lookup(domains, interfaceName);
    GlobalDiscoveryEntry[] globalDiscoveryEntries = new GlobalDiscoveryEntry[discoveryEntries.size()];
    int index = 0;
    for (DiscoveryEntry discoveryEntry : discoveryEntries) {
        // entries from persisted store are of type GlobalDiscoveryEntryPersisted.
        // Copy required or else _typeName will be incorrect
        globalDiscoveryEntries[index] = new GlobalDiscoveryEntry((GlobalDiscoveryEntry) discoveryEntry);
        index++;
    }
    deferred.resolve(globalDiscoveryEntries);
    return new Promise<Lookup1Deferred>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry)

Example 78 with Promise

use of io.joynr.provider.Promise in project joynr by bmwcarit.

the class LocalCapabilitiesDirectoryImpl method add.

/**
 * Adds local capability to local and (depending on SCOPE) the global directory
 */
@Override
public Promise<DeferredVoid> add(final DiscoveryEntry discoveryEntry) {
    final DeferredVoid deferred = new DeferredVoid();
    if (localDiscoveryEntryStore.hasDiscoveryEntry(discoveryEntry)) {
        if (discoveryEntry.getQos().getScope().equals(ProviderScope.LOCAL) || globalDiscoveryEntryCache.lookup(discoveryEntry.getParticipantId(), DiscoveryQos.NO_MAX_AGE) != null) {
            // in this case, no further need for global registration is required. Registration completed.
            deferred.resolve();
            return new Promise<>(deferred);
        }
    // in the other case, the global registration needs to be done
    } else {
        localDiscoveryEntryStore.add(discoveryEntry);
        notifyCapabilityAdded(discoveryEntry);
    }
    if (discoveryEntry.getQos().getScope().equals(ProviderScope.GLOBAL)) {
        registerGlobal(discoveryEntry, deferred);
    } else {
        deferred.resolve();
    }
    return new Promise<>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DeferredVoid(io.joynr.provider.DeferredVoid)

Example 79 with Promise

use of io.joynr.provider.Promise 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)

Aggregations

Promise (io.joynr.provider.Promise)79 DeferredVoid (io.joynr.provider.DeferredVoid)36 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)27 MapStringString (joynr.interlanguagetest.namedTypeCollection2.MapStringString)13 Method (java.lang.reflect.Method)9 ProviderWrapper (io.joynr.jeeintegration.ProviderWrapper)6 JoynrProvider (io.joynr.provider.JoynrProvider)6 Test (org.junit.Test)6 JoynrException (io.joynr.exceptions.JoynrException)5 Deferred (io.joynr.provider.Deferred)4 PromiseListener (io.joynr.provider.PromiseListener)4 ExtendedExtendedBaseStruct (joynr.interlanguagetest.namedTypeCollection2.ExtendedExtendedBaseStruct)4 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)4 StructWithStringArray (joynr.interlanguagetest.namedTypeCollection1.StructWithStringArray)3 ExtendedTypeCollectionEnumerationInTypeCollection (joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection)3 DiscoveryEntry (joynr.types.DiscoveryEntry)3 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)3 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)2 DiscoveryScope (io.joynr.arbitration.DiscoveryScope)2 ProviderContainer (io.joynr.provider.ProviderContainer)2