use of org.infinispan.commands.irac.IracTouchKeyCommand in project infinispan by infinispan.
the class DefaultIracManager method checkAndTrackExpiration.
@Override
public CompletionStage<Boolean> checkAndTrackExpiration(Object key) {
if (log.isTraceEnabled()) {
log.tracef("Checking remote backup sites to see if key %s has been touched recently", key);
}
IracTouchKeyCommand command = commandsFactory.buildIracTouchCommand(key);
AtomicBoolean expired = new AtomicBoolean(true);
// TODO: technically this waits for all backups to respond - we can optimize so
// we return early
// if at least one backup says it isn't expired
AggregateCompletionStage<AtomicBoolean> collector = CompletionStages.aggregateCompletionStage(expired);
for (XSiteBackup backup : asyncBackups) {
if (takeOfflineManager.getSiteState(backup.getSiteName()) == SiteState.OFFLINE) {
if (log.isTraceEnabled()) {
log.tracef("Skipping %s as it is offline", backup.getSiteName());
}
// backup is offline
continue;
}
if (log.isTraceEnabled()) {
log.tracef("Sending irac touch key command to %s", backup);
}
XSiteResponse<Boolean> response = sendToRemoteSite(backup, command);
collector.dependsOn(response.thenAccept(touched -> {
if (touched) {
if (log.isTraceEnabled()) {
log.tracef("Key %s was recently touched on a remote site %s", key, backup);
}
expired.set(false);
} else if (log.isTraceEnabled()) {
log.tracef("Entry %s was expired on remote site %s", key, backup);
}
}));
}
return collector.freeze().thenApply(AtomicBoolean::get);
}
Aggregations