FileDeleter (Lucene 10.5.1 core API)
Description: declaration: package: org.apache.lucene.util, class: FileDeleter

Package org.apache.lucene.util

# Class FileDeleter

java.lang.Object
org.apache.lucene.util.FileDeleter

public final class FileDeleter extends Object
This class provides ability to track the reference counts of a set of index files and delete them when their counts decreased to 0.

This class is NOT thread-safe, the user should make sure the thread-safety themselves

NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static enum`
  `FileDeleter.MsgType`
  Types of messages this file deleter will broadcast REF: messages about reference FILE: messages about file
  `static final class`
  `FileDeleter.RefCount`
  Tracks the reference count for a single index file:

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FileDeleter(Directory directory, BiConsumer<FileDeleter.MsgType,String> messenger)`
  Create a new FileDeleter with a messenger consumes various verbose messages

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `decRef(Collection<String> fileNames)`
  Decrease ref counts for all provided files, delete them if ref counts down to 0, even on exception.
  `void`
  `deleteFileIfNoRef(String fileName)`
  `void`
  `deleteFilesIfNoRef(Collection<String> files)`
  delete only files that are unref'ed
  `boolean`
  `exists(String fileName)`
  return true only if file is touched and also has larger than 0 ref count
  `void`
  `forceDelete(String fileName)`
  `Set<String>`
  `getAllFiles()`
  get all files, some of them may have ref count 0
  `int`
  `getRefCount(String fileName)`
  get ref count for a provided file, if the file is not yet recorded, this method will return 0
  `Set<String>`
  `getUnrefedFiles()`
  get files that are touched but not incref'ed
  `void`
  `incRef(String fileName)`
  `void`
  `incRef(Collection<String> fileNames)`
  `void`
  `initRefCount(String fileName)`
  if the file is not yet recorded, this method will create a new RefCount object with count 0

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

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

- ## Constructor Details

  - ### FileDeleter

    public FileDeleter(Directory directory, BiConsumer<FileDeleter.MsgType,String> messenger)
    Create a new FileDeleter with a messenger consumes various verbose messages
    Parameters:
      `directory` - the index directory
      `messenger` - two arguments will be passed in, `FileDeleter.MsgType` and the actual message in String. Can be null if the user do not want debug infos

- ## Method Details

  - ### incRef

    public void incRef(Collection<String> fileNames)

  - ### incRef

    public void incRef(String fileName)

  - ### decRef

    public void decRef(Collection<String> fileNames) throws IOException
    Decrease ref counts for all provided files, delete them if ref counts down to 0, even on exception. Throw first exception hit, if any
    Throws:
      `IOException`

  - ### initRefCount

    public void initRefCount(String fileName)
    if the file is not yet recorded, this method will create a new RefCount object with count 0

  - ### getRefCount

    public int getRefCount(String fileName)
    get ref count for a provided file, if the file is not yet recorded, this method will return 0

  - ### getAllFiles

    public Set<String> getAllFiles()
    get all files, some of them may have ref count 0

  - ### exists

    public boolean exists(String fileName)
    return true only if file is touched and also has larger than 0 ref count

  - ### getUnrefedFiles

    public Set<String> getUnrefedFiles()
    get files that are touched but not incref'ed

  - ### deleteFilesIfNoRef

    public void deleteFilesIfNoRef(Collection<String> files) throws IOException
    delete only files that are unref'ed
    Throws:
      `IOException`

  - ### forceDelete

    public void forceDelete(String fileName) throws IOException
    Throws:
      `IOException`

  - ### deleteFileIfNoRef

    public void deleteFileIfNoRef(String fileName) throws IOException
    Throws:
      `IOException`