简体   繁体   English

AWS Java SDK-将ProgressListener与TransferManager结合使用

[英]AWS Java SDK - using ProgressListener with TransferManager

I am looking at usage example provided in AWS SDK docs for TransferManager , in particular for the following code: 我正在查看AWS SDK文档中为TransferManager提供的使用示例,尤其是以下代码:

TransferManager tx = new TransferManager(
               credentialProviderChain.getCredentials());
Upload myUpload = tx.upload(myBucket, myFile.getName(), myFile);
 // Transfers also allow you to set a <code>ProgressListener</code> to receive
// asynchronous notifications about your transfer's progress.
myUpload.addProgressListener(myProgressListener);

and I am wondering whether we don't have here case of a race condition. 我想知道我们是否没有比赛条件的情况。 AFAIU TransferManager works asynchronously, it may start the uploading file straight away after the Upload object creation, even before we add the listener, so if we use the snippet as provided in the docs, it seems to be possible that we won't receive all notifications. AFAIU TransferManager异步工作,它可能在创建Upload对象后立即开始上传文件,甚至在添加侦听器之前也是如此,因此,如果我们使用文档中提供的代码段,则似乎我们可能收不到全部通知。 I've looked briefly into the addProgressListener and I don't see there that past events would be replayed on attaching a new listener. 我已经简要地查看了addProgressListener ,但没有看到在附加新的侦听器时会重播过去的事件。 Am I wrong? 我错了吗? Am I missing something? 我想念什么吗?

If you need to get ALL events, I imagine this can be achieved using a different upload method that takes in a ProgressListener as a parameter. 如果您需要获取ALL事件,我想可以使用将ProgressListener作为参数的其他upload方法来实现。 Of course, using this method will require encapsulating your bucketname, key, and file into an instance of PutObjectRequest . 当然,使用此方法将需要将您的存储桶名称,键和文件封装到PutObjectRequest的实例中。

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

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