mirror of https://github.com/apache/jclouds.git
Cancel Futures in clearContainer
This prevents Futures from hanging around on exceptional code paths like interrupts and timeouts.
This commit is contained in:
parent
ddbb41130d
commit
76a5538229
|
@ -91,12 +91,14 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
|
||||||
if (options.isRecursive())
|
if (options.isRecursive())
|
||||||
message = message + " recursively";
|
message = message + " recursively";
|
||||||
Map<StorageMetadata, Exception> exceptions = Maps.newHashMap();
|
Map<StorageMetadata, Exception> exceptions = Maps.newHashMap();
|
||||||
PageSet<? extends StorageMetadata> listing;
|
|
||||||
int maxErrors = 3; // TODO parameterize
|
int maxErrors = 3; // TODO parameterize
|
||||||
for (int numErrors = 0; numErrors < maxErrors; ) {
|
for (int numErrors = 0; numErrors < maxErrors; ) {
|
||||||
// fetch partial directory listing
|
// fetch partial directory listing
|
||||||
|
PageSet<? extends StorageMetadata> listing;
|
||||||
|
Future<PageSet<? extends StorageMetadata>> listFuture =
|
||||||
|
connection.list(containerName, options);
|
||||||
try {
|
try {
|
||||||
listing = connection.list(containerName, options).get();
|
listing = listFuture.get();
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
break;
|
break;
|
||||||
|
@ -107,6 +109,8 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
|
||||||
}
|
}
|
||||||
retryHandler.imposeBackoffExponentialDelay(numErrors, message);
|
retryHandler.imposeBackoffExponentialDelay(numErrors, message);
|
||||||
continue;
|
continue;
|
||||||
|
} finally {
|
||||||
|
listFuture.cancel(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// recurse on subdirectories
|
// recurse on subdirectories
|
||||||
|
@ -162,7 +166,12 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
|
||||||
}
|
}
|
||||||
retryHandler.imposeBackoffExponentialDelay(numErrors, message);
|
retryHandler.imposeBackoffExponentialDelay(numErrors, message);
|
||||||
continue;
|
continue;
|
||||||
|
} finally {
|
||||||
|
for (Future<?> future : responses.values()) {
|
||||||
|
future.cancel(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!exceptions.isEmpty()) {
|
if (!exceptions.isEmpty()) {
|
||||||
++numErrors;
|
++numErrors;
|
||||||
retryHandler.imposeBackoffExponentialDelay(numErrors, message);
|
retryHandler.imposeBackoffExponentialDelay(numErrors, message);
|
||||||
|
|
Loading…
Reference in New Issue