public class UrisToWriterListener extends Object implements QueryBatchListener
Facilitates writing uris to a file when necessary because setting merge timestamp and withConsistentSnapshot is not an option, but you need to run DeleteListener or ApplyTransformListener.
Example writing uris to disk then running a delete:
FileWriter writer = new FileWriter("uriCache.txt");
QueryBatcher getUris = dataMovementManager.newQueryBatcher(query)
.withBatchSize(5000)
.onUrisReady( new UrisToWriterListener(writer) )
.onQueryFailure(exception -> exception.printStackTrace());
JobTicket getUrisTicket = dataMovementManager.startJob(getUris);
getUris.awaitCompletion();
dataMovementManager.stopJob(getUrisTicket);
writer.flush();
writer.close();
// now we have the uris, let's step through them
BufferedReader reader = new BufferedReader(new FileReader("uriCache.txt"));
QueryBatcher performDelete = dataMovementManager.newQueryBatcher(reader.lines().iterator())
.onUrisReady(new DeleteListener())
.onQueryFailure(exception -> exception.printStackTrace());
JobTicket ticket = dataMovementManager.startJob(performDelete);
performDelete.awaitCompletion();
dataMovementManager.stopJob(ticket);
| Modifier and Type | Class and Description |
|---|---|
static interface |
UrisToWriterListener.OutputListener |
| Constructor and Description |
|---|
UrisToWriterListener(Writer writer) |
| Modifier and Type | Method and Description |
|---|---|
UrisToWriterListener |
onBatchFailure(BatchFailureListener<Batch<String>> listener)
When a batch fails or a callback throws an Exception, run this listener code.
|
UrisToWriterListener |
onGenerateOutput(UrisToWriterListener.OutputListener listener) |
void |
processEvent(QueryBatch batch)
The method called by QueryBatcher or WriteBatcher to run your custom code on this batch.
|
UrisToWriterListener |
withRecordPrefix(String prefix) |
UrisToWriterListener |
withRecordSuffix(String suffix) |
public UrisToWriterListener(Writer writer)
public void processEvent(QueryBatch batch)
QueryBatchListenerThe method called by QueryBatcher or WriteBatcher to run your custom code on this batch. You usually implement this as a lambda expression.
For example, see the lambda expression passed to onUrisReady:
QueryBatcher qhb = dataMovementManager.newQueryBatcher(query)
.withBatchSize(1000)
.withThreadCount(20)
.onUrisReady(batch -> {
for ( String uri : batch.getItems() ) {
if ( uri.endsWith(".txt") ) {
batch.getClient().newDocumentManager().delete(uri);
}
}
})
.onQueryFailure(queryBatchException -> queryBatchException.printStackTrace());
JobTicket ticket = dataMovementManager.startJob(qhb);
qhb.awaitCompletion();
dataMovementManager.stopJob(ticket);
processEvent in interface BatchListener<QueryBatch>processEvent in interface QueryBatchListenerbatch - the batch of uris and some metadata about the current status of the jobpublic UrisToWriterListener withRecordSuffix(String suffix)
public UrisToWriterListener withRecordPrefix(String prefix)
public UrisToWriterListener onGenerateOutput(UrisToWriterListener.OutputListener listener)
public UrisToWriterListener onBatchFailure(BatchFailureListener<Batch<String>> listener)
When a batch fails or a callback throws an Exception, run this listener code. Multiple listeners can be registered with this method.
listener - the code to run when a failure occursCopyright © 2013-2017 MarkLogic Corporation.