Search in sources :

Example 11 with Promise

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

the class IltProvider method setAttributeStringNoSubscriptions.

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

Example 12 with Promise

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

the class IltProvider method overloadedMethodWithSelector.

/*
     * overloadedMethodWithSelector (3)
     */
@Override
public Promise<OverloadedMethodWithSelector2Deferred> overloadedMethodWithSelector(ExtendedExtendedEnumeration[] enumArrayArg, Long int64Arg, BaseStruct baseStructArg, Boolean booleanArg) {
    logger.warn("*************************************************");
    logger.warn("* IltProvider.overloadedMethodWithSelector called");
    logger.warn("*************************************************");
    OverloadedMethodWithSelector2Deferred deferred = new OverloadedMethodWithSelector2Deferred();
    /* check input */
    if (!IltUtil.checkExtendedExtendedEnumerationArray(enumArrayArg)) {
        deferred.reject(new ProviderRuntimeException("overloadedMethodWithSelector: failed to compare enumArrayArg"));
        return new Promise<OverloadedMethodWithSelector2Deferred>(deferred);
    }
    if (int64Arg != 1L) {
        deferred.reject(new ProviderRuntimeException("overloadedMethodWithSelector: failed to compare int64Arg"));
        return new Promise<OverloadedMethodWithSelector2Deferred>(deferred);
    }
    if (!IltUtil.checkBaseStruct(baseStructArg)) {
        deferred.reject(new ProviderRuntimeException("overloadedMethodWithSelector: failed to compare baseStructArg"));
        return new Promise<OverloadedMethodWithSelector2Deferred>(deferred);
    }
    if (booleanArg != false) {
        deferred.reject(new ProviderRuntimeException("overloadedMethodWithSelector: failed to compare booleanArg"));
        return new Promise<OverloadedMethodWithSelector2Deferred>(deferred);
    }
    /* prepare output */
    Double doubleOut = 1.1d;
    String[] stringArrayOut = IltUtil.createStringArray();
    ExtendedBaseStruct extendedBaseStructOut = IltUtil.createExtendedBaseStruct();
    deferred.resolve(doubleOut, stringArrayOut, extendedBaseStructOut);
    return new Promise<OverloadedMethodWithSelector2Deferred>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) ExtendedExtendedBaseStruct(joynr.interlanguagetest.namedTypeCollection2.ExtendedExtendedBaseStruct) ExtendedBaseStruct(joynr.interlanguagetest.namedTypeCollection2.ExtendedBaseStruct) MapStringString(joynr.interlanguagetest.namedTypeCollection2.MapStringString) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Example 13 with Promise

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

the class MyRadioProvider method addFavoriteStation.

@Override
public Promise<AddFavoriteStationDeferred> addFavoriteStation(final RadioStation radioStation) {
    final AddFavoriteStationDeferred deferred = new AddFavoriteStationDeferred();
    if (radioStation.getName().isEmpty()) {
        deferred.reject(new ProviderRuntimeException(MISSING_NAME));
    }
    executorService.schedule(new Runnable() {

        @Override
        public void run() {
            boolean duplicateFound = false;
            for (RadioStation station : stationsList) {
                if (!duplicateFound && station.getName().equals(radioStation.getName())) {
                    duplicateFound = true;
                    deferred.reject(AddFavoriteStationErrorEnum.DUPLICATE_RADIOSTATION);
                    break;
                }
            }
            if (!duplicateFound) {
                LOG.info(PRINT_BORDER + "addFavoriteStation(" + radioStation + ")" + PRINT_BORDER);
                stationsList.add(radioStation);
                deferred.resolve(true);
            }
        }
    }, DELAY_MS, TimeUnit.MILLISECONDS);
    // Promise is returned immediately. Deferred is resolved later
    return new Promise<AddFavoriteStationDeferred>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) RadioStation(joynr.vehicle.RadioStation)

Example 14 with Promise

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

the class CapabilitiesDirectoryImpl method add.

@Override
public Promise<DeferredVoid> add(GlobalDiscoveryEntry globalDiscoveryEntry) {
    DeferredVoid deferred = new DeferredVoid();
    Promise<DeferredVoid> promise = new Promise<DeferredVoid>(deferred);
    Address address = CapabilityUtils.getAddressFromGlobalDiscoveryEntry(globalDiscoveryEntry);
    String clusterControllerId;
    if (address instanceof MqttAddress) {
        clusterControllerId = ((MqttAddress) address).getTopic();
    } else if (address instanceof ChannelAddress) {
        clusterControllerId = ((ChannelAddress) address).getChannelId();
    } else {
        deferred.reject(new ProviderRuntimeException(""));
        return promise;
    }
    GlobalDiscoveryEntryPersisted discoveryEntry = new GlobalDiscoveryEntryPersisted(globalDiscoveryEntry, clusterControllerId);
    logger.debug("registered discovery entry: {}", discoveryEntry);
    discoveryEntryStore.add(discoveryEntry);
    deferred.resolve();
    return promise;
}
Also used : Promise(io.joynr.provider.Promise) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Address(joynr.system.RoutingTypes.Address) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) DeferredVoid(io.joynr.provider.DeferredVoid) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) GlobalDiscoveryEntryPersisted(io.joynr.capabilities.GlobalDiscoveryEntryPersisted) MqttAddress(joynr.system.RoutingTypes.MqttAddress)

Example 15 with Promise

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

the class CapabilitiesDirectoryImpl method lookup.

@Override
public Promise<Lookup2Deferred> lookup(String forParticipantId) {
    Lookup2Deferred deferred = new Lookup2Deferred();
    logger.debug("Searching discovery entries for participantId: {}", forParticipantId);
    DiscoveryEntry discoveryEntry = discoveryEntryStore.lookup(forParticipantId, DiscoveryQos.NO_FILTER.getCacheMaxAgeMs());
    if (discoveryEntry == null) {
        deferred.resolve(null);
    } else {
        deferred.resolve((GlobalDiscoveryEntry) discoveryEntry);
    }
    return new Promise<Lookup2Deferred>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry)

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