Package io.agroal.pool.util
Class AutoCloseableElement
java.lang.Object
io.agroal.pool.util.AutoCloseableElement
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
ConnectionWrapper,ResultSetWrapper,StatementWrapper
Abstract class to track auto-closeable resources by having them forming a collection between themselves.
This class is designed to prevent leaks of Agroal JDBC wrapper objects.
Once a new wrapper is created it tries to insert itself between the head and the first element of the list (if it exists).
There is the invariant that at any given point in time the list can be traversed from the head and all inserted elements are reachable.
As an implementation detail, the collection formed is actually a stack (FILO behaviour) and is thread-safe.
The resources do not remove themselves on close. It's assumed that the implementations of this interface are wrappers and the contents are dropped at that moment. Also, allowing removal of elements would introduce an undesirable amount of complexity to this class.
- Author:
- Luis Barreiro
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of resources that were not properly closed.abstract booleanisClosed()static AutoCloseableElementnewHead()Create a special marker element to be used as head of a collection.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.AutoCloseable
close
-
Constructor Details
-
AutoCloseableElement
-
-
Method Details
-
isClosed
- Throws:
Exception
-
closeAllAutocloseableElements
public int closeAllAutocloseableElements()Returns the number of resources that were not properly closed. The resources are closed in the process and the collection is cleared. This method should be invoked on the collection head only, otherwise it may not traverse the whole collection. -
newHead
Create a special marker element to be used as head of a collection.
-