public class ProgressListener extends java.lang.Object implements QueryBatchListener
Reports on progress as batches are processed by sending an instance of the nested ProgressUpdate interface to instances of java.util.function.Consumer.
As an example, one approach would be to log the progress as a string:
QueryBatcher queryBatcher = moveMgr.newQueryBatcher(query)
.withConsistentSnapshot()
.onUrisReady(
new ProgressListener()
.onProgressUpdate(progressUpdate -> {
System.out.println(progressUpdate.getProgressAsString());
})
);
JobTicket ticket = moveMgr.startJob(queryBatcher);
queryBatcher.awaitCompletion();
moveMgr.stopJob(ticket);
The method withTotalResults
can be used to inform the listener of the total number
of expected results; this would likely have been determined by first using a QueryManager with a page length of zero
to determine the number of results for a query. Given the total results, each ProgressUpdate object will be aware of
how close to complete the QueryBatcher is.Modifier and Type | Class and Description |
---|---|
static interface |
ProgressListener.ProgressUpdate
Captures data of interest for a progress update.
|
static class |
ProgressListener.SimpleProgressUpdate
Simple implementation of ProgressUpdate; only real thing of interest in here is how it generates the progress
as a string for display purposes.
|
Constructor and Description |
---|
ProgressListener() |
ProgressListener(java.util.function.Consumer<ProgressListener.ProgressUpdate>... consumers)
Use this constructor for when the total number of results isn't known ahead of time.
|
ProgressListener(long totalResults,
java.util.function.Consumer<ProgressListener.ProgressUpdate>... consumers)
Use this constructor for when the total number of results is known ahead of time.
|
Modifier and Type | Method and Description |
---|---|
void |
initializeListener(QueryBatcher queryBatcher)
Initializes the start time so that each ProgressUpdate knows how long it occurred after the job was started.
|
protected void |
invokeConsumer(java.util.function.Consumer<ProgressListener.ProgressUpdate> consumer,
ProgressListener.ProgressUpdate progressUpdate)
Protected so that a subclass can override how a consumer is invoked, particularly how an exception is handled.
|
protected ProgressListener.ProgressUpdate |
newProgressUpdate(QueryBatch batch,
long startTime,
long totalForThisUpdate,
double timeSoFar)
A subclass can override this to provide a different implementation of ProgressUpdate.
|
ProgressListener |
onProgressUpdate(java.util.function.Consumer<ProgressListener.ProgressUpdate> consumer) |
void |
processEvent(QueryBatch batch)
Batches arrive in random order, so a ProgressUpdate is created and sent to each Consumer only if the
value of "getJobResultsSoFar" on the QueryBatch exceeds the number of results seen so far.
|
ProgressListener |
withTotalResults(long totalResults) |
public ProgressListener()
public ProgressListener(java.util.function.Consumer<ProgressListener.ProgressUpdate>... consumers)
consumers
- public ProgressListener(long totalResults, java.util.function.Consumer<ProgressListener.ProgressUpdate>... consumers)
consumers
- totalResults
- public ProgressListener withTotalResults(long totalResults)
public ProgressListener onProgressUpdate(java.util.function.Consumer<ProgressListener.ProgressUpdate> consumer)
public void initializeListener(QueryBatcher queryBatcher)
initializeListener
in interface QueryBatchListener
queryBatcher
- public void processEvent(QueryBatch batch)
For example, if there are 2 batches, and batch 2 is processed first by this listener followed by batch 1, a ProgressUpdate is only created when batch 2 is processed.
processEvent
in interface BatchListener<QueryBatch>
processEvent
in interface QueryBatchListener
batch
- protected ProgressListener.ProgressUpdate newProgressUpdate(QueryBatch batch, long startTime, long totalForThisUpdate, double timeSoFar)
batch
- startTime
- totalForThisUpdate
- timeSoFar
- protected void invokeConsumer(java.util.function.Consumer<ProgressListener.ProgressUpdate> consumer, ProgressListener.ProgressUpdate progressUpdate)
consumer
- progressUpdate
- Copyright © 2013-2018 MarkLogic Corporation.