public class ExportListener extends java.lang.Object implements QueryBatchListener
Reads document contents (and optionally metadata) for each batch, then sends
each document to any listeners registered with onDocumentReady
for further processing or writing to any target supported
by Java. Supports reading partial documents via transforms. Supports
exporting all documents at a consistent point-in-time using
withConsistentSnapshot.
QueryBatcher exportBatcher = moveMgr.newQueryBatcher(query)
.withConsistentSnapshot()
.onUrisReady(
new ExportListener()
.withConsistentSnapshot()
.onDocumentReady(doc -> {
logger.debug("Contents=[{}]", doc.getContentAs(String.class));
})
)
.onQueryFailure(exception -> exception.printStackTrace());
JobTicket ticket = moveMgr.startJob(exportBatcher);
exportBatcher.awaitCompletion();
moveMgr.stopJob(ticket);
By default only document contents are retrieved. If you would also like
metadata, make sure to call withMetadataCategory
to configure which categories of metadata you desire.
As with all the provided listeners, this listener will not meet the needs of all applications but the source code for it should serve as helpful sample code so you can write your own custom listeners.
Constructor and Description |
---|
ExportListener() |
Modifier and Type | Method and Description |
---|---|
protected java.util.List<BatchFailureListener<QueryBatch>> |
getBatchFailureListeners() |
protected DocumentPage |
getDocs(QueryBatch batch) |
protected java.util.List<BatchFailureListener<Batch<java.lang.String>>> |
getFailureListeners()
Deprecated.
|
void |
initializeListener(QueryBatcher queryBatcher)
This implementation of initializeListener adds this instance of
ExportListener to the two RetryListener's in this QueryBatcher so they
will retry any batches that fail during the read request.
|
ExportListener |
onBatchFailure(BatchFailureListener<Batch<java.lang.String>> listener)
Deprecated.
|
ExportListener |
onDocumentReady(java.util.function.Consumer<DocumentRecord> listener)
Adds a listener to process each retrieved document, which is the way users
of ExportListener can provide custom code to export documents.
|
ExportListener |
onFailure(BatchFailureListener<QueryBatch> listener)
When a batch fails or a callback throws an Exception, run this listener
code.
|
void |
processEvent(QueryBatch batch)
This is the method QueryBatcher calls for ExportListener to do its
thing.
|
ExportListener |
withConsistentSnapshot()
Specifies that documents should be retrieved as they were when this QueryBatcher job started.
|
ExportListener |
withMetadataCategory(DocumentManager.Metadata category)
Adds a metadata category to retrieve and make available from
DocumentRecord.getMetadata to listeners
registered with onDocumentReady. |
ExportListener |
withNonDocumentFormat(Format nonDocumentFormat)
Sets the format for metadata available from
DocumentRecord.getMetadata to listeners registered with
onDocumentReady (assuming withMetadataCategory has been called to request specific metdata). |
ExportListener |
withTransform(ServerTransform transform)
Sets the server tranform to modify the document contents.
|
protected DocumentPage getDocs(QueryBatch batch)
public void initializeListener(QueryBatcher queryBatcher)
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 ExportListener withConsistentSnapshot()
query
, not with
an Iterator
.QueryBatcher.withConsistentSnapshot()
public ExportListener withMetadataCategory(DocumentManager.Metadata category)
DocumentRecord.getMetadata
to listeners
registered with onDocumentReady. To specify the format for the metdata,
call withNonDocumentFormat
.category
- the metadata category to retrieveDocumentManager.setMetadataCategories
public ExportListener withNonDocumentFormat(Format nonDocumentFormat)
DocumentRecord.getMetadata
to listeners registered with
onDocumentReady (assuming withMetadataCategory
has been called to request specific metdata). If
setNonDocumentFormat is not called, the server default format will be
used.nonDocumentFormat
- the format in which retrieve the metadataDocumentManager.setNonDocumentFormat
public ExportListener withTransform(ServerTransform transform)
transform
- the name of the transform already installed in the REST serverpublic ExportListener onDocumentReady(java.util.function.Consumer<DocumentRecord> listener)
QueryBatcher.onUrisReady
instead. You do not need to call close() on
each DocumentRecord because the ExportListener will call close for you on
the entire DocumentPage.listener
- the code which will process each documentConsumer
,
DocumentRecord
@Deprecated public ExportListener onBatchFailure(BatchFailureListener<Batch<java.lang.String>> listener)
onFailure(BatchFailureListener)
listener
- the code to run when a failure occurspublic ExportListener onFailure(BatchFailureListener<QueryBatch> listener)
listener
- the code to run when a failure occurs@Deprecated protected java.util.List<BatchFailureListener<Batch<java.lang.String>>> getFailureListeners()
protected java.util.List<BatchFailureListener<QueryBatch>> getBatchFailureListeners()
Copyright © 2013-2020 MarkLogic Corporation.