/** * @param filename * @param blocks * @return A JSON String of <code>filename</code> and counts of <code>blocks</code> * @throws JsonGenerationException * @throws JsonMappingException * @throws IOException */ public static String toJSON(final String filename, final NavigableSet<CachedBlock> blocks) throws JsonGenerationException, JsonMappingException, IOException { CachedBlockCountsPerFile counts = new CachedBlockCountsPerFile(filename); for (CachedBlock cb: blocks) { counts.count++; counts.size += cb.getSize(); BlockType bt = cb.getBlockType(); if (bt != null && bt.isData()) { counts.countData++; counts.sizeData += cb.getSize(); } } return MAPPER.writeValueAsString(counts); }
/** * @param cb * @return True if full.... if we won't be adding any more. */ public boolean update(final CachedBlock cb) { if (isFull()) return true; NavigableSet<CachedBlock> set = this.cachedBlockByFile.get(cb.getFilename()); if (set == null) { set = new ConcurrentSkipListSet<>(); this.cachedBlockByFile.put(cb.getFilename(), set); } set.add(cb); this.size += cb.getSize(); this.count++; BlockType bt = cb.getBlockType(); if (bt != null && bt.isData()) { this.dataBlockCount++; this.dataSize += cb.getSize(); } long age = (this.now - cb.getCachedTime())/NANOS_PER_SECOND; this.hist.add(age, 1); return false; }
/** * @param cb * @return The block content of <code>bc</code> as a String minus the filename. */ public static String toStringMinusFileName(final CachedBlock cb, final long now) { return "offset=" + cb.getOffset() + ", size=" + cb.getSize() + ", age=" + (now - cb.getCachedTime()) + ", type=" + cb.getBlockType() + ", priority=" + cb.getBlockPriority(); }
private void logPerFile(final BlockCacheUtil.CachedBlocksByFile cbsbf) throws IOException { for (Map.Entry<String, NavigableSet<CachedBlock>> e: cbsbf.getCachedBlockStatsByFile().entrySet()) { int count = 0; long size = 0; int countData = 0; long sizeData = 0; for (CachedBlock cb: e.getValue()) { count++; size += cb.getSize(); BlockType bt = cb.getBlockType(); if (bt != null && bt.isData()) { countData++; sizeData += cb.getSize(); } } LOG.info("filename=" + e.getKey() + ", count=" + count + ", countData=" + countData + ", size=" + size + ", sizeData=" + sizeData); LOG.info(BlockCacheUtil.toJSON(e.getKey(), e.getValue())); } }
/** * @param filename * @param blocks * @return A JSON String of <code>filename</code> and counts of <code>blocks</code> * @throws JsonGenerationException * @throws JsonMappingException * @throws IOException */ public static String toJSON(final String filename, final NavigableSet<CachedBlock> blocks) throws JsonGenerationException, JsonMappingException, IOException { CachedBlockCountsPerFile counts = new CachedBlockCountsPerFile(filename); for (CachedBlock cb: blocks) { counts.count++; counts.size += cb.getSize(); BlockType bt = cb.getBlockType(); if (bt != null && bt.isData()) { counts.countData++; counts.sizeData += cb.getSize(); } } return MAPPER.writeValueAsString(counts); }
/** * @param cb * @return True if full.... if we won't be adding any more. */ public boolean update(final CachedBlock cb) { if (isFull()) return true; NavigableSet<CachedBlock> set = this.cachedBlockByFile.get(cb.getFilename()); if (set == null) { set = new ConcurrentSkipListSet<CachedBlock>(); this.cachedBlockByFile.put(cb.getFilename(), set); } set.add(cb); this.size += cb.getSize(); this.count++; BlockType bt = cb.getBlockType(); if (bt != null && bt.isData()) { this.dataBlockCount++; this.dataSize += cb.getSize(); } long age = this.now - cb.getCachedTime(); this.age.update(age); return false; }
/** * @param cb * @return The block content of <code>bc</code> as a String minus the filename. */ public static String toStringMinusFileName(final CachedBlock cb, final long now) { return "offset=" + cb.getOffset() + ", size=" + cb.getSize() + ", age=" + (now - cb.getCachedTime()) + ", type=" + cb.getBlockType() + ", priority=" + cb.getBlockPriority(); }
private void logPerFile(final BlockCacheUtil.CachedBlocksByFile cbsbf) throws IOException { for (Map.Entry<String, NavigableSet<CachedBlock>> e: cbsbf.getCachedBlockStatsByFile().entrySet()) { int count = 0; long size = 0; int countData = 0; long sizeData = 0; for (CachedBlock cb: e.getValue()) { count++; size += cb.getSize(); BlockType bt = cb.getBlockType(); if (bt != null && bt.isData()) { countData++; sizeData += cb.getSize(); } } LOG.info("filename=" + e.getKey() + ", count=" + count + ", countData=" + countData + ", size=" + size + ", sizeData=" + sizeData); LOG.info(BlockCacheUtil.toJSON(e.getKey(), e.getValue())); } }