As you guys known, libaio can't guarantee ordering over the callbacks.
When you send a callback to AIO, the response could come in an aleatory order from the native layer.
NIO don't have that problem, as it will always guarantee flushing at the correct ordering.
AIO is actually mostly ordered. It will eventually deliver the callbacks out of order.
So, to fix that... each write on AIO will now have a long associated. This is the signature of the native method after my changes:
private native void write(long handle, long sequence,long position, long size,ByteBuffer buffer,AIOCallback aioPackage)
private void callbackDone(final AIOCallback callback, final long sequence, final ByteBuffer buffer)
if (sequence == nextReadSequence) { nextReadSequence++; callback.done(); flushCallbacks();