+ public synchronized void put(Policy policy) {
+ policiesId.put(policy.id(), policy);
+ multiMapPut(policiesRic, policy.ric().name(), policy);
+ multiMapPut(policiesService, policy.ownerServiceName(), policy);
+ multiMapPut(policiesType, policy.type().name(), policy);
+ }
+
+ private void multiMapPut(Map<String, Map<String, Policy>> multiMap, String key, Policy value) {
+ multiMap.computeIfAbsent(key, k -> new HashMap<>()).put(value.id(), value);
+ }
+
+ private void multiMapRemove(Map<String, Map<String, Policy>> multiMap, String key, Policy value) {
+ Map<String, Policy> map = multiMap.get(key);
+ if (map != null) {
+ map.remove(value.id());
+ if (map.isEmpty()) {
+ multiMap.remove(key);
+ }
+ }
+ }
+
+ private Collection<Policy> multiMapGet(Map<String, Map<String, Policy>> multiMap, String key) {
+ Map<String, Policy> map = multiMap.get(key);
+ if (map == null) {
+ return Collections.emptyList();
+ }
+ return new Vector<>(map.values());
+ }
+
+ public synchronized boolean containsPolicy(String id) {
+ return policiesId.containsKey(id);
+ }
+
+ public synchronized Policy get(String id) {
+ return policiesId.get(id);
+ }
+
+ public synchronized Policy getPolicy(String id) throws ServiceException {
+ Policy p = policiesId.get(id);
+ if (p == null) {
+ throw new ServiceException("Could not find policy: " + id);
+ }
+ return p;
+ }