@Test public void testPurgeUnused() throws IOException { ReferenceCountedACLCache cache = new ReferenceCountedACLCache(); List<ACL> acl1 = createACL("one"); List<ACL> acl2 = createACL("two"); List<ACL> acl3 = createACL("three"); List<ACL> acl4 = createACL("four"); List<ACL> acl5 = createACL("five"); Long aclId1 = convertACLsNTimes(cache, acl1, 1); Long aclId2 = convertACLsNTimes(cache, acl2, 2); Long aclId3 = convertACLsNTimes(cache, acl3, 3); Long aclId4 = convertACLsNTimes(cache, acl4, 4); Long aclId5 = convertACLsNTimes(cache, acl5, 5); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BinaryOutputArchive archive = BinaryOutputArchive.getArchive(baos); cache.serialize(archive); BinaryInputArchive inArchive = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray())); ReferenceCountedACLCache deserializedCache = new ReferenceCountedACLCache(); deserializedCache.deserialize(inArchive); callAddUsageNTimes(deserializedCache, aclId1, 1); callAddUsageNTimes(deserializedCache, aclId2, 2); deserializedCache.purgeUnused(); assertEquals(2, deserializedCache.size()); assertEquals(aclId1, deserializedCache.convertAcls(acl1)); assertEquals(aclId2, deserializedCache.convertAcls(acl2)); assertFalse(acl3.equals(deserializedCache.convertAcls(acl3))); assertFalse(acl4.equals(deserializedCache.convertAcls(acl4))); assertFalse(acl5.equals(deserializedCache.convertAcls(acl5))); }
public synchronized void purgeUnused() { Iterator<Map.Entry<Long, AtomicLongWithEquals>> refCountIter = referenceCounter.entrySet().iterator(); while (refCountIter.hasNext()) { Map.Entry<Long, AtomicLongWithEquals> entry = refCountIter.next(); if (entry.getValue().get() <= 0) { Long acl = entry.getKey(); aclKeyMap.remove(longKeyMap.get(acl)); longKeyMap.remove(acl); refCountIter.remove(); } } }
ReferenceCountedACLCache { public synchronized void purgeUnused() { Iterator<Map.Entry<Long, AtomicLongWithEquals>> refCountIter = referenceCounter.entrySet().iterator(); while (refCountIter.hasNext()) { Map.Entry<Long, AtomicLongWithEquals> entry = refCountIter.next(); if (entry.getValue().get() <= 0) { Long acl = entry.getKey(); aclKeyMap.remove(longKeyMap.get(acl)); longKeyMap.remove(acl); refCountIter.remove(); } } } }
ReferenceCountedACLCache { public synchronized void purgeUnused() { Iterator<Map.Entry<Long, AtomicLongWithEquals>> refCountIter = referenceCounter.entrySet().iterator(); while (refCountIter.hasNext()) { Map.Entry<Long, AtomicLongWithEquals> entry = refCountIter.next(); if (entry.getValue().get() <= 0) { Long acl = entry.getKey(); aclKeyMap.remove(longKeyMap.get(acl)); longKeyMap.remove(acl); refCountIter.remove(); } } }  }
ReferenceCountedACLCache { public synchronized void purgeUnused() { Iterator<Map.Entry<Long, AtomicLongWithEquals>> refCountIter = referenceCounter.entrySet().iterator(); while (refCountIter.hasNext()) { Map.Entry<Long, AtomicLongWithEquals> entry = refCountIter.next(); if (entry.getValue().get() <= 0) { Long acl = entry.getKey(); aclKeyMap.remove(longKeyMap.get(acl)); longKeyMap.remove(acl); refCountIter.remove(); } } }  synchronized Long convertAcls(List<ACL> acls); synchronized List<ACL> convertLong(Long longVal); synchronized void deserialize(InputArchive ia); synchronized void serialize(OutputArchive oa); int size(); synchronized void addUsage(Long acl); synchronized void removeUsage(Long acl); synchronized void purgeUnused(); }
ReferenceCountedACLCache { public synchronized void purgeUnused() { Iterator<Map.Entry<Long, AtomicLongWithEquals>> refCountIter = referenceCounter.entrySet().iterator(); while (refCountIter.hasNext()) { Map.Entry<Long, AtomicLongWithEquals> entry = refCountIter.next(); if (entry.getValue().get() <= 0) { Long acl = entry.getKey(); aclKeyMap.remove(longKeyMap.get(acl)); longKeyMap.remove(acl); refCountIter.remove(); } } }  synchronized Long convertAcls(List<ACL> acls); synchronized List<ACL> convertLong(Long longVal); synchronized void deserialize(InputArchive ia); synchronized void serialize(OutputArchive oa); int size(); synchronized void addUsage(Long acl); synchronized void removeUsage(Long acl); synchronized void purgeUnused();  }