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