Class SharedFileBackedOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.opendaylight.controller.cluster.io.FileBackedOutputStream
-
- org.opendaylight.controller.cluster.io.SharedFileBackedOutputStream
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
public class SharedFileBackedOutputStream extends FileBackedOutputStream
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 callincrementUsageCount(). Thecleanup()method decrements the usage count and, when it reaches 0, theFileBackedOutputStream.cleanup()is called to delete the backing file.- Author:
- Thomas Pantelis
-
-
Constructor Summary
Constructors Constructor Description SharedFileBackedOutputStream(int fileThreshold, String fileDirectory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcleanup()Overridden to decrement the usage count.intgetUsageCount()Returns the current usage count.voidincrementUsageCount()Increments the usage count.<T> voidsetOnCleanupCallback(Consumer<T> callback, T context)Sets the callback to be notified whenFileBackedOutputStream.cleanup()is called to delete the backing file.-
Methods inherited from class org.opendaylight.controller.cluster.io.FileBackedOutputStream
asByteSource, close, flush, getCount, write, write, write
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Constructor Detail
-
SharedFileBackedOutputStream
public SharedFileBackedOutputStream(int fileThreshold, String fileDirectory)
-
-
Method Detail
-
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
public <T> void setOnCleanupCallback(Consumer<T> callback, T context)
Sets the callback to be notified whenFileBackedOutputStream.cleanup()is called to delete the backing file.
-
cleanup
public void cleanup()
Overridden to decrement the usage count.- Overrides:
cleanupin classFileBackedOutputStream
-
-