From 5be4cbbaa9065ea0149c6d0b4c58e4c7ae95d247 Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Thu, 20 Sep 2007 20:38:20 +0000
Subject: [PATCH] Fixed an issue where the fixed time log rotation policy is not rotating the logs at the time configured. The rotation time was interpreted as UTC time instead of the local time zone.
---
opends/src/server/org/opends/server/loggers/FixedTimeRotationPolicy.java | 56 +++++++++++++++++++++++---------------------------------
1 files changed, 23 insertions(+), 33 deletions(-)
diff --git a/opends/src/server/org/opends/server/loggers/FixedTimeRotationPolicy.java b/opends/src/server/org/opends/server/loggers/FixedTimeRotationPolicy.java
index 86f290a..0444813 100644
--- a/opends/src/server/org/opends/server/loggers/FixedTimeRotationPolicy.java
+++ b/opends/src/server/org/opends/server/loggers/FixedTimeRotationPolicy.java
@@ -56,22 +56,19 @@
private static final long MS_IN_DAY = 24 * 3600 * 1000;
// The scheduled rotation times as ms offsets from the beginnging of the day.
- private long[] rotationTimes;
+ private int[] rotationTimes;
/**
* {@inheritDoc}
*/
public void initializeLogRotationPolicy(FixedTimeLogRotationPolicyCfg config)
{
- rotationTimes = new long[config.getTimeOfDay().size()];
+ rotationTimes = new int[config.getTimeOfDay().size()];
int i = 0;
for(String time : config.getTimeOfDay())
{
- int hour = Integer.valueOf(time)/100;
- int min = Integer.valueOf(time) - hour*100;
-
- rotationTimes[i++] = hour*3600*1000 + min*60*1000;
+ rotationTimes[i++] = Integer.valueOf(time);
}
Arrays.sort(rotationTimes);
@@ -100,15 +97,12 @@
boolean adminActionRequired = false;
ArrayList<Message> messages = new ArrayList<Message>();
- rotationTimes = new long[config.getTimeOfDay().size()];
+ rotationTimes = new int[config.getTimeOfDay().size()];
int i = 0;
for(String time : config.getTimeOfDay())
{
- int hour = Integer.valueOf(time)/100;
- int min = Integer.valueOf(time) - hour*100;
-
- rotationTimes[i++] = hour*3600*1000 + min*60*1000;
+ rotationTimes[i++] = Integer.valueOf(time);
}
Arrays.sort(rotationTimes);
@@ -121,39 +115,35 @@
*/
public boolean rotateFile(MultifileTextWriter writer)
{
- long currTime = TimeThread.getTime();
- long lastRotationTime = writer.getLastRotationTime();
- long dayOfLastRotation = MS_IN_DAY * (lastRotationTime / MS_IN_DAY);
- long hourOfLastRotation = lastRotationTime - dayOfLastRotation;
+ Calendar lastRotationTime = writer.getLastRotationTime();
- // Find a scheduled rotation time thats right after the last rotation time.
- long hourOfNextRotation = 0;
- for(long time : rotationTimes)
+ Calendar nextRotationTime = (Calendar)lastRotationTime.clone();
+ int i = 0;
+ nextRotationTime.set(Calendar.HOUR_OF_DAY, rotationTimes[i] / 100);
+ nextRotationTime.set(Calendar.MINUTE, rotationTimes[i] % 100);
+ nextRotationTime.set(Calendar.SECOND, 0);
+ while(lastRotationTime.after(nextRotationTime))
{
- if(time > hourOfLastRotation)
+ if(i == rotationTimes.length - 1)
{
- hourOfNextRotation = time;
- break;
+ nextRotationTime.add(Calendar.DATE, 1);
+ i = 0;
}
- }
+ else
+ {
+ i++;
+ }
- if(hourOfNextRotation <= 0)
- {
- // Rotation alrealy happened after the latest fixed time for that day.
- // Set it the first rotation time for the next day.
- hourOfNextRotation = rotationTimes[0] + MS_IN_DAY;
+ nextRotationTime.set(Calendar.HOUR_OF_DAY, rotationTimes[i] / 100);
+ nextRotationTime.set(Calendar.MINUTE, rotationTimes[i] % 100);
}
- long nextRotationTime = dayOfLastRotation + hourOfNextRotation;
-
if (debugEnabled())
{
- TRACER.debugInfo("The next fixed rotation time in %ds",
- (currTime - nextRotationTime)/1000);
+ TRACER.debugInfo("The next fixed rotation time is %s", rotationTimes[i]);
}
- return currTime > nextRotationTime;
-
+ return TimeThread.getCalendar().after(nextRotationTime);
}
}
--
Gitblit v1.10.0