com.orbitz.consul.cache.NodesCatalogCache Maven / Gradle / Ivy
package com.orbitz.consul.cache;
import com.google.common.base.Function;
import com.orbitz.consul.CatalogClient;
import com.orbitz.consul.async.ConsulResponseCallback;
import com.orbitz.consul.model.health.Node;
import com.orbitz.consul.option.QueryOptions;
import java.math.BigInteger;
import java.util.List;
public class NodesCatalogCache extends ConsulCache {
private NodesCatalogCache(Function keyConversion, CallbackConsumer callbackConsumer) {
super(keyConversion, callbackConsumer);
}
public static NodesCatalogCache newCache(
final CatalogClient catalogClient,
final QueryOptions queryOptions,
final int watchSeconds) {
Function keyExtractor = new Function() {
@Override
public String apply(Node node) {
return node.getNode();
}
};
CallbackConsumer callbackConsumer = new CallbackConsumer() {
@Override
public void consume(BigInteger index, ConsulResponseCallback> callback) {
catalogClient.getNodes(watchParams(index, watchSeconds, queryOptions), callback);
}
};
return new NodesCatalogCache(keyExtractor, callbackConsumer);
}
public static NodesCatalogCache newCache(final CatalogClient catalogClient) {
return newCache(catalogClient, QueryOptions.BLANK, 10);
}
}