Divide the MSB source codes into two repos
[msb/apigateway.git] / apiroute / apiroute-service / src / main / java / org / onap / msb / apiroute / wrapper / consulextend / cache / ServicesCatalogCache.java
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 (file)
index 0000000..08c7369
--- /dev/null
@@ -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);
+    }
+}