public Date getNextTriggeringDate(Date now) { return getEndOfNextNthPeriod(now, 1); }
public Date getNextTriggeringDate(Date now) { return getEndOfNextNthPeriod(now, 1); }
public Date getNextTriggeringDate(Date now) { return getEndOfNextNthPeriod(now, 1); }
public Date getNextTriggeringDate(Date now) { return getEndOfNextNthPeriod(now, 1); }
public long getStartOfCurrentPeriodWithGMTOffsetCorrection(long now, TimeZone timezone) { Calendar aCal = Calendar.getInstance(timezone); aCal.setTimeInMillis(now); Date d = getEndOfNextNthPeriod(aCal.getTime(), 0); long gmtOffset = aCal.get(Calendar.ZONE_OFFSET) + aCal.get(Calendar.DST_OFFSET); return d.getTime() + gmtOffset; } }
public long getStartOfCurrentPeriodWithGMTOffsetCorrection(long now, TimeZone timezone) { Date toppedDate; // there is a bug in Calendar which prevents it from // computing the correct DST_OFFSET when the time changes { Calendar aCal = Calendar.getInstance(timezone); aCal.setTimeInMillis(now); toppedDate = getEndOfNextNthPeriod(aCal.getTime(), 0); } Calendar secondCalendar = Calendar.getInstance(timezone); secondCalendar.setTimeInMillis(toppedDate.getTime()); long gmtOffset = secondCalendar.get(Calendar.ZONE_OFFSET) + secondCalendar.get(Calendar.DST_OFFSET); return toppedDate.getTime() + gmtOffset; } }
public long getStartOfCurrentPeriodWithGMTOffsetCorrection(long now, TimeZone timezone) { Date toppedDate; // there is a bug in Calendar which prevents it from // computing the correct DST_OFFSET when the time changes { Calendar aCal = Calendar.getInstance(timezone); aCal.setTimeInMillis(now); toppedDate = getEndOfNextNthPeriod(aCal.getTime(), 0); } Calendar secondCalendar = Calendar.getInstance(timezone); secondCalendar.setTimeInMillis(toppedDate.getTime()); long gmtOffset = secondCalendar.get(Calendar.ZONE_OFFSET) + secondCalendar.get(Calendar.DST_OFFSET); return toppedDate.getTime() + gmtOffset; } }
@Override public boolean accept(File dir, String path) { Date fileDate = dateParser.parseFilename(path); fileDate = rc.normalizeDate(fileDate); Date refDate = rc.getEndOfNextNthPeriod(baseDate, -maxHistory); refDate = rc.normalizeDate(refDate); return fileDate.compareTo(refDate) < 0; } };
private Calendar getEndOfNextNthPeriod(String dateFormat, Date date, int n) { RollingCalendar rc = new RollingCalendar(dateFormat); Date nextDate = rc.getEndOfNextNthPeriod(date, n); Calendar cal = Calendar.getInstance(GMT_TIMEZONE, Locale.US); cal.setTime(nextDate); return cal; }
public void clean(Date now) { long nowInMillis = now.getTime(); // for a live appender periodsElapsed is expected to be 1 int periodsElapsed = computeElapsedPeriodsSinceLastClean(nowInMillis); lastHeartBeat = nowInMillis; if (periodsElapsed > 1) { addInfo("Multiple periods, i.e. " + periodsElapsed + " periods, seem to have elapsed. This is expected at application start."); } for (int i = 0; i < periodsElapsed; i++) { int offset = getPeriodOffsetForDeletionTarget() - i; Date dateOfPeriodToClean = rc.getEndOfNextNthPeriod(now, offset); cleanPeriod(dateOfPeriodToClean); } }
public void clean(Date now) { long nowInMillis = now.getTime(); // for a live appender periodsElapsed is expected to be 1 int periodsElapsed = computeElapsedPeriodsSinceLastClean(nowInMillis); lastHeartBeat = nowInMillis; if (periodsElapsed > 1) { addInfo("Multiple periods, i.e. " + periodsElapsed + " periods, seem to have elapsed. This is expected at application start."); } for (int i = 0; i < periodsElapsed; i++) { int offset = getPeriodOffsetForDeletionTarget() - i; Date dateOfPeriodToClean = rc.getEndOfNextNthPeriod(now, offset); cleanPeriod(dateOfPeriodToClean); } }
public void clean(Date now) { long nowInMillis = now.getTime(); // for a live appender periodsElapsed is expected to be 1 int periodsElapsed = computeElapsedPeriodsSinceLastClean(nowInMillis); lastHeartBeat = nowInMillis; if (periodsElapsed > 1) { addInfo("Multiple periods, i.e. " + periodsElapsed + " periods, seem to have elapsed. This is expected at application start."); } for (int i = 0; i < periodsElapsed; i++) { int offset = getPeriodOffsetForDeletionTarget() - i; Date dateOfPeriodToClean = rc.getEndOfNextNthPeriod(now, offset); cleanPeriod(dateOfPeriodToClean); } }
void capTotalSize(Date now) { long totalSize = 0; long totalRemoved = 0; for (int offset = 0; offset < maxHistory; offset++) { Date date = rc.getEndOfNextNthPeriod(now, -offset); File[] matchingFileArray = getFilesInPeriod(date); descendingSortByLastModified(matchingFileArray); for (File f : matchingFileArray) { long size = f.length(); if (totalSize + size > totalSizeCap) { addInfo("Deleting [" + f + "]" + " of size " + new FileSize(size)); totalRemoved += size; f.delete(); } totalSize += size; } } addInfo("Removed " + new FileSize(totalRemoved) + " of files"); }
void capTotalSize(Date now) { long totalSize = 0; long totalRemoved = 0; for (int offset = 0; offset < maxHistory; offset++) { Date date = rc.getEndOfNextNthPeriod(now, -offset); File[] matchingFileArray = getFilesInPeriod(date); descendingSortByLastModified(matchingFileArray); for (File f : matchingFileArray) { long size = f.length(); if (totalSize + size > totalSizeCap) { addInfo("Deleting [" + f + "]" + " of size " + new FileSize(size)); totalRemoved += size; f.delete(); } totalSize += size; } } addInfo("Removed " + new FileSize(totalRemoved) + " of files"); }
void capTotalSize(Date now) { long totalSize = 0; long totalRemoved = 0; for (int offset = 0; offset < maxHistory; offset++) { Date date = rc.getEndOfNextNthPeriod(now, -offset); File[] matchingFileArray = getFilesInPeriod(date); descendingSortByLastModified(matchingFileArray); for (File f : matchingFileArray) { long size = f.length(); if (totalSize + size > totalSizeCap) { addInfo("Deleting [" + f + "]" + " of size " + new FileSize(size)); totalRemoved += size; f.delete(); } totalSize += size; } } addInfo("Removed " + new FileSize(totalRemoved) + " of files"); }
@Test public void testVaryingNumberOfHourlyPeriods() { RollingCalendar rc = new RollingCalendar("yyyy-MM-dd_HH"); long MILLIS_IN_HOUR = 3600 * 1000; for (int p = 100; p > -100; p--) { long now = 1223325293589L; // Mon Oct 06 22:34:53 CEST 2008 Date result = rc.getEndOfNextNthPeriod(new Date(now), p); long expected = now - (now % (MILLIS_IN_HOUR)) + p * MILLIS_IN_HOUR; assertEquals(expected, result.getTime()); } }
int fileIndex = 0; for (int offset = 0; offset < _maxHistory; ++offset) { final Date date = rc.getEndOfNextNthPeriod(now, -offset); final File[] matchingFileArray = getFilesInPeriod(date); descendingSortByLastModified(matchingFileArray);
@Test public void testVaryingNumberOfDailyPeriods() { RollingCalendar rc = new RollingCalendar("yyyy-MM-dd"); final long MILLIS_IN_DAY = 24 * 3600 * 1000; for (int p = 20; p > -100; p--) { long now = 1223325293589L; // Mon Oct 06 22:34:53 CEST 2008 Date nowDate = new Date(now); Date result = rc.getEndOfNextNthPeriod(nowDate, p); long offset = rc.getTimeZone().getRawOffset() + rc.getTimeZone().getDSTSavings(); long origin = now - ((now + offset) % (MILLIS_IN_DAY)); long expected = origin + p * MILLIS_IN_DAY; assertEquals("p=" + p, expected, result.getTime()); } }