+ 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) {
+ Map<String, Policy> map = multiMap.get(key);
+ if (map == null) {
+ map = new HashMap<>();
+ multiMap.put(key, map);
+ }
+ map.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 new Vector<Policy>();
+ }
+ return Collections.unmodifiableCollection(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;
+ }
+
+ public synchronized Collection<Policy> getAll() {
+ return Collections.unmodifiableCollection(policiesId.values());
+ }
+
+ public synchronized Collection<Policy> getForService(String service) {
+ return multiMapGet(policiesService, service);
+ }
+
+ public synchronized Collection<Policy> getForRic(String ric) {
+ return multiMapGet(policiesRic, ric);
+ }
+
+ public synchronized Collection<Policy> getForType(String type) {
+ return multiMapGet(policiesType, type);