use of org.commonjava.maven.galley.internal.xfer.BatchRetriever in project galley by Commonjava.
the class TransferManagerImpl method doBatch.
private <T extends TransferBatch> T doBatch(final Set<Resource> resources, final T batch, final boolean suppressFailures, final EventMetadata eventMetadata) throws TransferException {
logger.info("Attempting to batch-retrieve {} resources:\n {}", resources.size(), new JoinString("\n ", resources));
final Set<BatchRetriever> retrievers = new HashSet<BatchRetriever>(resources.size());
for (final Resource resource : resources) {
retrievers.add(new BatchRetriever(this, resource, suppressFailures, eventMetadata));
}
final Map<ConcreteResource, TransferException> errors = new HashMap<ConcreteResource, TransferException>();
final Map<ConcreteResource, Transfer> transfers = new HashMap<ConcreteResource, Transfer>();
do {
for (final BatchRetriever retriever : retrievers) {
batchExecutor.submit(retriever);
}
int count = retrievers.size();
for (int i = 0; i < count; i++) {
try {
Future<BatchRetriever> pending = batchExecutor.take();
BatchRetriever retriever = pending.get();
final ConcreteResource resource = retriever.getLastTry();
final TransferException error = retriever.getError();
if (error != null) {
logger.warn("ERROR: {}...{}", error, resource, error.getMessage());
retrievers.remove(retriever);
if (!(error instanceof TransferLocationException)) {
errors.put(resource, error);
}
continue;
}
final Transfer transfer = retriever.getTransfer();
if (transfer != null && transfer.exists()) {
transfers.put(resource, transfer);
retrievers.remove(retriever);
logger.debug("Completed: {}", resource);
continue;
}
if (!retriever.hasMoreTries()) {
logger.debug("Not completed, but out of tries: {}", resource);
retrievers.remove(retriever);
}
} catch (final InterruptedException e) {
logger.error(String.format("Failed to wait for batch retrieval attempts to complete: %s", e.getMessage()), e);
break;
} catch (ExecutionException e) {
logger.error(String.format("Failed to retrieve next completed retrieval: %s", e.getMessage()), e);
}
}
} while (!retrievers.isEmpty());
batch.setErrors(errors);
batch.setTransfers(transfers);
return batch;
}
Aggregations