use of io.joynr.provider.DeferredVoid 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);
}
use of io.joynr.provider.DeferredVoid 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);
}
use of io.joynr.provider.DeferredVoid 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.DeferredVoid in project joynr by bmwcarit.
the class LocalCapabilitiesDirectoryTest method addGlobalCapFails_NextAddShallAddGlobalAgain.
@SuppressWarnings("unchecked")
@Test(timeout = 1000)
public void addGlobalCapFails_NextAddShallAddGlobalAgain() throws InterruptedException {
ProviderQos providerQos = new ProviderQos();
providerQos.setScope(ProviderScope.GLOBAL);
String participantId = LocalCapabilitiesDirectoryTest.class.getName() + ".addLocalAndThanGlobalShallWork";
String domain = "testDomain";
final DiscoveryEntry discoveryEntry = new DiscoveryEntry(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, participantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId);
globalDiscoveryEntry = new GlobalDiscoveryEntry(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, participantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId, channelAddressSerialized);
Mockito.doAnswer(createAddAnswerWithError()).when(globalCapabilitiesClient).add(any(Callback.class), eq(globalDiscoveryEntry));
Promise<DeferredVoid> promise = localCapabilitiesDirectory.add(discoveryEntry);
promise.then(new PromiseListener() {
@Override
public void onFulfillment(Object... values) {
verify(globalDiscoveryEntryCacheMock, never()).add(eq(globalDiscoveryEntry));
verify(globalCapabilitiesClient).add(any(Callback.class), eq(globalDiscoveryEntry));
reset(globalCapabilitiesClient);
localCapabilitiesDirectory.add(discoveryEntry);
verify(globalCapabilitiesClient, timeout(200)).add(any(Callback.class), eq(globalDiscoveryEntry));
}
@Override
public void onRejection(JoynrException error) {
}
});
}
use of io.joynr.provider.DeferredVoid 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);
}
Aggregations