X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Frepository%2FServices.java;h=35cae71764c3da7c5e96eb24bc66979a0c03c56a;hb=7a4a590fb0ebf8772169625cdda327da43c79c6d;hp=5b5b4a8a785c291c1c694c5e4317bb21c6b7e9d1;hpb=4a7dd457d5b179dd0f588663fc1476dacfca4f22;p=nonrtric.git diff --git a/policy-agent/src/main/java/org/oransc/policyagent/repository/Services.java b/policy-agent/src/main/java/org/oransc/policyagent/repository/Services.java index 5b5b4a8a..35cae717 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/repository/Services.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/repository/Services.java @@ -20,9 +20,11 @@ package org.oransc.policyagent.repository; +import java.util.Collection; import java.util.HashMap; import java.util.Map; +import org.oransc.policyagent.exceptions.ServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,4 +36,28 @@ public class Services { public Services() { } + public synchronized Service getService(String name) throws ServiceException { + Service s = services.get(name); + if (s == null) { + throw new ServiceException("Could not find service: " + name); + } + return s; + } + + public synchronized Service get(String name) { + return services.get(name); + } + + public synchronized void put(Service service) { + logger.debug("Put service: " + service.getName()); + // TODO a threading problem is that this may happend at the same time as someone is iterating (getAll()) + // This is a generic problem + services.put(service.getName(), service); + } + + // TODO the returned value should be unmodifiable if possible + public synchronized Collection getAll() { + return services.values(); + } + }