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.
  • 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 cleanup
      capacity - The total number of file handles to allow outstanding
      targetUsageRatio - 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 cleanup
      capacity - The total number of file handles to allow outstanding
  • Method Details

    • getInstance

      public static TrackedFileHandleFactory 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 IOException
      Description copied from interface: FileHandleFactory
      Create a new FileHandle with the specified set of OpenOptions.
      Specified by:
      makeHandle in interface FileHandleFactory
      Parameters:
      file - The File to open
      openOptions - The OpenOptions to use
      Returns:
      The new file handle
      Throws:
      IOException
    • closeAll

      public void closeAll()