use of org.onosproject.net.intent.IntentState.WITHDRAWN in project onos by opennetworkinglab.
the class WipeOutCommand method wipeOutIntents.
private void wipeOutIntents() {
print("Wiping intents");
IntentService intentService = get(IntentService.class);
Set<Key> keysToWithdrawn = Sets.newConcurrentHashSet();
Set<Intent> intentsToWithdrawn = Tools.stream(intentService.getIntents()).filter(intent -> intentService.getIntentState(intent.key()) != WITHDRAWN).collect(Collectors.toSet());
intentsToWithdrawn.stream().map(Intent::key).forEach(keysToWithdrawn::add);
CompletableFuture<Void> completableFuture = new CompletableFuture<>();
IntentListener listener = e -> {
if (e.type() == IntentEvent.Type.WITHDRAWN) {
keysToWithdrawn.remove(e.subject().key());
}
if (keysToWithdrawn.isEmpty()) {
completableFuture.complete(null);
}
};
intentService.addListener(listener);
intentsToWithdrawn.forEach(intentService::withdraw);
try {
if (!intentsToWithdrawn.isEmpty()) {
// Wait 1.5 seconds for each Intent
completableFuture.get(intentsToWithdrawn.size() * 1500L, TimeUnit.MILLISECONDS);
}
} catch (InterruptedException | ExecutionException | TimeoutException e) {
print("Encountered exception while withdrawing intents: " + e.toString());
} finally {
intentService.removeListener(listener);
}
intentsToWithdrawn.forEach(intentService::purge);
}
Aggregations