private synchronized void applyTimeBasedRetention() { long now = System.currentTimeMillis(); long minTime = now - TimeUnit.SECONDS.toMillis(retentionConfig.getAgeSec()); ArrayList<Path> toDelete = new ArrayList<>(); for (Path path : retainedPaths) { // oldest first File file = path.toFile(); if (file.lastModified() < minTime) toDelete.add(path); else break; } for (Path path : toDelete) { trace.info("deleting file {}", path); path.toFile().delete(); } retainedPaths.removeAll(toDelete); }
@Override public String toString() { return String.format("fileCount:%d aggSize:%d ageSec:%d", getFileCount(), getAggregateFileSize(), getAgeSec()); }
periodMsec, periodMsec, TimeUnit.MILLISECONDS); if (retentionConfig.getAgeSec() > 0) { long periodMsec = retentionConfig.getPeriodMsec(); getExecutor().scheduleAtFixedRate(
private static <T> void checkFileWriterConfig(FileWriterRetentionConfig cfg, int fileCnt, long aggSize, long ageSec, long periodMsec) { assertEquals(fileCnt, cfg.getFileCount()); assertEquals(aggSize, cfg.getAggregateFileSize()); assertEquals(ageSec, cfg.getAgeSec()); assertEquals(periodMsec, cfg.getPeriodMsec()); cfg.toString(); int falseFileCnt = fileCnt-1; int trueFileCnt = fileCnt+1; long falseAggSize = aggSize-1; long trueAggSize = aggSize+1; assertFalse("fileCnt:"+fileCnt+" aggSize:"+aggSize, cfg.evaluate(falseFileCnt, falseAggSize)); if (fileCnt!=0) assertTrue("fileCnt:"+fileCnt+" aggSize:"+aggSize, cfg.evaluate(trueFileCnt, falseAggSize)); if (aggSize!=0) assertTrue("fileCnt:"+fileCnt+" aggSize:"+aggSize, cfg.evaluate(falseFileCnt, trueAggSize)); }