Divide the MSB source codes into two repos
[msb/apigateway.git] / apiroute / apiroute-service / src / main / java / org / onap / msb / apiroute / wrapper / queue / ServiceListCache.java
1 package org.onap.msb.apiroute.wrapper.queue;
2
3 import java.util.HashSet;
4 import java.util.Set;
5 import java.util.concurrent.atomic.AtomicReference;
6
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9
10
11 public class ServiceListCache {
12   
13   private static final Logger LOGGER = LoggerFactory.getLogger(ServiceListCache.class);
14
15   private final static AtomicReference<Set<String>> serviceNameList4Cache = new AtomicReference<Set<String>>(new HashSet<String>());
16
17   public static Set<String> getLatestServiceNamelist() {
18     return serviceNameList4Cache.get();
19   }
20   
21   public static void setLatestServiceNamelist(Set<String> newServicenamelist){
22     serviceNameList4Cache.set(newServicenamelist);
23     LOGGER.info("------current total Watch Service Num :"+ newServicenamelist.size());
24   }
25   
26   public synchronized static void removeService(String serviceName){
27     
28       Set<String> servicenamelist=serviceNameList4Cache.get();  
29       servicenamelist.remove(serviceName);      
30       serviceNameList4Cache.set(servicenamelist);
31       LOGGER.info("------current total Watch Service Num :"+ servicenamelist.size());
32     }
33
34
35 }