BatchListener<QueryBatch>
,
QueryBatchListener
,
java.lang.AutoCloseable
public class ExtractRowsViaTemplateListener extends java.lang.Object implements QueryBatchListener, java.lang.AutoCloseable
StructuredQueryDefinition query = new StructuredQueryBuilder().directory(1, "/employees/");
QueryBatcher qb = moveMgr.newQueryBatcher(query)
.onUrisReady(new ExtractRowsViaTemplateListener().withTemplate(templateUri).onTypedRowReady(row -> {
System.out.println("row:" + row);
}));
moveMgr.startJob(qb);
qb.awaitCompletion();
moveMgr.stopJob(qb);
If any of the consumers registered with this listener implements
the AutoCloseable interface and has a resource that needs to be
closed, we have to make sure that this listener also override the
close() method and make sure we call the close method of all the
consumers registered with it. This close method of the listener
will be called internally by the QueryBatcher when stopJob is
called on the batcher. It is the responsibility of the listeners to
call the close method if any of its consumers have the close method
implemented to close any resources used. Constructor | Description |
---|---|
ExtractRowsViaTemplateListener() |
Modifier and Type | Method | Description |
---|---|---|
void |
close() |
|
void |
initializeListener(QueryBatcher queryBatcher) |
This default method should be implemented by
custom listeners that should be retried in case of failover.
|
ExtractRowsViaTemplateListener |
onFailure(BatchFailureListener<QueryBatch> listener) |
When a batch fails or a callback throws an
Exception, run this listener code.
|
ExtractRowsViaTemplateListener |
onTypedRowReady(java.util.function.Consumer<TypedRow> listener) |
Register one or more listeners which needs to be
applied to each row got by applying the templates to the batch of
documents.
|
void |
processEvent(QueryBatch batch) |
This is the method QueryBatcher calls for
ExtractRowsViaTemplateListener to do its thing.
|
ExtractRowsViaTemplateListener |
withTemplate(java.lang.String templateUri) |
Register one or more template uris which needs
to be applied to each batch to extract the rows
|
public ExtractRowsViaTemplateListener withTemplate(java.lang.String templateUri)
templateUri
- the uri of the template to be
applied to each batch.public ExtractRowsViaTemplateListener onTypedRowReady(java.util.function.Consumer<TypedRow> listener)
listener
- the listener which needs to be applied
to each rowpublic ExtractRowsViaTemplateListener onFailure(BatchFailureListener<QueryBatch> listener)
listener
- the code to run when a failure
occurspublic void initializeListener(QueryBatcher queryBatcher)
QueryBatchListener
initializeListener
in interface QueryBatchListener
queryBatcher
- the QueryBatcher which will call
this Listenerpublic void processEvent(QueryBatch batch)
processEvent
in interface BatchListener<QueryBatch>
processEvent
in interface QueryBatchListener
batch
- the batch of uris and some metadata about
the current status of the jobpublic void close() throws java.lang.Exception
close
in
interface java.lang.AutoCloseable
java.lang.Exception
Copyright © 2022 MarkLogic Corporation