Package org.apache.storm.daemon.logviewer.utils

# Class DirectoryCleaner

java.lang.Object
org.apache.storm.daemon.logviewer.utils.DirectoryCleaner

public class DirectoryCleaner extends Object
Provide methods to help Logviewer to clean up files in directories and to get a list of files without worrying about excessive memory usage.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `MAX_NUMBER_OF_FILES_FOR_DIR`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DirectoryCleaner(StormMetricsRegistry metricsRegistry)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `org.apache.storm.daemon.logviewer.utils.DeletionMeta`
  `deleteOldestWhileTooLarge(List<Path> dirs, long quota, boolean forPerDir, Set<Path> activeDirs)`
  If totalSize of files exceeds the either the per-worker quota or global quota, Logviewer deletes oldest inactive log files in a worker directory or in all worker dirs.
  `List<Path>`
  `getFilesForDir(Path dir)`
  Lists files in directory.
  `DirectoryStream<Path>`
  `getStreamForDirectory(Path dir)`
  Creates DirectoryStream for give directory.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### MAX_NUMBER_OF_FILES_FOR_DIR

    public static final int MAX_NUMBER_OF_FILES_FOR_DIR
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### DirectoryCleaner

    public DirectoryCleaner(StormMetricsRegistry metricsRegistry)

- ## Method Details

  - ### getStreamForDirectory

    public DirectoryStream<Path> getStreamForDirectory(Path dir) throws IOException
    Creates DirectoryStream for give directory.
    Parameters:
      `dir` - File instance representing specific directory
    Returns:
      DirectoryStream
    Throws:
      `IOException`

  - ### deleteOldestWhileTooLarge

    public org.apache.storm.daemon.logviewer.utils.DeletionMeta deleteOldestWhileTooLarge(List<Path> dirs, long quota, boolean forPerDir, Set<Path> activeDirs) throws IOException
    If totalSize of files exceeds the either the per-worker quota or global quota, Logviewer deletes oldest inactive log files in a worker directory or in all worker dirs. We use the parameter forPerDir to switch between the two deletion modes.
    Parameters:
      `dirs` - the list of directories to be scanned for deletion
      `quota` - the per-dir quota or the total quota for the all directories
      `forPerDir` - if true, deletion happens for a single dir; otherwise, for all directories globally
      `activeDirs` - only for global deletion, we want to skip the active logs in activeDirs
    Returns:
      number of files deleted
    Throws:
      `IOException`

  - ### getFilesForDir

    public List<Path> getFilesForDir(Path dir) throws IOException
    Lists files in directory. Note that to avoid memory problem, we only return the first 1024 files in a directory.
    Parameters:
      `dir` - directory to get file list
    Returns:
      files in directory
    Throws:
      `IOException`