com.continuent.tungsten.common.commands
Class FileCommands

java.lang.Object
  extended by com.continuent.tungsten.common.commands.FileCommands

public class FileCommands
extends java.lang.Object

This class contains utilities for managing file used in logs.


Constructor Summary
FileCommands()
           
 
Method Summary
static void deleteFiles(java.io.File[] files, boolean wait)
          Delete a list of one or more files in array order.
static java.io.File[] filesOverModDate(java.io.File[] files, Interval retention)
          Returns members of a file array whose last modification dates are older than a specific retention period.
static java.io.File[] filesOverRetention(java.io.File dir, java.lang.String prefix, int retention)
          Compute and return a list of files matching a particular prefixed that exceed the number of files to retain.
static java.io.File[] filesOverRetentionAndInactive(java.io.File dir, java.lang.String prefix, int retention, java.lang.String activeFile)
          Returns only those files that are over retention and whose names sort lexically below an active file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileCommands

public FileCommands()
Method Detail

deleteFiles

public static void deleteFiles(java.io.File[] files,
                               boolean wait)
Delete a list of one or more files in array order. If a particular file is deleted in the array, we guarantee that any previous files are also deleted. Files after may or may not be deleted due to failures.

Parameters:
files - Files to be deleted
wait - If true, execute synchronously

filesOverRetention

public static java.io.File[] filesOverRetention(java.io.File dir,
                                                java.lang.String prefix,
                                                int retention)
Compute and return a list of files matching a particular prefixed that exceed the number of files to retain. The files sorted in ascending order. The list is returned minus the last N files, where N is the retention.

Parameters:
dir - Directory in which to see files
prefix - File prefix against which to match
retention - Number of files to retain.
Returns:
Array of files that exceed the retention. The array is empty if the directory does not exist.

filesOverRetentionAndInactive

public static java.io.File[] filesOverRetentionAndInactive(java.io.File dir,
                                                           java.lang.String prefix,
                                                           int retention,
                                                           java.lang.String activeFile)
Returns only those files that are over retention and whose names sort lexically below an active file. This allows us to delete files whose retention is expired and that have been processed.

Parameters:
dir - Directory in which to see files
prefix - File prefix against which to match
retention - Number of files to retain.
activeFile - Currently active file; this and higher files should not be deleted. Ignored if null.
Returns:
Array of files that exceed the retention. The array is empty if the directory does not exist.

filesOverModDate

public static java.io.File[] filesOverModDate(java.io.File[] files,
                                              Interval retention)
Returns members of a file array whose last modification dates are older than a specific retention period.

Parameters:
files - List of files to evaluate
retention - Retention period
Returns:
an array of files modified before the given date