opends/src/server/org/opends/server/loggers/FileNamingPolicy.java
@@ -22,7 +22,7 @@ * CDDL HEADER END * * * Copyright 2006-2008 Sun Microsystems, Inc. * Copyright 2006-2009 Sun Microsystems, Inc. */ package org.opends.server.loggers; @@ -58,7 +58,9 @@ public FilenameFilter getFilenameFilter(); /** * Gets all the existing files named by this policy. * Gets all the existing files named by this policy in the parent directoy * of the initial file. The initial file is excluded from this list if it * exists. * * @return The files named by this policy or <code>null</code> if an * error occured. opends/src/server/org/opends/server/loggers/SizeBasedRetentionPolicy.java
@@ -22,7 +22,7 @@ * CDDL HEADER END * * * Copyright 2006-2008 Sun Microsystems, Inc. * Copyright 2006-2009 Sun Microsystems, Inc. */ package org.opends.server.loggers; import org.opends.messages.Message; @@ -55,8 +55,10 @@ * The tracer object for the debug logger. */ private static final DebugTracer TRACER = getTracer(); private static final File[] EMPTY_FILE_LIST = new File[0]; private long size = 0; private FileComparator comparator; private SizeLimitLogRetentionPolicyCfg config; /** @@ -66,6 +68,7 @@ SizeLimitLogRetentionPolicyCfg config) { this.size = config.getDiskSpaceUsed(); this.comparator = new FileComparator(); this.config = config; config.addSizeLimitChangeListener(this); @@ -115,8 +118,6 @@ message); } ArrayList<File> filesToDelete = new ArrayList<File>(); long totalLength = 0; for (File file : files) { @@ -130,26 +131,28 @@ if (totalLength <= size) { return new File[0]; return EMPTY_FILE_LIST; } long freeSpaceNeeded = totalLength - size; // Sort files based on last modified time. Arrays.sort(files, new FileComparator()); Arrays.sort(files, comparator); long freedSpace = 0; for (int j = files.length - 1; j < 1; j--) int j; for (j = files.length - 1; j >= 0; j--) { freedSpace += files[j].length(); filesToDelete.add(files[j]); if (freedSpace >= freeSpaceNeeded) { break; } } return filesToDelete.toArray(new File[0]); File[] filesToDelete = new File[files.length - j]; System.arraycopy(files, j, filesToDelete, 0, filesToDelete.length); return filesToDelete; } /** opends/src/server/org/opends/server/loggers/TimeStampNaming.java
@@ -22,7 +22,7 @@ * CDDL HEADER END * * * Copyright 2006-2008 Sun Microsystems, Inc. * Copyright 2006-2009 Sun Microsystems, Inc. */ package org.opends.server.loggers; @@ -43,7 +43,8 @@ */ private static final DebugTracer TRACER = getTracer(); File file; private File file; private TimeStampNamingFilter filter; /** * The FilenameFilter implementation for this naming policy to filter @@ -66,8 +67,45 @@ { return false; } name = name.toLowerCase(); return name.startsWith(file.getName().toLowerCase()); String initialFileName = file.getName(); // Make sure it is the expected length. if(name.length() != initialFileName.length() + 16) { return false; } int pos; // Make sure we got the expected name prefix. for(pos = 0; pos < initialFileName.length(); pos++) { if(name.charAt(pos) != initialFileName.charAt(pos)) { return false; } } // Make sure there is a period between the prefix and timestamp. if(name.charAt(pos) != '.') { return false; } char c; // Make sure there are 14 numbers for the timestamp. for(pos++; pos < name.length() - 1; pos++) { c = name.charAt(pos); if(c < 48 || c > 57) { return false; } } // And ends with an Z. return name.charAt(pos) == 'Z'; } } @@ -80,6 +118,7 @@ public TimeStampNaming(File file) { this.file = file; this.filter = new TimeStampNamingFilter(); } /** @@ -103,7 +142,7 @@ */ public FilenameFilter getFilenameFilter() { return new TimeStampNamingFilter(); return filter; } /** @@ -112,7 +151,7 @@ public File[] listFiles() { File directory = file.getParentFile(); File[] files = directory.listFiles(getFilenameFilter()); File[] files = directory.listFiles(filter); if(files == null) {