Class LibaioFile<Callback extends SubmitInfo>
- java.lang.Object
-
- org.apache.activemq.artemis.nativo.jlibaio.LibaioFile<Callback>
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public final class LibaioFile<Callback extends SubmitInfo> extends java.lang.Object implements java.lang.AutoCloseableThis is an extension to use libaio.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanopen
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidfallocate(long size)It will use fallocate to initialize a file.voidfill(int alignment, long size)It will preallocate the file with a given size.intgetBlockSize()longgetSize()booleanlock()java.nio.ByteBuffernewBuffer(int size)It will allocate a buffer to be used on libaio operations.voidread(long position, int size, java.nio.ByteBuffer buffer, Callback callback)It will submit a read to the queue.voidwrite(long position, int size, java.nio.ByteBuffer buffer, Callback callback)It will submit a write to the queue.
-
-
-
Method Detail
-
getBlockSize
public int getBlockSize()
-
lock
public boolean lock()
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
java.io.IOException
-
getSize
public long getSize()
- Returns:
- The size of the file.
-
write
public void write(long position, int size, java.nio.ByteBuffer buffer, Callback callback) throws java.io.IOExceptionIt will submit a write to the queue. The callback sent here will be received on theLibaioContext.poll(SubmitInfo[], int, int)In case of the libaio queue is full (e.g. returning E_AGAIN) this method will return false.
Notice: this won't hold a global reference on buffer, callback should hold a reference towards bufferWrite. And don't free the buffer until the callback was called as this could crash the VM.- Parameters:
position- The position on the file to write. Notice this has to be a multiple of 512.size- The size of the buffer to use while writing.buffer- if you are using O_DIRECT the buffer here needs to be allocated bynewBuffer(int).callback- A callback to be returned on the poll method.- Throws:
java.io.IOException- in case of error
-
read
public void read(long position, int size, java.nio.ByteBuffer buffer, Callback callback) throws java.io.IOExceptionIt will submit a read to the queue. The callback sent here will be received on theLibaioContext.poll(SubmitInfo[], int, int). In case of the libaio queue is full (e.g. returning E_AGAIN) this method will return false.
Notice: this won't hold a global reference on buffer, callback should hold a reference towards bufferWrite. And don't free the buffer until the callback was called as this could crash the VM. *- Parameters:
position- The position on the file to read. Notice this has to be a multiple of 512.size- The size of the buffer to use while reading.buffer- if you are using O_DIRECT the buffer here needs to be allocated bynewBuffer(int).callback- A callback to be returned on the poll method.- Throws:
java.io.IOException- in case of error- See Also:
LibaioContext.poll(SubmitInfo[], int, int)
-
newBuffer
public java.nio.ByteBuffer newBuffer(int size)
It will allocate a buffer to be used on libaio operations. Buffers here are allocated with posix_memalign.
You need to explicitly free the buffer created from here using theLibaioContext.freeBuffer(java.nio.ByteBuffer).- Parameters:
size- the size of the buffer.- Returns:
- the buffer allocated.
-
fill
public void fill(int alignment, long size)It will preallocate the file with a given size.- Parameters:
size- number of bytes to be filled on the file
-
fallocate
public void fallocate(long size)
It will use fallocate to initialize a file.- Parameters:
size- number of bytes to be filled on the file
-
-