public class LibaioContext<Callback extends SubmitInfo> extends Object implements Closeable
LibaioFile
.
LibaioFile
as you need special alignments
when dealing with O_DIRECT files.
Constructor and Description |
---|
LibaioContext(int queueSize,
boolean useSemaphore)
The queue size here will use resources defined on the kernel parameter
fs.aio-max-nr .
|
Modifier and Type | Method and Description |
---|---|
void |
close()
This is used to close the libaio queues and cleanup the native data used.
|
protected void |
finalize() |
static void |
freeBuffer(ByteBuffer buffer)
This will call posix free to release the inner buffer allocated at
newAlignedBuffer(int, int) . |
static int |
getBlockSize(File path) |
static int |
getBlockSize(String path) |
static long |
getTotalMaxIO()
This is used to validate leaks on tests.
|
static boolean |
isLoaded() |
static boolean |
lock(int fd) |
void |
memsetBuffer(ByteBuffer buffer)
It will reset all the positions on the buffer to 0, using memset.
|
static void |
memsetBuffer(ByteBuffer buffer,
int size) |
static ByteBuffer |
newAlignedBuffer(int size,
int alignment)
Buffers for O_DIRECT need to use posix_memalign.
|
static int |
open(String path,
boolean direct)
it will return a file descriptor.
|
static LibaioFile |
openControlFile(String file,
boolean direct)
It will open a file disassociated with any sort of factory.
|
LibaioFile<Callback> |
openFile(File file,
boolean direct)
It will open a file.
|
LibaioFile<Callback> |
openFile(String file,
boolean direct)
It will open a file.
|
void |
poll()
It will start polling and will keep doing until the context is closed.
|
int |
poll(Callback[] callbacks,
int min,
int max)
It will poll the libaio queue for results.
|
static void |
resetMaxAIO()
This is used on tests validating for leaks.
|
void |
submitRead(int fd,
long position,
int size,
ByteBuffer bufferWrite,
Callback callback) |
void |
submitWrite(int fd,
long position,
int size,
ByteBuffer bufferWrite,
Callback callback)
|
public LibaioContext(int queueSize, boolean useSemaphore)
queueSize
- the size to be initialize on libaio
io_queue_init which can't be higher than /proc/sys/fs/aio-max-nr.useSemaphore
- should block on a semaphore avoiding using more submits than what's available.public static boolean isLoaded()
public static long getTotalMaxIO()
public void memsetBuffer(ByteBuffer buffer)
buffer
- a native buffer.
spublic static void resetMaxAIO()
public void submitWrite(int fd, long position, int size, ByteBuffer bufferWrite, Callback callback) throws IOException
fd
- the file descriptorposition
- the write positionsize
- number of bytes to usebufferWrite
- the native buffercallback
- a callbackIOException
- in case of errorpublic void submitRead(int fd, long position, int size, ByteBuffer bufferWrite, Callback callback) throws IOException
IOException
public void close()
close
in interface Closeable
close
in interface AutoCloseable
protected void finalize() throws Throwable
public LibaioFile<Callback> openFile(File file, boolean direct) throws IOException
file
- the file to be open.direct
- will set ODIRECT.IOException
- in case of error.public LibaioFile<Callback> openFile(String file, boolean direct) throws IOException
file
- the file to be open.direct
- should use O_DIRECT when opening the file.IOException
- in case of error.public static LibaioFile openControlFile(String file, boolean direct) throws IOException
file
- a file namedirect
- will use O_DIRECTIOException
- in case of error.public int poll(Callback[] callbacks, int min, int max)
SubmitInfo.onError(int, String)
in case of failures,
but it won't call done method for you.callbacks
- area to receive the callbacks passed on submission.The size of this callback has to
be greater than the parameter max.min
- the minimum number of elements to receive. It will block until this is achieved.max
- The maximum number of elements to receive.LibaioFile.write(long, int, java.nio.ByteBuffer, SubmitInfo)
,
LibaioFile.read(long, int, java.nio.ByteBuffer, SubmitInfo)
public void poll()
SubmitInfo.onError(int, String)
and
SubmitInfo.done()
.
In case of error, both SubmitInfo.onError(int, String)
and
SubmitInfo.done()
are called.public static int open(String path, boolean direct)
path
- the file name.direct
- translates as O_DIRECT On openpublic static ByteBuffer newAlignedBuffer(int size, int alignment)
LibaioFile.newBuffer(int)
.size
- needs to be % alignmentalignment
- the alignment used at the dispositivepublic static void freeBuffer(ByteBuffer buffer)
newAlignedBuffer(int, int)
.buffer
- a native buffer allocated with newAlignedBuffer(int, int)
.public static boolean lock(int fd)
public static void memsetBuffer(ByteBuffer buffer, int size)
public static int getBlockSize(File path)
public static int getBlockSize(String path)
Copyright © 2016 JBoss by Red Hat. All rights reserved.