简体   繁体   English

使用AWS TransferManager上载时找不到堆栈跟踪

[英]Unable to find stacktrace when uploading with AWS TransferManager

I am using the TransferManager to upload some files on my server to S3 asynchronously. 我正在使用TransferManager将服务器上的某些文件异步上传到S3。 The problem is that it is failing for an unknown reason and I am not seeing any exceptions in the logs. 问题是它由于未知原因而失败,并且我在日志中没有看到任何异常。

I see a comment in the documentation for seeing the exception when the transfer fails. 我在文档中看到一条注释,用于在传输失败时看到异常。 The problem is that this requires blocking the thread. 问题在于这需要阻塞线程。

// Or you can block the current thread and wait for your transfer to
// to complete. If the transfer fails, this method will throw an
// AmazonClientException or AmazonServiceException detailing the reason.
myUpload.waitForCompletion();

I've tried using the ProgressListener, but that seems to only notify me when the transfer fails. 我曾尝试使用ProgressListener,但这似乎只会在传输失败时通知我。 I don't see any exceptions thrown. 我没有看到任何异常。

Is there a way to view these exceptions without blocking? 有没有办法查看这些异常而不会阻塞?

Once the ProgressListener notifies you that the upload is complete (or has failed), you can call waitForCompletion to get the result without blocking. 一旦ProgressListener通知您上传完成(或失败),您可以调用waitForCompletion以获取结果而不会阻塞。

public class FailureListener extends SyncProgressListener {

    public static void bind(Upload upload) {
        upload.addProgressListener(new FailureListener(upload));
    }

    private final Upload upload;

    public FailureListener(Upload upload) {
        this.upload = upload;
    }

    @Override
    public void progressChanged(ProgressEvent progressEvent) {
        if (progressEvent.getEventType() == ProgressEventType.TRANSFER_FAILED_EVENT) {
            AmazonClientException e = getException();
            e.printStackTrace();
        }
    }

    private AmazonClientException getException() {
        try {
            // Won't actually "wait" since the transfer has already failed.
            return upload.waitForException();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new Error("WTF?", e);
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM