Class AutoCloseableElement

java.lang.Object
io.agroal.pool.util.AutoCloseableElement
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
ConnectionWrapper, ResultSetWrapper, StatementWrapper, XAConnectionWrapper, XAResourceWrapper

public abstract class AutoCloseableElement extends Object implements AutoCloseable
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 Details

  • Method Details

    • isClosed

      public abstract boolean isClosed() throws Exception
      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

      public static AutoCloseableElement newHead()
      Create a special marker element to be used as head of a collection.