Package com.illumon.iris.db.util.file
Class TrackedFileHandleFactory
java.lang.Object
com.illumon.iris.db.util.file.TrackedFileHandleFactory
- All Implemented Interfaces:
FileHandleFactory
public class TrackedFileHandleFactory extends Object implements FileHandleFactory
Simple least-recently-opened "cache" for FileHandles, to avoid running up against ulimits.
Will probably not achieve satisfactory results if the number of file handles concurrently in active use
exceeds capacity.
Note that returned FileHandles may be closed asynchronously by the factory.
TODO: Consider adding a lookup to enable handle sharing. Not necessary for current usage.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.illumon.iris.db.util.file.FileHandleFactory
FileHandleFactory.FileToHandleFunction, FileHandleFactory.OpenOptionsHelper
-
Field Summary
-
Constructor Summary
Constructors Constructor Description TrackedFileHandleFactory(com.fishlib.io.sched.Scheduler scheduler, int capacity)
Constructor with default target usage ratio of 0.9 (90%) and cleanup attempts every 60 seconds.TrackedFileHandleFactory(com.fishlib.io.sched.Scheduler scheduler, int capacity, double targetUsageRatio, long cleanupIntervalMillis)
Full constructor. -
Method Summary
Modifier and Type Method Description void
closeAll()
int
getCapacity()
static TrackedFileHandleFactory
getInstance()
com.fishlib.io.sched.Scheduler
getScheduler()
int
getSize()
double
getTargetUsageRatio()
int
getTargetUsageThreshold()
FileHandle
makeHandle(File file, OpenOption[] openOptions)
Create a newFileHandle
with the specified set ofOpenOption
s.
-
Field Details
-
Constructor Details
-
TrackedFileHandleFactory
public TrackedFileHandleFactory(@NotNull com.fishlib.io.sched.Scheduler scheduler, int capacity, double targetUsageRatio, long cleanupIntervalMillis)Full constructor.- Parameters:
scheduler
- The scheduler to use for cleanupcapacity
- The total number of file handles to allow outstandingtargetUsageRatio
- The target usage threshold as a ratio of capacity, in [0.1, 0.9]cleanupIntervalMillis
- The interval for asynchronous cleanup attempts
-
TrackedFileHandleFactory
public TrackedFileHandleFactory(@NotNull com.fishlib.io.sched.Scheduler scheduler, int capacity)Constructor with default target usage ratio of 0.9 (90%) and cleanup attempts every 60 seconds.- Parameters:
scheduler
- The scheduler to use for cleanupcapacity
- The total number of file handles to allow outstanding
-
-
Method Details
-
getInstance
-
getScheduler
public com.fishlib.io.sched.Scheduler getScheduler() -
getCapacity
public int getCapacity() -
getTargetUsageRatio
public double getTargetUsageRatio() -
getTargetUsageThreshold
public int getTargetUsageThreshold() -
getSize
public int getSize() -
makeHandle
@NotNull public final FileHandle makeHandle(@NotNull File file, @NotNull OpenOption[] openOptions) throws IOExceptionDescription copied from interface:FileHandleFactory
Create a newFileHandle
with the specified set ofOpenOption
s.- Specified by:
makeHandle
in interfaceFileHandleFactory
- Parameters:
file
- TheFile
to openopenOptions
- TheOpenOption
s to use- Returns:
- The new file handle
- Throws:
IOException
-
closeAll
public void closeAll()
-