org.infinispan.server.cli.handlers.CacheNameCommandCompleter Maven / Gradle / Ivy
package org.infinispan.server.cli.handlers;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.infinispan.server.cli.util.InfinispanUtil;
import org.jboss.as.cli.CommandContext;
import org.jboss.as.cli.CommandLineCompleter;
import org.jboss.as.cli.impl.DefaultCompleter;
/**
* The {@link CommandLineCompleter} implementation that shows all the caches name
* under the current cache container.
*
* @author Pedro Ruivo
* @since 6.1
*/
public class CacheNameCommandCompleter implements CommandLineCompleter {
private final DefaultCompleter completer;
public CacheNameCommandCompleter() {
completer = new DefaultCompleter(new DefaultCompleter.CandidatesProvider() {
@Override
public Collection getAllCandidates(CommandContext ctx) {
try {
Map> caches = InfinispanUtil.getCachesNames(ctx, InfinispanUtil.getCacheInfo(ctx)
.getContainer());
Set cachesName = new HashSet();
for (List cacheName : caches.values()) {
cachesName.addAll(cacheName);
}
return cachesName;
} catch (Exception e) {
return Collections.emptyList();
}
}
});
}
@Override
public int complete(CommandContext ctx, String buffer, int cursor, List candidates) {
return completer.complete(ctx, buffer, cursor, candidates);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy