use of co.cask.cdap.api.dataset.lib.AbstractCloseableIterator in project cdap by caskdata.
the class LevelDBMetadataTable method scanTopics.
private CloseableIterator<TopicMetadata> scanTopics(@Nullable byte[] startKey, @Nullable byte[] stopKey) throws IOException {
final CloseableIterator<Map.Entry<byte[], byte[]>> iterator = new DBScanIterator(levelDB, startKey, stopKey);
return new AbstractCloseableIterator<TopicMetadata>() {
private boolean closed = false;
@Override
protected TopicMetadata computeNext() {
if (closed || (!iterator.hasNext())) {
return endOfData();
}
Map.Entry<byte[], byte[]> entry = iterator.next();
TopicId topicId = MessagingUtils.toTopicId(entry.getKey());
Map<String, String> properties = GSON.fromJson(Bytes.toString(entry.getValue()), MAP_TYPE);
return new TopicMetadata(topicId, properties);
}
@Override
public void close() {
try {
iterator.close();
} finally {
endOfData();
closed = true;
}
}
};
}
Aggregations