diff options
Diffstat (limited to 'apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/consulextend/cache/ServicesCatalogCache.java')
-rw-r--r-- | apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/consulextend/cache/ServicesCatalogCache.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/consulextend/cache/ServicesCatalogCache.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/consulextend/cache/ServicesCatalogCache.java new file mode 100644 index 0000000..08c7369 --- /dev/null +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/consulextend/cache/ServicesCatalogCache.java @@ -0,0 +1,39 @@ +package org.onap.msb.apiroute.wrapper.consulextend.cache; + +import java.math.BigInteger; + +import org.apache.http.HttpEntity; +import org.onap.msb.apiroute.wrapper.consulextend.CatalogClient; +import org.onap.msb.apiroute.wrapper.consulextend.async.ConsulResponseCallback; + +import com.orbitz.consul.option.CatalogOptions; +import com.orbitz.consul.option.QueryOptions; + +public class ServicesCatalogCache extends ConsulCache<HttpEntity> { + + private ServicesCatalogCache(CallbackConsumer<HttpEntity> callbackConsumer) { + super(callbackConsumer); + } + + public static ServicesCatalogCache newCache( + final CatalogClient catalogClient, + final CatalogOptions catalogOptions, + final QueryOptions queryOptions, + final int watchSeconds) { + + CallbackConsumer<HttpEntity> callbackConsumer = new CallbackConsumer<HttpEntity>() { + @Override + public void consume(BigInteger index, ConsulResponseCallback<HttpEntity> callback) { + QueryOptions params = watchParams(index, watchSeconds, queryOptions); + catalogClient.getServices(catalogOptions, params,callback); + } + }; + + return new ServicesCatalogCache(callbackConsumer); + + } + + public static ServicesCatalogCache newCache(final CatalogClient catalogClient) { + return newCache(catalogClient, CatalogOptions.BLANK, QueryOptions.BLANK, 10); + } +} |