public class ChunkFilePipe extends Object implements JslipcPipe, JslipcBinman
FilePipe
this implementation is based on chunk
files which are written to a directory by a WritableChunkFileChannel
and consumed by a ReadableChunkFileChannel
. Once consumed, a chunk is
immediately deleted from disk, so only yet unread data needs to be persisted.
This way, the ChunkFilePipe does not block like the SharedMemoryPipe
and does not waste disk space like the FilePipe
. The price is speed,
since creating vast of files costs time.both directories
or
a directory and the role
of
this end of the pipe. This implementation provides a
JslipcBinman.cleanUpOnClose()
method, which will delete the files on
close()
.Modifier and Type | Field and Description |
---|---|
static String |
YANG_TO_YIN_NAME |
static String |
YIN_TO_YANG_NAME |
Constructor and Description |
---|
ChunkFilePipe(File sourceDir,
File sinkDir)
Creates a pipe with a
ReadableChunkFileChannel and
WritableChunkFileChannel based on the given directories. |
ChunkFilePipe(File directory,
JslipcRole role)
This is an alternative to
ChunkFilePipe(File, File) where you do
not pass the two files, but a directory hosting two files
yangToYin and yinToYang . |
Modifier and Type | Method and Description |
---|---|
void |
cleanUpOnClose()
Attempts to clean up any resources on
Closeable.close() if they are no longer needed. |
void |
close() |
static File |
getSinkDir(File directory,
JslipcRole role) |
static File |
getSourceDir(File directory,
JslipcRole role) |
WritableChunkFileChannel |
sink() |
ReadableChunkFileChannel |
source() |
String |
toString() |
public static final String YANG_TO_YIN_NAME
public static final String YIN_TO_YANG_NAME
public ChunkFilePipe(File directory, JslipcRole role) throws IOException
ChunkFilePipe(File, File)
where you do
not pass the two files, but a directory hosting two files
yangToYin
and yinToYang
. The files are created
if they do not yet exist. Which one is used for source or sink depends on
the role:
role | source | sink |
---|---|---|
yang | yinToYang | yangToYin |
yin | yangToYin | yinToYang |
yin
or
yang
. It is just needed to distinguish the
endpoints of the pipe, so one end should have the role yin, the other
yang.directory
- role
- IOException
public ChunkFilePipe(File sourceDir, File sinkDir)
ReadableChunkFileChannel
and
WritableChunkFileChannel
based on the given directories.sourceDir
- the directory to create the ReadableChunkFileChannel
from.sinkDir
- the directory to create the WritableChunkFileChannel
from.public void cleanUpOnClose()
JslipcBinman
Closeable.close()
if they are no longer needed.cleanUpOnClose
in interface JslipcBinman
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public ReadableChunkFileChannel source() throws IOException
source
in interface JslipcPipe
IOException
public WritableChunkFileChannel sink() throws IOException
sink
in interface JslipcPipe
IOException
public static File getSourceDir(File directory, JslipcRole role) throws IOException
IOException
public static File getSinkDir(File directory, JslipcRole role) throws IOException
IOException
Copyright © 2014. All Rights Reserved.