All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.orbitz.consul.cache.NodesCatalogCache Maven / Gradle / Ivy

There is a newer version: 1.5.3
Show newest version
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);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy