Package de.aristaflow.adept2.util.io
Class RereadableContent.RrcCleanup
- java.lang.Object
-
- de.aristaflow.adept2.util.CleanupTask.AbstractCleanupTask<IOException>
-
- de.aristaflow.adept2.util.io.RereadableContent.RrcCleanup
-
- All Implemented Interfaces:
CleanupTask<IOException>
- Enclosing class:
- RereadableContent
protected static final class RereadableContent.RrcCleanup extends CleanupTask.AbstractCleanupTask<IOException>
TheCleanupTask
doing the clean-up (RereadableContent.close()
) independently from theRereadableContent
. This allows to use it as post-mortem action of theRereadableContent
.
An instance of this class exists for eachRereadableContent
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 aRereadableContent
, its final clean-up will occur, for instance, the temporary file will be deleted. Instance tracking is done via an arbitraryObject
but since the cleanup is referenced by the corresponding instance ofInputStream
(orRereadableContent
) viaCleaner
theObject
can be kept internal to this clean-up task.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface de.aristaflow.adept2.util.CleanupTask
CleanupTask.AbstractCleanupTask<EX extends Exception>, CleanupTask.AtomicCloseTask, CleanupTask.CloseAndResetTask, CleanupTask.MutableCloseTask
-
-
Field Summary
Fields Modifier and Type Field Description protected Collection<Object>
existingStreams
All objects for which streams (rather their clean-up tasks) have been created.protected Closeable
finalCleanup
The final clean-up to be executed after all streams and theRereadableContent
itself have been closed/cleaned up.protected Object
stream
The (object of the) stream for which thisCleanupTask
has been registered.-
Fields inherited from class de.aristaflow.adept2.util.CleanupTask.AbstractCleanupTask
descriptor, logger
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
RrcCleanup(String descriptor, RereadableContent rc)
Creates a new clean-up for closing as post-mortem action of aRereadableContent
or a created input stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanup(boolean explicit)
Performs the actual clean-up.-
Methods inherited from class de.aristaflow.adept2.util.CleanupTask.AbstractCleanupTask
getDescriptor
-
-
-
-
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, theRereadableContent
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 thisCleanupTask
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 theRereadableContent
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 aRereadableContent
or a created input stream. Also used for RereadableContent.close() explicit clean-up.- Parameters:
descriptor
- A string meaningfully describing the cleanup.rc
- TheRereadableContent
providing theexistingStreams
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 byCleanup
and must NOT be called directly!- Parameters:
explicit
- Whether the clean-up was triggered explicitly viaCleanup.clean()
. Otherwise it was triggered implicitly as a post-mortem action by the object becoming phantom reachable.- Throws:
IOException
-
-