33
33
import software .amazon .awssdk .core .exception .SdkClientException ;
34
34
import software .amazon .awssdk .core .exception .SdkException ;
35
35
import software .amazon .awssdk .core .internal .async .FileAsyncRequestBody ;
36
+ import software .amazon .awssdk .services .s3 .DelegatingS3AsyncClient ;
36
37
import software .amazon .awssdk .services .s3 .S3AsyncClient ;
37
38
import software .amazon .awssdk .services .s3 .internal .multipart .MultipartS3AsyncClient ;
38
39
import software .amazon .awssdk .services .s3 .internal .resource .S3AccessPointResource ;
@@ -110,11 +111,11 @@ class GenericS3TransferManager implements S3TransferManager {
110
111
}
111
112
112
113
@ SdkTestInternalApi
113
- GenericS3TransferManager (S3AsyncClient s3CrtAsyncClient ,
114
+ GenericS3TransferManager (S3AsyncClient s3AsyncClient ,
114
115
UploadDirectoryHelper uploadDirectoryHelper ,
115
116
TransferManagerConfiguration configuration ,
116
117
DownloadDirectoryHelper downloadDirectoryHelper ) {
117
- this .s3AsyncClient = s3CrtAsyncClient ;
118
+ this .s3AsyncClient = s3AsyncClient ;
118
119
this .isDefaultS3AsyncClient = false ;
119
120
this .transferConfiguration = configuration ;
120
121
this .uploadDirectoryHelper = uploadDirectoryHelper ;
@@ -138,13 +139,13 @@ public Upload upload(UploadRequest uploadRequest) {
138
139
try {
139
140
assertNotUnsupportedArn (uploadRequest .putObjectRequest ().bucket (), "upload" );
140
141
141
- CompletableFuture <PutObjectResponse > crtFuture =
142
+ CompletableFuture <PutObjectResponse > future =
142
143
s3AsyncClient .putObject (uploadRequest .putObjectRequest (), requestBody );
143
144
144
- // Forward upload cancellation to CRT future
145
- CompletableFutureUtils .forwardExceptionTo (returnFuture , crtFuture );
145
+ // Forward upload cancellation to future
146
+ CompletableFutureUtils .forwardExceptionTo (returnFuture , future );
146
147
147
- CompletableFutureUtils .forwardTransformedResultTo (crtFuture , returnFuture ,
148
+ CompletableFutureUtils .forwardTransformedResultTo (future , returnFuture ,
148
149
r -> CompletedUpload .builder ()
149
150
.response (r )
150
151
.build ());
@@ -298,13 +299,12 @@ public <ResultT> Download<ResultT> download(DownloadRequest<ResultT> downloadReq
298
299
try {
299
300
assertNotUnsupportedArn (downloadRequest .getObjectRequest ().bucket (), "download" );
300
301
301
- CompletableFuture <ResultT > crtFuture =
302
- s3AsyncClient .getObject (downloadRequest .getObjectRequest (), responseTransformer );
302
+ CompletableFuture <ResultT > future = doGetObject (downloadRequest .getObjectRequest (), responseTransformer );
303
303
304
- // Forward download cancellation to CRT future
305
- CompletableFutureUtils .forwardExceptionTo (returnFuture , crtFuture );
304
+ // Forward download cancellation to future
305
+ CompletableFutureUtils .forwardExceptionTo (returnFuture , future );
306
306
307
- CompletableFutureUtils .forwardTransformedResultTo (crtFuture , returnFuture ,
307
+ CompletableFutureUtils .forwardTransformedResultTo (future , returnFuture ,
308
308
r -> CompletedDownload .builder ()
309
309
.result (r )
310
310
.build ());
@@ -341,14 +341,12 @@ private TransferProgressUpdater doDownloadFile(
341
341
342
342
assertNotUnsupportedArn (downloadRequest .getObjectRequest ().bucket (), "download" );
343
343
344
- CompletableFuture <GetObjectResponse > crtFuture =
345
- s3AsyncClient .getObject (downloadRequest .getObjectRequest (),
346
- responseTransformer );
344
+ CompletableFuture <GetObjectResponse > future = doGetObject (downloadRequest .getObjectRequest (), responseTransformer );
347
345
348
- // Forward download cancellation to CRT future
349
- CompletableFutureUtils .forwardExceptionTo (returnFuture , crtFuture );
346
+ // Forward download cancellation to future
347
+ CompletableFutureUtils .forwardExceptionTo (returnFuture , future );
350
348
351
- CompletableFutureUtils .forwardTransformedResultTo (crtFuture , returnFuture ,
349
+ CompletableFutureUtils .forwardTransformedResultTo (future , returnFuture ,
352
350
res -> CompletedFileDownload .builder ()
353
351
.response (res )
354
352
.build ());
@@ -450,13 +448,13 @@ public Copy copy(CopyRequest copyRequest) {
450
448
assertNotUnsupportedArn (copyRequest .copyObjectRequest ().sourceBucket (), "copy sourceBucket" );
451
449
assertNotUnsupportedArn (copyRequest .copyObjectRequest ().destinationBucket (), "copy destinationBucket" );
452
450
453
- CompletableFuture <CopyObjectResponse > crtFuture =
451
+ CompletableFuture <CopyObjectResponse > future =
454
452
s3AsyncClient .copyObject (copyRequest .copyObjectRequest ());
455
453
456
- // Forward transfer cancellation to CRT future
457
- CompletableFutureUtils .forwardExceptionTo (returnFuture , crtFuture );
454
+ // Forward transfer cancellation to future
455
+ CompletableFutureUtils .forwardExceptionTo (returnFuture , future );
458
456
459
- CompletableFutureUtils .forwardTransformedResultTo (crtFuture , returnFuture ,
457
+ CompletableFutureUtils .forwardTransformedResultTo (future , returnFuture ,
460
458
r -> CompletedCopy .builder ()
461
459
.response (r )
462
460
.build ());
@@ -511,4 +509,14 @@ private static boolean isMrapArn(Arn arn) {
511
509
512
510
return !s3EndpointResource .region ().isPresent ();
513
511
}
512
+
513
+ // TODO remove once MultipartS3AsyncClient is complete
514
+ private <ResultT > CompletableFuture <ResultT > doGetObject (
515
+ GetObjectRequest getObjectRequest , AsyncResponseTransformer <GetObjectResponse , ResultT > asyncResponseTransformer ) {
516
+ S3AsyncClient clientToUse = s3AsyncClient ;
517
+ if (s3AsyncClient instanceof MultipartS3AsyncClient ) {
518
+ clientToUse = (S3AsyncClient ) ((DelegatingS3AsyncClient ) s3AsyncClient ).delegate ();
519
+ }
520
+ return clientToUse .getObject (getObjectRequest , asyncResponseTransformer );
521
+ }
514
522
}
0 commit comments