1 package org.onap.msb.apiroute.wrapper.consulextend.expose;
3 import org.apache.http.HttpEntity;
4 import org.onap.msb.apiroute.wrapper.consulextend.CatalogClient;
5 import org.onap.msb.apiroute.wrapper.consulextend.cache.ServicesCatalogCache;
6 import org.onap.msb.apiroute.wrapper.consulextend.cache.ConsulCache.Listener;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
10 import com.orbitz.consul.option.CatalogOptions;
11 import com.orbitz.consul.option.QueryOptions;
13 public class WatchCatalogServicesTask extends WatchTask<HttpEntity> {
15 private final static Logger LOGGER = LoggerFactory
16 .getLogger(WatchCatalogServicesTask.class);
18 private ServicesCatalogCache servicesCache = null;
20 public WatchCatalogServicesTask(
21 final CatalogClient catalogClient,
22 final CatalogOptions catalogOptions,
23 final QueryOptions queryOptions,
24 final int watchSeconds)
26 initCache(catalogClient,catalogOptions,queryOptions,watchSeconds);
29 public WatchCatalogServicesTask(
30 final CatalogClient catalogClient,
31 final int watchSeconds)
33 initCache(catalogClient,CatalogOptions.BLANK,QueryOptions.BLANK,watchSeconds);
36 public WatchCatalogServicesTask(
37 final CatalogClient catalogClient)
39 initCache(catalogClient,CatalogOptions.BLANK,QueryOptions.BLANK,10);
42 private ServicesCatalogCache initCache(final CatalogClient catalogClient,
43 final CatalogOptions catalogOptions,
44 final QueryOptions queryOptions,
45 final int watchSeconds) {
46 LOGGER.info("************create all services watch task*****************");
47 servicesCache = ServicesCatalogCache.newCache(catalogClient,
48 catalogOptions, queryOptions, watchSeconds);
51 .addListener((Listener<HttpEntity>) new InternalListener());
57 public boolean startWatch() {
58 // TODO Auto-generated method stub
59 if(servicesCache!=null)
62 servicesCache.start();
63 LOGGER.info("************start all services watch task*****************");
65 } catch (Exception e) {
66 // TODO Auto-generated catch block
67 LOGGER.warn("start service list watch failed:", e);
75 public boolean stopWatch() {
76 // TODO Auto-generated method stub
77 if (servicesCache != null) {
80 LOGGER.info("************stop all services watch task*****************");
82 } catch (Exception e) {
83 // TODO Auto-generated catch block
84 LOGGER.warn("stop service list watch failed:", e);