Interface ICloseableRegistry

  • All Superinterfaces:
    AutoCloseable, Closeable
    All Known Implementing Classes:
    CloseableRegistry

    @Internal
    public interface ICloseableRegistry
    extends Closeable
    This class allows to register instances of Closeable, which are all closed if this registry is closed.

    Registering to an already closed registry will throw an exception and close the provided Closeable

    All methods in this class are thread-safe.

    This class closes all registered Closeables in the reverse registration order.

    • Method Detail

      • registerCloseable

        void registerCloseable​(Closeable closeable)
                        throws IOException
        Registers a Closeable with the registry. In case the registry is already closed, this method throws an IllegalStateException and closes the passed Closeable.
        Parameters:
        closeable - Closeable to register.
        Throws:
        IOException - exception when the registry was closed before.
      • registerCloseableTemporarily

        default Closeable registerCloseableTemporarily​(Closeable closeable)
                                                throws IOException
        Same as registerCloseable(Closeable) but allows to unregister the passed closeable by closing the returned closeable.
        Parameters:
        closeable - Closeable to register.
        Returns:
        another Closeable that unregisters the passed closeable.
        Throws:
        IOException - exception when the registry was closed before.
      • unregisterCloseable

        boolean unregisterCloseable​(Closeable closeable)
        Removes a Closeable from the registry.
        Parameters:
        closeable - instance to remove from the registry.
        Returns:
        true if the closeable was previously registered and became unregistered through this call.
      • isClosed

        boolean isClosed()
        Returns:
        true if this registry was closed.