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>
TheCleanupTaskdoing 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 eachRereadableContentand 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 arbitraryObjectbut since the cleanup is referenced by the corresponding instance ofInputStream(orRereadableContent) viaCleanertheObjectcan 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>existingStreamsAll objects for which streams (rather their clean-up tasks) have been created.protected CloseablefinalCleanupThe final clean-up to be executed after all streams and theRereadableContentitself have been closed/cleaned up.protected ObjectstreamThe (object of the) stream for which thisCleanupTaskhas been registered.-
Fields inherited from class de.aristaflow.adept2.util.CleanupTask.AbstractCleanupTask
descriptor, logger
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedRrcCleanup(String descriptor, RereadableContent rc)Creates a new clean-up for closing as post-mortem action of aRereadableContentor a created input stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcleanup(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, theRereadableContentis 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 thisCleanupTaskhas 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 theRereadableContentitself 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 aRereadableContentor a created input stream. Also used for RereadableContent.close() explicit clean-up.- Parameters:
descriptor- A string meaningfully describing the cleanup.rc- TheRereadableContentproviding theexistingStreamsto prevent early clean-up as well as the final clean-up.
-
-
Method Detail
-
cleanup
public void cleanup(boolean explicit) throws IOExceptionDescription copied from interface:CleanupTaskPerforms the actual clean-up. This method is only called byCleanupand 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
-
-