if (material != null) { material.incrementRequestedApplications(); LOG.debug("Incrementing requested application to " + material.getRequestedApplications() + " for key " + key); } else { Path appDirPath;
@Override public void removeMaterial(String username, String applicationId) throws InterruptedException { StorageKey key = new StorageKey(username, applicationId); try { lock.lock(); CryptoMaterial material = materialLocation.get(key); if (material != null) { material.decrementRequestedApplications(); LOG.debug("Decrementing requested applications to " + material.getRequestedApplications() + " for key " + key); if (material.isSafeToRemove()) { RemoveEvent event = new RemoveEvent(material.getCertFolder()); materialLocation.remove(key); dispatchEvent(event); LOG.debug("Dispatching remove event for key " + key); } } } finally { lock.unlock(); } }
/** * Method invoked by a JMX client to get the state of the CertificateLocalization service. * Under the attributes tab. * @return It returns a map with the name of the material and the number of references. */ @Override public String getState() { ImmutableMap<StorageKey, CryptoMaterial> state; try { lock.lock(); state = ImmutableMap.copyOf(materialLocation); } finally { lock.unlock(); } ReturnState<String, String> returnState = new ReturnState<>(); ReturnState<String, Integer> internalState = new ReturnState<>(); for (Map.Entry<StorageKey, CryptoMaterial> entry : state.entrySet()) { internalState.put(entry.getKey().username, entry.getValue().getRequestedApplications()); } returnState.put(JMX_MATERIALIZED_KEY, JSON.toString(internalState)); return JSON.toString(returnState); }