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
diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/queue/ServiceListCache.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/queue/ServiceListCache.java
new file mode 100644 (file)
index 0000000..59be2e4
--- /dev/null
@@ -0,0 +1,35 @@
+package org.onap.msb.apiroute.wrapper.queue;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class ServiceListCache {
+  
+  private static final Logger LOGGER = LoggerFactory.getLogger(ServiceListCache.class);
+
+  private final static AtomicReference<Set<String>> serviceNameList4Cache = new AtomicReference<Set<String>>(new HashSet<String>());
+
+  public static Set<String> getLatestServiceNamelist() {
+    return serviceNameList4Cache.get();
+  }
+  
+  public static void setLatestServiceNamelist(Set<String> newServicenamelist){
+    serviceNameList4Cache.set(newServicenamelist);
+    LOGGER.info("------current total Watch Service Num :"+ newServicenamelist.size());
+  }
+  
+  public synchronized static void removeService(String serviceName){
+    
+      Set<String> servicenamelist=serviceNameList4Cache.get();  
+      servicenamelist.remove(serviceName);      
+      serviceNameList4Cache.set(servicenamelist);
+      LOGGER.info("------current total Watch Service Num :"+ servicenamelist.size());
+    }
+
+
+}