/*
* Create a S3ServiceMulti object with an event listener that responds to
* ListObjectsEvent notifications and populates a complete object listing.
*/
final S3ServiceMulti s3Multi = new S3ServiceMulti(restService, new S3ServiceEventAdaptor() {
public void s3ServiceEventPerformed(ListObjectsEvent event) {
if (ListObjectsEvent.EVENT_IN_PROGRESS == event.getEventCode()) {
Iterator chunkIter = event.getChunkList().iterator();
while (chunkIter.hasNext()) {
S3ObjectsChunk chunk = (S3ObjectsChunk) chunkIter.next();
System.out.println("Listed " + chunk.getObjects().length
+ " objects for sub-listing with prefix: '"
+ chunk.getPrefix() + "'");
allObjects.addAll(Arrays.asList(chunk.getObjects()));
}
} else if (ListObjectsEvent.EVENT_ERROR == event.getEventCode()) {
s3ServiceExceptions[0] = new S3ServiceException(
"Failed to list all objects in S3 bucket",
event.getErrorCause());
}
}
});
startTime = System.currentTimeMillis();
/*
* Perform a multi-threaded listing, where each common prefix string
* will be used as the prefix for a separate listing thread.
*/
(new Thread() {
public void run() {
s3Multi.listObjects(bucketName, commonPrefixes, null, 1000);
};
}).run();
long threadedElapsedTime = System.currentTimeMillis() - startTime;
totalElapsedTime += threadedElapsedTime;