public final class PipeFactory extends Object
Pipe
implementations:
byteArrayRingBuffer(int)
byteBufferRingBuffer(ByteBuffer)
ByteBuffer
elasticPipe()
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 closedPerformance | 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(ByteBuffer delegate) |
static Pipe |
elasticPipe() |
static Pipe |
elasticPipe(ProducerWhichThrows<? extends Pipe,? extends IOException> pipes) |
static Pipe |
mappedFileRingBuffer(File file,
int capacity,
boolean deleteFileOnClose) |
static Pipe |
mappedTempFileRingBuffer(int capacity) |
static Pipe |
randomAccessFileRingBuffer(File file,
long capacity,
boolean deleteFileOnClose) |
static Pipe |
randomAccessTempFileRingBuffer(long capacity) |
public static Pipe byteArrayRingBuffer(int capacity)
capacity
public static Pipe randomAccessTempFileRingBuffer(long capacity) throws IOException
RandomAccessFile
, which is deleted when the pipe is
closedIOException
public static Pipe randomAccessFileRingBuffer(File file, long capacity, boolean deleteFileOnClose) throws 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 closedRuntimeException
- capacity is less than oneIOException
public static Pipe byteBufferRingBuffer(ByteBuffer delegate)
ByteBuffer
and has the same sizeByteBuffer.allocate(int)
,
ByteBuffer.allocateDirect(int)
public static Pipe mappedTempFileRingBuffer(int capacity) throws IOException
memory-mapped
temporary file,
which will be unmapped and deleted when the pipe is closedIOException
public static Pipe mappedFileRingBuffer(File file, int capacity, boolean deleteFileOnClose) throws 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 closedIOException
public 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 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)Copyright © 2018 Arno Unkrig. All rights reserved.