remove not required docs and .readthedocs.yaml
[msb/discovery.git] / sdclient / discovery-service / src / main / java / org / onap / msb / sdclient / wrapper / consul / cache / HealthCache.java
1 /**
2  * Copyright 2016-2017 ZTE, Inc. and others.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 package org.onap.msb.sdclient.wrapper.consul.cache;
15
16 import java.math.BigInteger;
17 import java.util.List;
18
19 import org.onap.msb.sdclient.wrapper.consul.HealthClient;
20 import org.onap.msb.sdclient.wrapper.consul.async.ConsulResponseCallback;
21 import org.onap.msb.sdclient.wrapper.consul.model.health.ServiceHealth;
22
23 import com.google.common.base.Function;
24
25 public class HealthCache extends ConsulCache<String, ServiceHealth> {
26
27     private final String serviceName;
28
29     private HealthCache(Function<ServiceHealth, String> keyConversion,
30                     ConsulCache.CallbackConsumer<ServiceHealth> callbackConsumer, String serviceName) {
31         super(keyConversion, callbackConsumer);
32         this.serviceName = serviceName;
33         // TODO Auto-generated constructor stub
34     }
35
36
37     public static HealthCache newCache(final HealthClient healthClient, final String serviceName,
38                     final int watchSeconds) {
39         Function<ServiceHealth, String> keyExtractor = input -> {
40             // return input.getKey().substring(rootPath.length() + 1);
41             return input.getService().getId();
42         };
43
44         final CallbackConsumer<ServiceHealth> callbackConsumer = (index, callback) -> healthClient.getHealthyServiceInstances(serviceName, watchParams(index, watchSeconds), callback);
45
46
47         return new HealthCache(keyExtractor, callbackConsumer, serviceName);
48
49
50     }
51
52     public String getServiceName() {
53         return this.serviceName;
54     }
55
56
57 }