Class AbstractHandleableCloseable<T extends HandleableCloseable<T>>

  • Type Parameters:
    T - the type of the closeable resource
    All Implemented Interfaces:
    Closeable, AutoCloseable, HandleableCloseable<T>

    public abstract class AbstractHandleableCloseable<T extends HandleableCloseable<T>>
    extends Object
    implements HandleableCloseable<T>
    A basic implementation of a closeable resource. Use as a convenient base class for your closeable resources. Ensures that the close() method is idempotent; implements the registry of close handlers.
    • Constructor Detail

      • AbstractHandleableCloseable

        protected AbstractHandleableCloseable​(Executor executor)
        Basic constructor.
        Parameters:
        executor - the executor used to execute the close notification handlers
      • AbstractHandleableCloseable

        protected AbstractHandleableCloseable​(Executor executor,
                                              boolean autoClose)
        Basic constructor.
        Parameters:
        executor - the executor used to execute the close notification handlers
        autoClose - true if this instance should automatically close on finalize
    • Method Detail

      • isOpen

        public boolean isOpen()
        Read the status of this resource. This is just a snapshot in time; there is no guarantee that the resource will remain open for any amount of time, even if this method returns true.
        Specified by:
        isOpen in interface HandleableCloseable<T extends HandleableCloseable<T>>
        Returns:
        true if the resource is still open
      • closeAction

        protected void closeAction()
                            throws IOException
        Called exactly once when the close() method is invoked; the actual close operation should take place here. This method must call closeComplete(), directly or indirectly, for the close operation to finish (it may happen in another thread but it must happen). This method should not expect the closeComplete() call to be made from another thread from the same thread pool that may cause close(). As close will block, this can result in situations where all threads in the pool are blocked on close() method calls, which means the closeComplete() will never be run.
        Throws:
        RemotingException - if the close failed
        IOException
      • closeComplete

        protected void closeComplete()
        Call when close is complete.
      • closeFailed

        protected void closeFailed​(IOException cause)
        Call if an async close has failed.
        Parameters:
        cause - the failure cause
      • getExecutor

        protected Executor getExecutor()
        Get the executor to use for handler invocation.
        Returns:
        the executor
      • finalize

        protected void finalize()
                         throws Throwable
        Finalize this closeable instance. If the instance hasn't been closed, it is closed and a warning is logged.
        Overrides:
        finalize in class Object
        Throws:
        Throwable