Class 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.
    • Constructor Detail

      • FileDeleter

        public FileDeleter​(Directory directory,
                           BiConsumer<FileDeleter.MsgType,​String> messenger)
        Create a new FileDeleter with a messenger consumes various verbose messages
        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 Detail

      • 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
      • 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