private AtomicInteger getCounter(final ResourceClaim claim) { if (claim == null) { return null; } ClaimCount counter = claimantCounts.get(claim); if (counter != null) { return counter.getCount(); } counter = new ClaimCount(claim, new AtomicInteger(0)); final ClaimCount existingCounter = claimantCounts.putIfAbsent(claim, counter); return existingCounter == null ? counter.getCount() : existingCounter.getCount(); }
@Override public ResourceClaim getResourceClaim(final String container, final String section, final String id) { final ResourceClaim tempClaim = new StandardResourceClaim(this, container, section, id, false); final ClaimCount count = claimantCounts.get(tempClaim); return (count == null) ? null : count.getClaim(); }
@Override public int decrementClaimantCount(final ResourceClaim claim) { if (claim == null) { return 0; } synchronized (claim) { final ClaimCount counter = claimantCounts.get(claim); if (counter == null) { logger.warn("Decrementing claimant count for {} but claimant count is not known. Returning -1", claim); return -1; } final int newClaimantCount = counter.getCount().decrementAndGet(); if (newClaimantCount < 0) { logger.error("Decremented claimant count for {} to {}", claim, newClaimantCount); } else { logger.debug("Decrementing claimant count for {} to {}", claim, newClaimantCount); } // If the claim is no longer referenced, we want to remove it. We consider the claim to be "no longer referenced" // if the count is 0 and it is no longer writable (if it's writable, it may still be writable by the Content Repository, // even though no existing FlowFile is referencing the claim). if (newClaimantCount == 0 && !claim.isWritable()) { removeClaimantCount(claim); } return newClaimantCount; } }
@Override public int getClaimantCount(final ResourceClaim claim) { if (claim == null) { return 0; } // No need to synchronize on the Resource Claim here, since this is simply obtaining a value. // We synchronize elsewhere because we want to atomically perform multiple operations, such as // getting the claimant count and then updating a queue. However, the operation of obtaining // the ClaimCount and getting its count value has no side effect and therefore can be performed // without synchronization (since the claimantCounts map and the ClaimCount are also both thread-safe // and there is no need for the two actions of obtaining the ClaimCount and getting its Count value // to be performed atomically). final ClaimCount counter = claimantCounts.get(claim); return counter == null ? 0 : counter.getCount().get(); }
private AtomicInteger getCounter(final ResourceClaim claim) { if (claim == null) { return null; } ClaimCount counter = claimantCounts.get(claim); if (counter != null) { return counter.getCount(); } counter = new ClaimCount(claim, new AtomicInteger(0)); final ClaimCount existingCounter = claimantCounts.putIfAbsent(claim, counter); return existingCounter == null ? counter.getCount() : existingCounter.getCount(); }
@Override public ResourceClaim getResourceClaim(final String container, final String section, final String id) { final ResourceClaim tempClaim = new StandardResourceClaim(this, container, section, id, false); final ClaimCount count = claimantCounts.get(tempClaim); return (count == null) ? null : count.getClaim(); }
@Override public int decrementClaimantCount(final ResourceClaim claim) { if (claim == null) { return 0; } synchronized (claim) { final ClaimCount counter = claimantCounts.get(claim); if (counter == null) { logger.warn("Decrementing claimant count for {} but claimant count is not known. Returning -1", claim); return -1; } final int newClaimantCount = counter.getCount().decrementAndGet(); if (newClaimantCount < 0) { logger.error("Decremented claimant count for {} to {}", claim, newClaimantCount); } else { logger.debug("Decrementing claimant count for {} to {}", claim, newClaimantCount); } // If the claim is no longer referenced, we want to remove it. We consider the claim to be "no longer referenced" // if the count is 0 and it is no longer writable (if it's writable, it may still be writable by the Content Repository, // even though no existing FlowFile is referencing the claim). if (newClaimantCount == 0 && !claim.isWritable()) { removeClaimantCount(claim); } return newClaimantCount; } }
@Override public int getClaimantCount(final ResourceClaim claim) { if (claim == null) { return 0; } // No need to synchronize on the Resource Claim here, since this is simply obtaining a value. // We synchronize elsewhere because we want to atomically perform multiple operations, such as // getting the claimant count and then updating a queue. However, the operation of obtaining // the ClaimCount and getting its count value has no side effect and therefore can be performed // without synchronization (since the claimantCounts map and the ClaimCount are also both thread-safe // and there is no need for the two actions of obtaining the ClaimCount and getting its Count value // to be performed atomically). final ClaimCount counter = claimantCounts.get(claim); return counter == null ? 0 : counter.getCount().get(); }