use of io.cdap.cdap.messaging.store.RawPayloadTableEntry in project cdap by caskdata.
the class LevelDBPayloadTable method read.
@Override
protected CloseableIterator<RawPayloadTableEntry> read(byte[] startRow, byte[] stopRow, final int limit) throws IOException {
final DBScanIterator iterator = new DBScanIterator(levelDB, startRow, stopRow);
return new AbstractCloseableIterator<RawPayloadTableEntry>() {
private final RawPayloadTableEntry tableEntry = new RawPayloadTableEntry();
private boolean closed = false;
private int maxLimit = limit;
@Override
protected RawPayloadTableEntry computeNext() {
if (closed || maxLimit <= 0 || (!iterator.hasNext())) {
return endOfData();
}
Map.Entry<byte[], byte[]> row = iterator.next();
maxLimit--;
return tableEntry.set(row.getKey(), row.getValue());
}
@Override
public void close() {
try {
iterator.close();
} finally {
endOfData();
closed = true;
}
}
};
}
use of io.cdap.cdap.messaging.store.RawPayloadTableEntry in project cdap by cdapio.
the class HBasePayloadTable method read.
@Override
public CloseableIterator<RawPayloadTableEntry> read(byte[] startRow, byte[] stopRow, final int limit) throws IOException {
Scan scan = tableUtil.buildScan().setStartRow(startRow).setStopRow(stopRow).setCaching(scanCacheRows).build();
final ResultScanner scanner = DistributedScanner.create(table, scan, rowKeyDistributor, scanExecutor);
return new AbstractCloseableIterator<RawPayloadTableEntry>() {
private final RawPayloadTableEntry tableEntry = new RawPayloadTableEntry();
private boolean closed = false;
private int maxLimit = limit;
@Override
protected RawPayloadTableEntry computeNext() {
if (closed || maxLimit <= 0) {
return endOfData();
}
Result result;
try {
result = scanner.next();
} catch (IOException e) {
throw exceptionHandler.handleAndWrap(e);
}
if (result == null) {
return endOfData();
}
maxLimit--;
return tableEntry.set(rowKeyDistributor.getOriginalKey(result.getRow()), result.getValue(columnFamily, COL));
}
@Override
public void close() {
try {
scanner.close();
} finally {
endOfData();
closed = true;
}
}
};
}
use of io.cdap.cdap.messaging.store.RawPayloadTableEntry in project cdap by cdapio.
the class LevelDBPayloadTable method read.
@Override
protected CloseableIterator<RawPayloadTableEntry> read(byte[] startRow, byte[] stopRow, final int limit) throws IOException {
final DBScanIterator iterator = new DBScanIterator(levelDB, startRow, stopRow);
return new AbstractCloseableIterator<RawPayloadTableEntry>() {
private final RawPayloadTableEntry tableEntry = new RawPayloadTableEntry();
private boolean closed = false;
private int maxLimit = limit;
@Override
protected RawPayloadTableEntry computeNext() {
if (closed || maxLimit <= 0 || (!iterator.hasNext())) {
return endOfData();
}
Map.Entry<byte[], byte[]> row = iterator.next();
maxLimit--;
return tableEntry.set(row.getKey(), row.getValue());
}
@Override
public void close() {
try {
iterator.close();
} finally {
endOfData();
closed = true;
}
}
};
}
use of io.cdap.cdap.messaging.store.RawPayloadTableEntry in project cdap by caskdata.
the class HBasePayloadTable method persist.
@Override
public void persist(Iterator<RawPayloadTableEntry> entries) throws IOException {
List<Put> batchPuts = new ArrayList<>();
while (entries.hasNext()) {
RawPayloadTableEntry tableEntry = entries.next();
Put put = tableUtil.buildPut(rowKeyDistributor.getDistributedKey(tableEntry.getKey())).add(columnFamily, COL, tableEntry.getValue()).build();
batchPuts.add(put);
}
try {
if (!batchPuts.isEmpty()) {
mutator.mutate(batchPuts);
mutator.flush();
}
} catch (IOException e) {
throw exceptionHandler.handle(e);
}
}
use of io.cdap.cdap.messaging.store.RawPayloadTableEntry in project cdap by caskdata.
the class HBasePayloadTable method read.
@Override
public CloseableIterator<RawPayloadTableEntry> read(byte[] startRow, byte[] stopRow, final int limit) throws IOException {
Scan scan = tableUtil.buildScan().setStartRow(startRow).setStopRow(stopRow).setCaching(scanCacheRows).build();
final ResultScanner scanner = DistributedScanner.create(table, scan, rowKeyDistributor, scanExecutor);
return new AbstractCloseableIterator<RawPayloadTableEntry>() {
private final RawPayloadTableEntry tableEntry = new RawPayloadTableEntry();
private boolean closed = false;
private int maxLimit = limit;
@Override
protected RawPayloadTableEntry computeNext() {
if (closed || maxLimit <= 0) {
return endOfData();
}
Result result;
try {
result = scanner.next();
} catch (IOException e) {
throw exceptionHandler.handleAndWrap(e);
}
if (result == null) {
return endOfData();
}
maxLimit--;
return tableEntry.set(rowKeyDistributor.getOriginalKey(result.getRow()), result.getValue(columnFamily, COL));
}
@Override
public void close() {
try {
scanner.close();
} finally {
endOfData();
closed = true;
}
}
};
}
Aggregations