Class CloseableGroup

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

    public class CloseableGroup
    extends java.lang.Object
    implements java.io.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 Summary

      Constructors 
      Constructor Description
      CloseableGroup()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addCloseable​(java.io.Closeable closeable)
      Register a closeable to be managed by this class.
      void addCloseable​(java.lang.AutoCloseable autoCloseable)
      Register an autocloseables to be managed by this class.
      void close()
      Close all the registered resources.
      void setSuppressCloseFailure​(boolean shouldSuppress)
      Whether to suppress failure when any of the closeable this class tracks throws exception during closing.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CloseableGroup

        public CloseableGroup()
    • Method Detail

      • addCloseable

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

        public void addCloseable​(java.lang.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 java.io.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 java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException