Package org.apache.iceberg.io
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
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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCloseable
(Closeable closeable) Register a closeable to be managed by this class.void
addCloseable
(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.
-
Constructor Details
-
CloseableGroup
public CloseableGroup()
-
-
Method Details
-
addCloseable
Register a closeable to be managed by this class. -
addCloseable
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
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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-