@Override public Resource getResource(ResourceIdentity resid) { return getResourceInternal(resid); }
@Override public Resource addResource(Resource res) { synchronized (resources) { if (getResourceInternal(res.getIdentity()) != null) throw new IllegalArgumentException("Resource already added: " + res); LOGGER.debug("Add to {}: {}", storeName, res); // Add resource capabilites for (Capability cap : res.getCapabilities(null)) { CacheKey cachekey = CacheKey.create(cap); getCachedCapabilities(cachekey).add(cap); } // Log cap/req details if (LOGGER.isDebugEnabled()) { for (Capability cap : res.getCapabilities(null)) { LOGGER.debug(" {}", cap); } for (Requirement req : res.getRequirements(null)) { LOGGER.debug(" {}", req); } } resources.put(res.getIdentity(), res); return res; } }
@Override public Set<Capability> findProviders(Requirement req) { CacheKey cachekey = CacheKey.create(req); Set<Capability> result = new HashSet<Capability>(); for (Capability cap : findCachedCapabilities(cachekey)) { if (matchPolicy.match(cap, req)) { result.add(cap); } } return Collections.unmodifiableSet(result); }
@Override public Resource removeResource(ResourceIdentity resid) { synchronized (resources) { Resource res = resources.remove(resid); if (res != null) { LOGGER.debug("Remove from {}: {}", storeName, res); // Remove resource capabilities for (Capability cap : res.getCapabilities(null)) { CacheKey cachekey = CacheKey.create(cap); Set<Capability> cachecaps = getCachedCapabilities(cachekey); cachecaps.remove(cap); if (cachecaps.isEmpty()) { capabilityCache.remove(cachekey); } } } return res; } }