Example usage for com.amazonaws.services.s3.model DeleteObjectRequest withGeneralProgressListener

List of usage examples for com.amazonaws.services.s3.model DeleteObjectRequest withGeneralProgressListener

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model DeleteObjectRequest withGeneralProgressListener.

Prototype

public <T extends AmazonWebServiceRequest> T withGeneralProgressListener(ProgressListener progressListener) 

Source Link

Document

Sets the optional progress listener for receiving updates about the progress of the request, and returns a reference to this object so that method calls can be chained together.

Usage

From source file:modules.storage.AmazonS3Storage.java

License:Open Source License

@Override
public F.Promise<Void> delete(String key, String name) {
    Promise<Void> promise = Futures.promise();

    AmazonS3 amazonS3 = new AmazonS3Client(credentials);
    DeleteObjectRequest request = new DeleteObjectRequest(bucketName, key);
    request.withGeneralProgressListener(progressEvent -> {
        if (progressEvent.getEventType().isTransferEvent()) {
            if (progressEvent.getEventType().equals(ProgressEventType.TRANSFER_COMPLETED_EVENT)) {
                promise.success(null);/*  w  ww.ja v a  2s  .  c  om*/
            } else if (progressEvent.getEventType().equals(ProgressEventType.TRANSFER_FAILED_EVENT)) {
                logger.error(progressEvent.toString());
                promise.failure(new Exception(progressEvent.toString()));
            }
        }
    });

    try {
        amazonS3.deleteObject(request);
    } catch (AmazonServiceException ase) {
        logAmazonServiceException(ase);
    } catch (AmazonClientException ace) {
        logAmazonClientException(ace);
    }

    return F.Promise.wrap(promise.future());
}