Search in sources :

Example 71 with Promise

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

the class DummyCapabilitiesDirectory 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.resolve(capabilities.toArray(new DiscoveryEntryWithMetaInfo[0]));
            } else {
                deferred.reject(new ProviderRuntimeException("Received capabilities list was null"));
            }
        }

        @Override
        public void onError(Throwable e) {
            deferred.reject(new ProviderRuntimeException(e.toString()));
        }
    };
    DiscoveryScope discoveryScope = DiscoveryScope.valueOf(discoveryQos.getDiscoveryScope().name());
    lookup(domains, interfaceName, new DiscoveryQos(30000, ArbitrationStrategy.NotSet, discoveryQos.getCacheMaxAge(), discoveryScope), callback);
    return new Promise<Lookup1Deferred>(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 72 with Promise

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

the class GlobalDomainRoleControllerProviderImpl method removeDomainRole.

@Override
public Promise<RemoveDomainRoleDeferred> removeDomainRole(String uid, Role role) {
    RemoveDomainRoleDeferred deferred = new RemoveDomainRoleDeferred();
    boolean removeSuccess = domainAccessStore.removeDomainRole(uid, role);
    if (removeSuccess) {
        // To notify DRE removal only primary keys (user ID and role) must
        // be set. All other fields are undefined.
        DomainRoleEntry removedEntry = new DomainRoleEntry(uid, null, role);
        fireDomainRoleEntryChanged(ChangeType.REMOVE, removedEntry);
    }
    deferred.resolve(removeSuccess);
    return new Promise<RemoveDomainRoleDeferred>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DomainRoleEntry(joynr.infrastructure.DacTypes.DomainRoleEntry)

Example 73 with Promise

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

the class MyRadioProvider method shuffleStations.

@Override
public Promise<DeferredVoid> shuffleStations() {
    final DeferredVoid deferred = new DeferredVoid();
    // actions that take longer must be run in an appliction thread.
    // DO NOT block joynr threads
    executorService.schedule(new Runnable() {

        @Override
        public void run() {
            RadioStation oldStation = currentStation;
            currentStationIndex++;
            currentStationIndex = currentStationIndex % stationsList.size();
            currentStation = stationsList.get(currentStationIndex);
            currentStationChanged(currentStation);
            LOG.info(PRINT_BORDER + "shuffleStations: " + oldStation + " -> " + currentStation + PRINT_BORDER);
            deferred.resolve();
        }
    }, DELAY_MS, TimeUnit.MILLISECONDS);
    // Promise is returned immediately. Deferred is resolved later
    return new Promise<DeferredVoid>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DeferredVoid(io.joynr.provider.DeferredVoid) RadioStation(joynr.vehicle.RadioStation)

Example 74 with Promise

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

the class MyRadioProvider method getLocationOfCurrentStation.

@Override
public Promise<GetLocationOfCurrentStationDeferred> getLocationOfCurrentStation() {
    Country country = currentStation.getCountry();
    GeoPosition location = countryGeoPositionMap.get(country);
    LOG.info(PRINT_BORDER + "getLocationOfCurrentStation: country: " + country.name() + ", location: " + location + PRINT_BORDER);
    RadioProvider.GetLocationOfCurrentStationDeferred deferred = new GetLocationOfCurrentStationDeferred();
    // actions that take no time can be returned immediately by resolving the deferred.
    deferred.resolve(country, location);
    return new Promise<RadioProvider.GetLocationOfCurrentStationDeferred>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) Country(joynr.vehicle.Country) GeoPosition(joynr.vehicle.GeoPosition) RadioProvider(joynr.vehicle.RadioProvider)

Example 75 with Promise

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

the class CapabilitiesDirectoryImpl method touch.

@Override
public Promise<DeferredVoid> touch(String clusterControllerId) {
    DeferredVoid deferred = new DeferredVoid();
    discoveryEntryStore.touch(clusterControllerId);
    deferred.resolve();
    return new Promise<DeferredVoid>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DeferredVoid(io.joynr.provider.DeferredVoid)

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