1 package org.onap.msb.apiroute.wrapper.consulextend.cache;
3 import java.math.BigInteger;
6 import org.onap.msb.apiroute.wrapper.consulextend.HealthClient;
7 import org.onap.msb.apiroute.wrapper.consulextend.async.ConsulResponseCallback;
8 import org.onap.msb.apiroute.wrapper.consulextend.model.health.ServiceHealth;
10 import com.orbitz.consul.option.CatalogOptions;
11 import com.orbitz.consul.option.QueryOptions;
13 public class ServiceHealthCache extends ConsulCache<List<ServiceHealth>> {
14 private ServiceHealthCache(CallbackConsumer<List<ServiceHealth>> callbackConsumer) {
15 super(callbackConsumer);
19 * Factory method to construct a string/{@link ServiceHealth} map for a particular service.
21 * Keys will be a {@link HostAndPort} object made up of the service's address/port combo
23 * @param healthClient the {@link HealthClient}
24 * @param serviceName the name of the service
25 * @param passing include only passing services?
26 * @return a cache object
28 public static ServiceHealthCache newCache(
29 final HealthClient healthClient,
30 final String serviceName,
31 final boolean passing,
32 final CatalogOptions catalogOptions,
33 final int watchSeconds,
34 final QueryOptions queryOptions) {
36 CallbackConsumer<List<ServiceHealth>> callbackConsumer = new CallbackConsumer<List<ServiceHealth>>() {
38 public void consume(BigInteger index,
39 ConsulResponseCallback<List<ServiceHealth>> callback) {
40 // TODO Auto-generated method stub
41 QueryOptions params = watchParams(index, watchSeconds, queryOptions);
43 healthClient.getHealthyServiceInstances(serviceName, catalogOptions, params, callback);
45 healthClient.getAllServiceInstances(serviceName, catalogOptions, params, callback);
50 return new ServiceHealthCache(callbackConsumer);
53 public static ServiceHealthCache newCache(
54 final HealthClient healthClient,
55 final String serviceName,
56 final boolean passing,
57 final CatalogOptions catalogOptions,
58 final int watchSeconds) {
59 return newCache(healthClient, serviceName, passing, catalogOptions, watchSeconds, QueryOptions.BLANK);
62 public static ServiceHealthCache newCache(final HealthClient healthClient, final String serviceName) {
63 return newCache(healthClient, serviceName, true, CatalogOptions.BLANK, 10);