while (continueWritingChangedDocuments.get()) {
// Poll for a changed document, but wait at most 1 second ...
NodeKey key = changedDocumentQueue.poll(1L, TimeUnit.SECONDS);
if (key != null) {
// Write out the document to the changed area ...
SchematicEntry entry = documentStore.get(key.toString());
writeToChangedArea(entry);
}
}
} catch (InterruptedException e) {
Thread.interrupted();
}
// Continue to drain whatever is still in the queue, but never block ...
while (!changedDocumentQueue.isEmpty()) {
// Poll for a changed document, but at most only
NodeKey key = changedDocumentQueue.poll();
if (key != null) {
// Write out the document to the changed area ...
SchematicEntry entry = documentStore.get(key.toString());
writeToChangedArea(entry);
}
}
changesLatch.countDown();
}
});
// PHASE 0:
// Register a listener with the repository to start start recording the documents as they exist when the
// changes are made while this execution is proceeding. It's possible not all of these will be needed,
// but by doing this we make sure that we include the latest changes in the backup (at least those
// changes made before the observer is disconnected)...
repositoryCache.changeBus().register(observer);
try {
// PHASE 1:
// Perform the backup of the repository cache content ...
int counter = 0;
Sequence<String> sequence = InfinispanUtil.getAllKeys(documentStore.localCache());
while (true) {
String key = sequence.next();
if (key == null) break;
SchematicEntry entry = documentStore.get(key);
if (entry != null) {
writeToContentArea(entry);
++counter;
}
}
LOGGER.debug("Wrote {0} documents to {1}", counter, backupDirectory.getAbsolutePath());
// PHASE 2:
// Write out the repository metadata document (which may have not changed) ...
NodeKey metadataKey = repositoryCache.getRepositoryMetadataDocumentKey();
SchematicEntry entry = documentStore.get(metadataKey.toString());
writeToContentArea(entry);
} catch (Exception e) {
I18n msg = JcrI18n.problemObtainingDocumentsToBackup;
this.problems.addError(msg, repositoryName(), backupLocation(), e.getMessage());
} finally {