- java.lang.Object
-
- org.apache.lucene.util.FileDeleter
-
public final class FileDeleter extends java.lang.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FileDeleter.MsgType
Types of messages this file deleter will broadcast REF: messages about reference FILE: messages about filestatic class
FileDeleter.RefCount
Tracks the reference count for a single index file:
-
Field Summary
Fields Modifier and Type Field Description private Directory
directory
private java.util.function.BiConsumer<FileDeleter.MsgType,java.lang.String>
messenger
private java.util.Map<java.lang.String,FileDeleter.RefCount>
refCounts
private static FileDeleter.RefCount
ZERO_REF
-
Constructor Summary
Constructors Constructor Description FileDeleter(Directory directory, java.util.function.BiConsumer<FileDeleter.MsgType,java.lang.String> messenger)
Create a new FileDeleter with a messenger consumes various verbose messages
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
decRef(java.lang.String fileName)
Returns true if the file should be deletedvoid
decRef(java.util.Collection<java.lang.String> fileNames)
Decrease ref counts for all provided files, delete them if ref counts down to 0, even on exception.private void
delete(java.lang.String fileName)
private void
delete(java.util.Collection<java.lang.String> toDelete)
void
deleteFileIfNoRef(java.lang.String fileName)
void
deleteFilesIfNoRef(java.util.Collection<java.lang.String> files)
delete only files that are unref'edboolean
exists(java.lang.String fileName)
return true only if file is touched and also has larger than 0 ref countvoid
forceDelete(java.lang.String fileName)
java.util.Set<java.lang.String>
getAllFiles()
get all files, some of them may have ref count 0int
getRefCount(java.lang.String fileName)
get ref count for a provided file, if the file is not yet recorded, this method will return 0private FileDeleter.RefCount
getRefCountInternal(java.lang.String fileName)
java.util.Set<java.lang.String>
getUnrefedFiles()
get files that are touched but not incref'edvoid
incRef(java.lang.String fileName)
void
incRef(java.util.Collection<java.lang.String> fileNames)
void
initRefCount(java.lang.String fileName)
if the file is not yet recorded, this method will create a new RefCount object with count 0
-
-
-
Field Detail
-
refCounts
private final java.util.Map<java.lang.String,FileDeleter.RefCount> refCounts
-
directory
private final Directory directory
-
messenger
private final java.util.function.BiConsumer<FileDeleter.MsgType,java.lang.String> messenger
-
ZERO_REF
private static final FileDeleter.RefCount ZERO_REF
-
-
Constructor Detail
-
FileDeleter
public FileDeleter(Directory directory, java.util.function.BiConsumer<FileDeleter.MsgType,java.lang.String> messenger)
Create a new FileDeleter with a messenger consumes various verbose messages- Parameters:
directory
- the index directorymessenger
- 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(java.util.Collection<java.lang.String> fileNames)
-
incRef
public void incRef(java.lang.String fileName)
-
decRef
public void decRef(java.util.Collection<java.lang.String> fileNames) throws java.io.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:
java.io.IOException
-
decRef
private boolean decRef(java.lang.String fileName)
Returns true if the file should be deleted
-
getRefCountInternal
private FileDeleter.RefCount getRefCountInternal(java.lang.String fileName)
-
initRefCount
public void initRefCount(java.lang.String fileName)
if the file is not yet recorded, this method will create a new RefCount object with count 0
-
getRefCount
public int getRefCount(java.lang.String fileName)
get ref count for a provided file, if the file is not yet recorded, this method will return 0
-
getAllFiles
public java.util.Set<java.lang.String> getAllFiles()
get all files, some of them may have ref count 0
-
exists
public boolean exists(java.lang.String fileName)
return true only if file is touched and also has larger than 0 ref count
-
getUnrefedFiles
public java.util.Set<java.lang.String> getUnrefedFiles()
get files that are touched but not incref'ed
-
deleteFilesIfNoRef
public void deleteFilesIfNoRef(java.util.Collection<java.lang.String> files) throws java.io.IOException
delete only files that are unref'ed- Throws:
java.io.IOException
-
forceDelete
public void forceDelete(java.lang.String fileName) throws java.io.IOException
- Throws:
java.io.IOException
-
deleteFileIfNoRef
public void deleteFileIfNoRef(java.lang.String fileName) throws java.io.IOException
- Throws:
java.io.IOException
-
delete
private void delete(java.util.Collection<java.lang.String> toDelete) throws java.io.IOException
- Throws:
java.io.IOException
-
delete
private void delete(java.lang.String fileName) throws java.io.IOException
- Throws:
java.io.IOException
-
-