Package org.opendaylight.raft.spi
Class SharedFileBackedOutputStream
java.lang.Object
java.io.OutputStream
org.opendaylight.raft.spi.FileBackedOutputStream
org.opendaylight.raft.spi.SharedFileBackedOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
A FileBackedOutputStream that allows for sharing in that it maintains a usage count and the backing file isn't
deleted until the usage count reaches 0. The usage count is initialized to 1 on construction. Subsequent users of
the instance must call
incrementUsageCount()
. The cleanup()
method decrements the usage count and,
when it reaches 0, the FileBackedOutputStream.cleanup()
is called to delete the backing file.- Author:
- Thomas Pantelis
-
Nested Class Summary
Nested classes/interfaces inherited from class org.opendaylight.raft.spi.FileBackedOutputStream
FileBackedOutputStream.Configuration
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cleanup()
Overridden to decrement the usage count.int
Returns the current usage count.void
Increments the usage count.void
setOnCleanupCallback
(Runnable callback) Sets the callback to be notified whenFileBackedOutputStream.cleanup()
is called to delete the backing file.Methods inherited from class org.opendaylight.raft.spi.FileBackedOutputStream
close, flush, getCount, toStreamSource, write, write, write
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
SharedFileBackedOutputStream
Default constructor. Resulting instance uses the given file threshold, and does not reset the data when theSizedStreamSource
returned byFileBackedOutputStream.toStreamSource()
is finalized.- Parameters:
config
- the configuration.
-
-
Method Details
-
incrementUsageCount
public void incrementUsageCount()Increments the usage count. This must be followed by a corresponding call tocleanup()
when this instance is no longer needed. -
getUsageCount
public int getUsageCount()Returns the current usage count.- Returns:
- the current usage count
-
setOnCleanupCallback
Sets the callback to be notified whenFileBackedOutputStream.cleanup()
is called to delete the backing file.- Parameters:
callback
- the callback
-
cleanup
public void cleanup()Overridden to decrement the usage count.- Overrides:
cleanup
in classFileBackedOutputStream
-