
org.infinispan.tasks.GlobalKeySetTask Maven / Gradle / Ivy
package org.infinispan.tasks;
import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import org.infinispan.Cache;
import org.infinispan.distexec.DefaultExecutorService;
import org.infinispan.distexec.DistributedCallable;
/**
* GlobalKeySetTask is a {@link DistributedCallable} for obtaining all of the keys
* across a cluster.
*
* @author Manik Surtani
* @author Tristan Tarrant
* @since 5.3
*/
public class GlobalKeySetTask implements DistributedCallable>, Serializable {
private Cache cache;
@Override
public Set call() throws Exception {
return new HashSet(cache.keySet());
}
@Override
public void setEnvironment(Cache cache, Set inputKeys) {
this.cache = cache;
}
public static Set getGlobalKeySet(Cache cache) throws InterruptedException, ExecutionException {
if (cache.getCacheConfiguration().clustering().cacheMode().isDistributed()) {
DefaultExecutorService des = new DefaultExecutorService(cache);
List>> fk = des.submitEverywhere(new GlobalKeySetTask());
Set allKeys = new HashSet();
for(Future> f : fk) {
allKeys.addAll(f.get());
}
return allKeys;
} else {
return new HashSet(cache.keySet());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy