TarFiles implements Closeable { public void collectBlobReferences(Consumer<String> collector, Predicate<GCGeneration> reclaim) throws IOException { Node head; lock.writeLock().lock(); try { if (writer != null) { internalNewWriter(); } head = readers; } finally { lock.writeLock().unlock(); } for (TarReader reader : iterable(head)) { reader.collectBlobReferences(collector, reclaim); } } private  TarFiles(Builder builder); static Builder builder(); @Override void close(); @Override String toString(); long size(); int readerCount(); int segmentCount(); void flush(); boolean containsSegment(long msb, long lsb); Buffer readSegment(long msb, long lsb); void writeSegment(UUID id, byte[] buffer, int offset, int length, GCGeneration generation, Set<UUID> references, Set<String> binaryReferences); CleanupResult cleanup(CleanupContext context); void collectBlobReferences(Consumer<String> collector, Predicate<GCGeneration> reclaim); Iterable<UUID> getSegmentIds(); Map<UUID, Set<UUID>> getGraph(String fileName); Map<String, Set<UUID>> getIndices(); FileReaper createFileReaper();  }
@Test public void testCollectBlobReferences() throws Exception { writeSegmentWithBinaryReferences(randomUUID()); writeSegmentWithBinaryReferences(randomUUID(), "a"); writeSegmentWithBinaryReferences(randomUUID(), "b", "c"); Set<String> references = new HashSet<>(); tarFiles.collectBlobReferences(references::add, gen -> false); assertEquals(references, new HashSet<>(asList("a", "b", "c"))); }
@Test public void testCollectBlobReferencesWithGenerationFilter() throws Exception { GCGeneration ok = newGCGeneration(1, 1, false); GCGeneration ko = newGCGeneration(2, 2, false); writeSegmentWithBinaryReferences(randomUUID(), ok, "ok"); writeSegmentWithBinaryReferences(randomUUID(), ko, "ko"); Set<String> references = new HashSet<>(); tarFiles.collectBlobReferences(references::add, ko::equals); assertEquals(references, singleton("ok")); }