public final class PipeFactory
extends java.lang.Object
Pipe implementations:
byteArrayRingBuffer(int)byteBufferRingBuffer(ByteBuffer)ByteBufferelasticPipe()elasticPipe(de.unkrig.commons.lang.protocol.ProducerWhichThrows)mappedFileRingBuffer(java.io.File, int, boolean)memory-mapped file, which will be
unmapped and (optionally) deleted when the pipe is closed
mappedTempFileRingBuffer(int)memory-mapped temporary file, which
will be unmapped and deleted when the pipe is closedrandomAccessFileRingBuffer(java.io.File, long, boolean)RandomAccessFile, which will (optionally) be deleted when the pipe is
closed
randomAccessTempFileRingBuffer(long)RandomAccessFile, which is deleted when the pipe is closed| Performance | Resource usage | Size limits | |
|---|---|---|---|
byteArrayRingBuffer(int) |
Fast | Heap memory | 2 GB |
byteBufferRingBuffer(ByteBuffer.allocate(int)) |
Fast | Heap memory | 2 GB |
byteBufferRingBuffer(ByteBuffer.allocateDirect(int)) |
Fast | Off-heap memory | 2 GB |
mappedFileRingBuffer(File, int, boolean) |
Medium | Low | 2 GB, Address space, disk space |
randomAccessFileRingBuffer(File, long, boolean) |
Low | Low | Disk space |
| Modifier and Type | Method and Description |
|---|---|
static Pipe |
byteArrayRingBuffer(int capacity) |
static Pipe |
byteBufferRingBuffer(java.nio.ByteBuffer delegate) |
static Pipe |
elasticPipe() |
static Pipe |
elasticPipe(ProducerWhichThrows<? extends Pipe,? extends java.io.IOException> pipes) |
static Pipe |
mappedFileRingBuffer(java.io.File file,
int capacity,
boolean deleteFileOnClose) |
static Pipe |
mappedTempFileRingBuffer(int capacity) |
static Pipe |
randomAccessFileRingBuffer(java.io.File file,
long capacity,
boolean deleteFileOnClose) |
static Pipe |
randomAccessTempFileRingBuffer(long capacity) |
public static Pipe byteArrayRingBuffer(int capacity)
capacitypublic static Pipe randomAccessTempFileRingBuffer(long capacity) throws java.io.IOException
RandomAccessFile, which is deleted when the pipe is
closedjava.io.IOExceptionpublic static Pipe randomAccessFileRingBuffer(java.io.File file, long capacity, boolean deleteFileOnClose) throws java.io.IOException
file - Will be created if it does not exist; any existing contents will progressively be
overwritten by Pipe.write(byte[], int, int)deleteFileOnClose - Whether to delete the file when the pipe is closedjava.lang.RuntimeException - capacity is less than onejava.io.IOExceptionpublic static Pipe byteBufferRingBuffer(java.nio.ByteBuffer delegate)
ByteBuffer and has the same sizeByteBuffer.allocate(int),
ByteBuffer.allocateDirect(int)public static Pipe mappedTempFileRingBuffer(int capacity) throws java.io.IOException
memory-mapped temporary file,
which will be unmapped and deleted when the pipe is closedjava.io.IOExceptionpublic static Pipe mappedFileRingBuffer(java.io.File file, int capacity, boolean deleteFileOnClose) throws java.io.IOException
capacity - The number of bytes in the file to use for bufferingdeleteFileOnClose - Whether the file should be deleted when the pipe is closedmemory-mapped file, which will be unmapped and (optionally) deleted when
the pipe is closedjava.io.IOExceptionpublic static Pipe elasticPipe()
Pipe that implements infinite capacity and good performance by first allocating a small
in-memory ring buffer, then, if that fills up, a larger one that uses a memory-mapped temporary file,
and eventually one that is backed by a random access file with practically unlimited sizepublic static Pipe elasticPipe(ProducerWhichThrows<? extends Pipe,? extends java.io.IOException> pipes)
pipes - Is invoked when another pipe is needed; the produced pipes are closed when they are no longer
needed, or when the returned pipe is closedPipe that implements infinite capacity by allocating delegate pipes as needed (and
closing them when they are no longer needed)