08c7369dea6d35f7aeeb1486704144c7dab16df7
[msb/apigateway.git] /
1 package org.onap.msb.apiroute.wrapper.consulextend.cache;
2
3 import java.math.BigInteger;
4
5 import org.apache.http.HttpEntity;
6 import org.onap.msb.apiroute.wrapper.consulextend.CatalogClient;
7 import org.onap.msb.apiroute.wrapper.consulextend.async.ConsulResponseCallback;
8
9 import com.orbitz.consul.option.CatalogOptions;
10 import com.orbitz.consul.option.QueryOptions;
11
12 public class ServicesCatalogCache extends ConsulCache<HttpEntity> {
13         
14     private ServicesCatalogCache(CallbackConsumer<HttpEntity> callbackConsumer) {
15         super(callbackConsumer);
16     }
17
18     public static ServicesCatalogCache newCache(
19             final CatalogClient catalogClient,
20             final CatalogOptions catalogOptions,
21             final QueryOptions queryOptions,
22             final int watchSeconds) {
23         
24         CallbackConsumer<HttpEntity> callbackConsumer = new CallbackConsumer<HttpEntity>() {
25             @Override
26             public void consume(BigInteger index, ConsulResponseCallback<HttpEntity> callback) {
27                 QueryOptions params = watchParams(index, watchSeconds, queryOptions);
28                 catalogClient.getServices(catalogOptions, params,callback);
29             }
30         };
31
32         return new ServicesCatalogCache(callbackConsumer);
33
34     }
35     
36     public static ServicesCatalogCache newCache(final CatalogClient catalogClient) {
37         return newCache(catalogClient, CatalogOptions.BLANK, QueryOptions.BLANK, 10);
38     }
39 }