final int entrySize,
@NotNull final Replica.EntryExternalizable externalizable) {
//todo HCOLL-71 fix the 128 padding
final int entrySize0 = entrySize + 128;
entryBuffer = new ByteBufferBytes(ByteBuffer.allocateDirect(entrySize0));
// in bound
Executors.newSingleThreadExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
final Thread thread = new Thread(r, "reader-map" + externalizable);
thread.setDaemon(true);
return thread;
}
}).execute(new Runnable() {
@Override
public void run() {
// this is used in nextEntry() below, its what could be described as callback method
try {
for (; ; ) {
byte[] item = null;
try {
for (; ; ) {
isReadingEntry.set(true);
item = input.poll();
if (item == null) {
isReadingEntry.set(false);
Thread.sleep(1);
} else {
break;
}
}
final ByteBufferBytes bufferBytes = new ByteBufferBytes(ByteBuffer.wrap(item));
while (bufferBytes.remaining() > 0) {
final long entrySize = bufferBytes.readStopBit();
final long position = bufferBytes.position();
final long limit = bufferBytes.limit();
bufferBytes.limit(position + entrySize);
externalizable.readExternalEntry(bufferBytes);
bufferBytes.position(position);
bufferBytes.limit(limit);
// skip onto the next entry
bufferBytes.skip(entrySize);
}
isReadingEntry.set(false);
} catch (InterruptedException e1) {
LOG.warn("", e1);
}
}
} catch (Exception e) {
LOG.warn("", e);
}
}
});
// out bound
Executors.newSingleThreadExecutor().execute(new Runnable() {
@Override
public void run() {
buffer = new ByteBufferBytes(ByteBuffer.allocate(entrySize0 * MAX_NUMBER_OF_ENTRIES_PER_CHUNK));
// this is used in nextEntry() below, its what could be described as callback method
final Replica.AbstractEntryCallback entryCallback =
new Replica.AbstractEntryCallback() {