use of org.cojen.tupl.Cursor in project Tupl by cojen.
the class CompressedPageArray method isEmpty.
@Override
public boolean isEmpty() throws IOException {
Cursor c = mPages.newCursor(Transaction.BOGUS);
c.first();
boolean isEmpty = c.key() == null;
c.reset();
return isEmpty;
}
use of org.cojen.tupl.Cursor in project Tupl by cojen.
the class CompressedPageArray method writePage.
@Override
public void writePage(long index, long srcPtr, int offset) throws IOException {
try (Cursor c = mPages.newAccessor(Transaction.BOGUS, keyFor(index))) {
var entry = mCompressors.access();
try {
PageCompressor compressor = entry.get();
int len = compressor.compress(srcPtr, offset, pageSize());
c.valueWrite(0, compressor.compressedBytes(), 0, len);
} finally {
entry.release();
}
}
}
use of org.cojen.tupl.Cursor in project Tupl by cojen.
the class CompressedPageArray method writePage.
@Override
public void writePage(long index, byte[] src, int offset) throws IOException {
try (Cursor c = mPages.newAccessor(Transaction.BOGUS, keyFor(index))) {
var entry = mCompressors.access();
try {
PageCompressor compressor = entry.get();
int len = compressor.compress(src, offset, pageSize());
c.valueWrite(0, compressor.compressedBytes(), 0, len);
} finally {
entry.release();
}
}
}
use of org.cojen.tupl.Cursor in project Tupl by cojen.
the class CompressedPageArray method pageCount.
@Override
public long pageCount() throws IOException {
Cursor c = mPages.newCursor(Transaction.BOGUS);
c.last();
byte[] key = c.key();
c.reset();
return key == null ? 0 : (indexFor(key) + 1);
}
use of org.cojen.tupl.Cursor in project Tupl by cojen.
the class Primer method prime.
private void prime() {
try {
Cursor c = mView.newCursor(Transaction.BOGUS);
try {
c.autoload(false);
while (true) {
byte[] key;
synchronized (this) {
if (mFinished) {
return;
}
int len = mDin.readUnsignedShort();
if (len == 0xffff) {
mFinished = true;
return;
}
key = new byte[len];
mDin.readFully(key);
if (mTaskCount < mTaskLimit)
spawn: {
try {
Runner.start(this::prime);
} catch (Throwable e) {
break spawn;
}
mTaskCount++;
}
}
c.findNearby(key);
}
} catch (IOException e) {
synchronized (this) {
if (mEx == null) {
mEx = e;
}
}
} finally {
c.reset();
}
} finally {
synchronized (this) {
mTaskCount--;
notifyAll();
}
}
}
Aggregations