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,XAConnectionWrapper,XAResourceWrapper
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, rather there is a pruneClosed() method that must be called to remove subsequent closed elements.
- Author:
- Luis Barreiro
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of resources that were not properly closed.protected abstract booleanabstract booleanisClosed()static AutoCloseableElementnewHead()Create a special marker element to be used as head of a collection.voidCheck for runs of closed elements after the current position and remove them from the linked listMethods 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
-
internalClosed
protected abstract boolean internalClosed() -
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. -
pruneClosed
public void pruneClosed()Check for runs of closed elements after the current position and remove them from the linked list -
newHead
Create a special marker element to be used as head of a collection.
-