Changed in config will add and recover Rics
[nonrtric.git] / policy-agent / src / main / java / org / oransc / policyagent / repository / Rics.java
index 9ea6db6..bdf9930 100644 (file)
 
 package org.oransc.policyagent.repository;
 
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.oransc.policyagent.exceptions.ServiceException;
+
 /**
  * Dynamic representation of all Rics in the system.
  */
 public class Rics {
     Map<String, Ric> rics = new HashMap<>();
 
-    public void put(Ric ric) {
+    public synchronized void put(Ric ric) {
         rics.put(ric.name(), ric);
     }
 
-    public Collection<Ric> getRics() {
+    public synchronized Iterable<Ric> getRics() {
         return rics.values();
     }
 
-    public Ric getRic(String name) {
+    public synchronized Ric getRic(String name) throws ServiceException {
+        Ric ric = rics.get(name);
+        if (ric == null) {
+            throw new ServiceException("Could not find ric: " + name);
+        }
+        return ric;
+    }
+
+    public synchronized Ric get(String name) {
         return rics.get(name);
     }
 
-    public int size() {
+    public synchronized void remove(String name) {
+        rics.remove(name);
+    }
+
+    public synchronized int size() {
         return rics.size();
     }
 
-    public void clear() {
+    public synchronized void clear() {
         this.rics.clear();
     }
 }