-
Notifications
You must be signed in to change notification settings - Fork 916
[TM DownloadDirectory Part1] Create POJO classes for download directory #2993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zoewangg
merged 3 commits into
zoewang/tm-downloadDirectory
from
zoewang/tm-downloadDirectoryPart1
Jan 27, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
156 changes: 156 additions & 0 deletions
156
...-manager/src/main/java/software/amazon/awssdk/transfer/s3/CompletedDirectoryDownload.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.transfer.s3; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Objects; | ||
import software.amazon.awssdk.annotations.SdkPreviewApi; | ||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
import software.amazon.awssdk.utils.ToString; | ||
import software.amazon.awssdk.utils.Validate; | ||
import software.amazon.awssdk.utils.builder.CopyableBuilder; | ||
import software.amazon.awssdk.utils.builder.ToCopyableBuilder; | ||
|
||
/** | ||
* Represents a completed download directory transfer to Amazon S3. It can be used to track | ||
* failed single file downloads. | ||
* | ||
* @see S3TransferManager#downloadDirectory(DownloadDirectoryRequest) | ||
*/ | ||
@SdkPublicApi | ||
@SdkPreviewApi | ||
public final class CompletedDirectoryDownload implements CompletedDirectoryTransfer, | ||
ToCopyableBuilder<CompletedDirectoryDownload.Builder, | ||
CompletedDirectoryDownload> { | ||
|
||
private final Collection<FailedFileDownload> failedTransfers; | ||
|
||
private CompletedDirectoryDownload(DefaultBuilder builder) { | ||
this.failedTransfers = Collections.unmodifiableCollection( | ||
new ArrayList<>(Validate.paramNotNull(builder.failedTransfers, "failedTransfers"))); | ||
} | ||
|
||
@Override | ||
public Collection<FailedFileDownload> failedTransfers() { | ||
return failedTransfers; | ||
} | ||
|
||
/** | ||
* Creates a default builder for {@link CompletedDirectoryDownload}. | ||
*/ | ||
public static Builder builder() { | ||
return new DefaultBuilder(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
CompletedDirectoryDownload that = (CompletedDirectoryDownload) o; | ||
|
||
return Objects.equals(failedTransfers, that.failedTransfers); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return failedTransfers != null ? failedTransfers.hashCode() : 0; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ToString.builder("CompletedDirectoryDownload") | ||
.add("failedTransfers", failedTransfers) | ||
.build(); | ||
} | ||
|
||
public static Class<? extends Builder> serializableBuilderClass() { | ||
return DefaultBuilder.class; | ||
} | ||
|
||
@Override | ||
public Builder toBuilder() { | ||
return new DefaultBuilder(this); | ||
} | ||
|
||
public interface Builder extends CopyableBuilder<CompletedDirectoryDownload.Builder, | ||
CompletedDirectoryDownload> { | ||
|
||
/** | ||
* Sets a collection of {@link FailedFileDownload}s | ||
* | ||
* @param failedTransfers failed download | ||
* @return This builder for method chaining. | ||
*/ | ||
Builder failedTransfers(Collection<FailedFileDownload> failedTransfers); | ||
|
||
/** | ||
* Add a {@link FailedFileDownload} | ||
* | ||
* @param failedTransfer failed download | ||
* @return This builder for method chaining. | ||
*/ | ||
Builder addFailedTransfer(FailedFileDownload failedTransfer); | ||
|
||
/** | ||
* Builds a {@link CompletedDirectoryDownload} based on the properties supplied to this builder | ||
* @return An initialized {@link CompletedDirectoryDownload} | ||
*/ | ||
CompletedDirectoryDownload build(); | ||
} | ||
|
||
private static final class DefaultBuilder implements Builder { | ||
private Collection<FailedFileDownload> failedTransfers = new ArrayList<>(); | ||
|
||
private DefaultBuilder() { | ||
} | ||
|
||
private DefaultBuilder(CompletedDirectoryDownload completedDirectoryDownload) { | ||
this.failedTransfers = new ArrayList<>(completedDirectoryDownload.failedTransfers); | ||
} | ||
|
||
@Override | ||
public Builder failedTransfers(Collection<FailedFileDownload> failedTransfers) { | ||
this.failedTransfers = new ArrayList<>(failedTransfers); | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder addFailedTransfer(FailedFileDownload failedTransfer) { | ||
failedTransfers.add(failedTransfer); | ||
return this; | ||
} | ||
|
||
public Collection<FailedFileDownload> getFailedTransfers() { | ||
return Collections.unmodifiableCollection(failedTransfers); | ||
} | ||
|
||
public void setFailedTransfers(Collection<FailedFileDownload> failedTransfers) { | ||
failedTransfers(failedTransfers); | ||
} | ||
|
||
@Override | ||
public CompletedDirectoryDownload build() { | ||
return new CompletedDirectoryDownload(this); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...-transfer-manager/src/main/java/software/amazon/awssdk/transfer/s3/DirectoryDownload.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.transfer.s3; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import software.amazon.awssdk.annotations.SdkPreviewApi; | ||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
|
||
/** | ||
* A download transfer of a directory of objects from S3 | ||
*/ | ||
@SdkPublicApi | ||
@SdkPreviewApi | ||
public interface DirectoryDownload extends DirectoryTransfer { | ||
@Override | ||
CompletableFuture<CompletedDirectoryDownload> completionFuture(); | ||
zoewangg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion, non-blocking: IMO, it's more polite to return the most concrete abstract type, e.g. List instead of Collection here so that people can have constant-time random access to its members. I know that's controversial "because order doesn't matter" here, but I think it's more likely that a user would want to use failedTransfers().get(n) to get the n'th failure than a user would get confused about the order being "inconsistent" just because we returned a List instead of a Collection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, @Bennett-Lynch and I had the same debate before! We can definitely open the discussion. The main reason I think Collection is better because it gives us flexibility to change the implementation (although it's very unlikely we will change it).
I think customers can still do
failedFileUploads.stream().collect(Collectors.toList())
if they want to iterate the list by index.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you've already convinced Bennett that this is the correct decision, then I don't want to make you have to debate this again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was pro-
List
as well, and still somewhat am, but was mostly persuaded to useCollection
since it allows us to use our ConcurrentLinkedQueue directly. I agree that ordering doesn't strictly matter here, but it still seems like a nice-to-have.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@millems Everyone's opinion matters! Let's vote on it. :)
@Bennett-Lynch We are still copying it to an ArrayList technically.