use of org.apache.sling.event.impl.support.BatchResourceRemover in project sling by apache.
the class JobQueueImpl method removeAll.
/**
* @see org.apache.sling.event.jobs.Queue#removeAll()
*/
@Override
public synchronized void removeAll() {
final Set<String> topics = this.cache.getTopics();
logger.debug("Removing all jobs for queue {} : {}", queueName, topics);
if (!topics.isEmpty()) {
final ResourceResolver resolver = this.services.configuration.createResourceResolver();
try {
final Resource baseResource = resolver.getResource(this.services.configuration.getLocalJobsPath());
// sanity check - should never be null
if (baseResource != null) {
final BatchResourceRemover brr = new BatchResourceRemover();
for (final String t : topics) {
final Resource topicResource = baseResource.getChild(t.replace('/', '.'));
if (topicResource != null) {
JobTopicTraverser.traverse(logger, topicResource, new JobTopicTraverser.JobCallback() {
@Override
public boolean handle(final JobImpl job) {
final Resource jobResource = topicResource.getResourceResolver().getResource(job.getResourcePath());
// sanity check
if (jobResource != null) {
try {
brr.delete(jobResource);
} catch (final PersistenceException ignore) {
logger.error("Unable to remove job " + job, ignore);
topicResource.getResourceResolver().revert();
topicResource.getResourceResolver().refresh();
}
}
return true;
}
});
}
}
try {
resolver.commit();
} catch (final PersistenceException ignore) {
logger.error("Unable to remove jobs", ignore);
}
}
} finally {
resolver.close();
}
}
}
Aggregations