ps = conn.prepareStatement(sql);
ps.setLong(1, ctx.getTimeService().wallClockTime());
rs = ps.executeQuery();
rs.setFetchSize(tableManipulation.getFetchSize());
ExecutorCompletionService<Void> ecs = new ExecutorCompletionService<Void>(executor);
final TaskContextImpl taskContext = new TaskContextImpl();
int taskCount = 0;
//we can do better here: ATM we load the entries in the caller's thread and process them in parallel
// we can do the loading (expensive operation) in parallel as well.
while (rs.next()) {
InputStream binaryStream = rs.getBinaryStream(1);
final Bucket bucket = unmarshallBucket(binaryStream);
ecs.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
for (MarshalledEntry me : bucket.getStoredEntries(filter, ctx.getTimeService()).values()) {
if (!taskContext.isStopped()) {
task.processEntry(me, taskContext);
}
}
return null;
}