Class CloseableGroup

java.lang.Object
org.apache.iceberg.io.CloseableGroup
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
ArrowReader, AvroIterable, CloseableIterable.ConcatCloseableIterable, ManifestReader, ParallelIterable, ParquetIterable, ParquetReader, SortedMerge, VectorizedParquetReader, VectorizedTableScanIterable

public class CloseableGroup extends Object implements Closeable
This class acts as a helper for handling the closure of multiple resource. It can be used for either inheritance or composition. To use it, register resources to be closed via the add() calls, and call the corresponding close method when needed.

It can take both closeable and autocloseable objects, and handle closeable as autocloseable and guarantee close idempotency by ensuring that each resource will be closed once even with concurrent close calls. It will also wrap checked non-IO exceptions into runtime exceptions.

Users can choose to suppress close failure with this class. By default such failures are not suppressed.

  • Constructor Details

    • CloseableGroup

      public CloseableGroup()
  • Method Details

    • addCloseable

      public void addCloseable(Closeable closeable)
      Register a closeable to be managed by this class.
    • addCloseable

      public void addCloseable(AutoCloseable autoCloseable)
      Register an autocloseables to be managed by this class. It will be handled as a closeable object.
    • setSuppressCloseFailure

      public void setSuppressCloseFailure(boolean shouldSuppress)
      Whether to suppress failure when any of the closeable this class tracks throws exception during closing. This could be helpful to ensure the close method of all resources to be called.
      Parameters:
      shouldSuppress - true if user wants to suppress close failures
    • close

      public void close() throws IOException
      Close all the registered resources. Close method of each resource will only be called once. Checked exception from AutoCloseable will be wrapped to runtime exception.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException