-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Issue #929 implement a utility class to save large downloads to a file #12292
base: jetty-12.0.x
Are you sure you want to change the base?
Conversation
Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>
Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>
Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>
Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>
Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>
Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>
The CI build failed due to javadoc issues.
You can see your CI builds here -> https://jenkins.webtide.net/blue/organizations/jenkins/jetty.project/activity?branch=PR-12292 |
Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>
Hello, |
All tests passed on my laptop with JDK17. Should I also run tests with JDK22? |
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.
@arsenalzp good effort!
Please follow my review, and your implementation should become much simpler and with less code.
Thanks!
jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/Request.java
Show resolved
Hide resolved
jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpRequest.java
Show resolved
Hide resolved
jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/PathResponseListener.java
Show resolved
Hide resolved
jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/PathResponseListener.java
Show resolved
Hide resolved
jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/PathResponseListener.java
Show resolved
Hide resolved
* CompletableFuture>Path> completable = PathResponseListener.write(request, Path.of("/tmp/file.bin")); | ||
* </pre> | ||
*/ | ||
public class PathResponseListener implements CompleteListener, Response.ContentListener |
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.
Make this class implement Response.Listener
instead, like BufferingResponseListener
, so users have all events available if they want to.
This class should extend CompletableFuture<Path>
, so users can get its result once the file is written (or failed).
if (response.getStatus() != HttpStatus.OK_200) | ||
{ | ||
throw new HttpResponseException(String.format("HTTP status code of this response %d", response.getStatus()), response); | ||
} |
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.
Move this check to onHeaders()
so it is done only once.
See examples in BufferingResponseListener
.
jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/PathResponseListener.java
Show resolved
Hide resolved
|
||
public static CompletableFuture<Path> write(Request request, Path path) | ||
{ | ||
return CompletableFuture.supplyAsync(() -> |
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.
This method should be implemented in terms of PathResponseListener
, not by rewriting the same logic again.
public Response get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException, ExecutionException | ||
{ | ||
boolean expired = !responseLatch.await(timeout, unit); | ||
if (expired && this.response == null) | ||
throw new TimeoutException(); | ||
try (AutoLock ignored = lock.lock()) | ||
{ | ||
// If the request failed there is no response. | ||
if (response == null) | ||
throw new ExecutionException(failure); | ||
return response; | ||
} | ||
} | ||
|
||
public Response get() throws InterruptedException, ExecutionException | ||
{ | ||
this.completable.get(); | ||
return this.response; | ||
} |
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.
Remove these methods, as this class should be a CompletableFuture
.
Our CI environment will do it, but sure if you want to try, give it a go. |
Hello,
This PR is trying to implement feature described in the issue #929.
Fixes: #929