Class RereadableContent.RrcCleanup

  • All Implemented Interfaces:
    CleanupTask<IOException>
    Enclosing class:
    RereadableContent

    protected static final class RereadableContent.RrcCleanup
    extends CleanupTask.AbstractCleanupTask<IOException>
    The CleanupTask doing the clean-up (RereadableContent.close()) independently from the RereadableContent. This allows to use it as post-mortem action of the RereadableContent.
    An instance of this class exists for each RereadableContent and for each of its input streams. When closing or cleaning-up as post-mortem action, the corresponding instance will be deregistered. If no instance exists for a RereadableContent, its final clean-up will occur, for instance, the temporary file will be deleted. Instance tracking is done via an arbitrary Object but since the cleanup is referenced by the corresponding instance of InputStream (or RereadableContent) via Cleaner the Object can be kept internal to this clean-up task.
    • Field Detail

      • existingStreams

        protected final Collection<Object> existingStreams
        All objects for which streams (rather their clean-up tasks) have been created. Each clean-up task removes its object. As soon as this collection is empty, the RereadableContent is not used any more (or may not even exist any more) and the final cleanup may take place.
      • stream

        protected final Object stream
        The (object of the) stream for which this CleanupTask has been registered. This allows to track existing input streams.
      • finalCleanup

        protected final Closeable finalCleanup
        The final clean-up to be executed after all streams and the RereadableContent itself have been closed/cleaned up.
    • Constructor Detail

      • RrcCleanup

        protected RrcCleanup​(String descriptor,
                             RereadableContent rc)
        Creates a new clean-up for closing as post-mortem action of a RereadableContent or a created input stream. Also used for RereadableContent.close() explicit clean-up.
        Parameters:
        descriptor - A string meaningfully describing the cleanup.
        rc - The RereadableContent providing the existingStreams to prevent early clean-up as well as the final clean-up.
    • Method Detail

      • cleanup

        public void cleanup​(boolean explicit)
                     throws IOException
        Description copied from interface: CleanupTask
        Performs the actual clean-up. This method is only called by Cleanup and must NOT be called directly!
        Parameters:
        explicit - Whether the clean-up was triggered explicitly via Cleanup.clean(). Otherwise it was triggered implicitly as a post-mortem action by the object becoming phantom reachable.
        Throws:
        IOException