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);
}
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);
}
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);
}
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;
}
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);
}
Aggregations