Class LibaioFile<Callback extends SubmitInfo>
java.lang.Object
org.apache.activemq.artemis.nativo.jlibaio.LibaioFile<Callback>
- All Implemented Interfaces:
AutoCloseable
This is an extension to use libaio.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()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.intlonggetSize()booleanlock()newBuffer(int size) It will allocate a buffer to be used on libaio operations.voidread(long position, int size, ByteBuffer buffer, Callback callback) It will submit a read to the queue.voidwrite(long position, int size, ByteBuffer buffer, Callback callback) It will submit a write to the queue.
-
Field Details
-
open
protected boolean open
-
-
Method Details
-
getBlockSize
public int getBlockSize() -
lock
public boolean lock() -
close
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
getSize
public long getSize()- Returns:
- The size of the file.
-
write
It 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:
IOException- in case of error
-
read
It 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:
IOException- in case of error- See Also:
-
newBuffer
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
-