-
Notifications
You must be signed in to change notification settings - Fork 532
8361286: Allow enabling of background loading for images loaded from an InputStream #1875
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
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back jhendrikx! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
- Fixed generics (mix up of two ImageLoader types) - Removed unused code for handling headers, methods, request parameters - Use long for progress as streams max exceed 2 GB - Improved documentation of Image regarding background loading
7efebfd
to
1452b5c
Compare
Webrevs
|
Reviewers: @kevinrushforth @jayathirthrao /reviewers 2 |
@kevinrushforth |
This will need a CSR. The newly proposed constructors should have an /csr needed |
@kevinrushforth has indicated that a compatibility and specification (CSR) request is needed for this pull request. @hjohn please create a CSR request for issue JDK-8361286 with the correct fix version. This pull request cannot be integrated until the CSR request is approved. |
Do we still use |
I don't know about the |
|
I wonder if this should be explained in the @NamedArg javadoc. |
It probably should, I never use FXML, but I should have guessed it was for that purpose :) |
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.
Looks very good!
Noticed it does not close the input stream with a synchronous constructor (it does with the async one).
- some minor comments and suggestions.
modules/javafx.graphics/src/main/java/com/sun/javafx/runtime/async/AbstractRemoteResource.java
Show resolved
Hide resolved
modules/javafx.graphics/src/main/java/com/sun/javafx/tk/quantum/QuantumToolkit.java
Show resolved
Hide resolved
modules/javafx.graphics/src/main/java/javafx/scene/image/Image.java
Outdated
Show resolved
Hide resolved
modules/javafx.graphics/src/main/java/javafx/scene/image/Image.java
Outdated
Show resolved
Hide resolved
@@ -154,6 +155,35 @@ public void loadImageAsyncProgressTest() { | |||
assertTrue(p3 == p4); | |||
} | |||
|
|||
@Test |
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.
Do you think it would make sense to add a test that actually loads a valid image?
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 don't think that can be done with the stub toolkit This test is specifically stubbing/mocking everything out to verify that Image
works correctly. However, there are many areas where (real) images are loaded already, and all the code involved (excluding the new parts in Image
) was already there in one way or another as the URL variants that allowed background loading is also just an InputStream
with some extra steps to determine their size (for progress).
modules/javafx.graphics/src/test/java/test/javafx/scene/image/ImageTest.java
Outdated
Show resolved
Hide resolved
FYI Created https://bugs.openjdk.org/browse/JDK-8365864 but if someone wants to do it, I can send it their way. |
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.
Change looks to me apart from some questions.
Will also run tests on our CI system and check.
return processStream(stream); | ||
} | ||
finally { | ||
stream.close(); |
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.
Do we have to continue closing the stream when background loading is happening with URL?
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 see that the resource is getting closed.
|
||
protected AbstractRemoteResource(String url, String method, String outboundContent, AsyncOperationListener<T> listener) { |
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 see that outboundContent calls are no where used. Is this the reason we are cleaning up this code?
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.
Yeah, I generally remove code that I see is unused, if it otherwise would have needed to be adjusted.
@hjohn in case you missed my earlier comment: Noticed it does not close the input stream with a synchronous constructor (it does with the async one). you can try it with the monkey tester from this branch https://github.com/andy-goryachev-oracle/MonkeyTest/tree/image.from.stream or simply
|
A good question would be what the behavior should be. For the URL variants, since the Image class is creating the stream in both cases, it makes sense that it closes that stream. For However, when consuming the stream asynchronously, it is very hard for users to know when to safely close the stream as you basically handed ownership of the stream to another thread (you can't use the stream for anything while background loading is in progress...) The only way to know when the other thread is done with the stream is to look at the progress property. So, I think there are a few options:
A prime motivation for allowing input streams for background loading was that the URL API is limited (you can't do authentication, use POST, or provide a body). In those cases you're forced to |
re: closing stream I wonder if we should close the stream in both sync and async variants (and document that). I would say there should be no reason not to close - suggesting that if the application wants not to close it's surely a bad choice for the application. For example, one can think of a situation where multiple images are stored within the same stream, but there should be a reliable way for the application to specify the size of each image (and then the app can provide a derived InputStream which EOFs when the end of an image is reached). Another alternative is to add another boolean What do you think? |
It's unusual to close the stream when you're not the owner (although some API's do that, they are often obscure and not used that much). Changing this behavior for the sync variant would be a breaking change, so I'm not sure we want to even go there. Adding another If we go the |
I like the |
We need to leave the existing synchronous constructors alone, other than to document that they do not close the input stream (which is what we do in the As for the new constructors, I think the options are:
|
I think at least the convenience constructor |
No, that would be an incompatible change. |
You are right, please disregard the comment. I think we should clarify the behavior in each constructor that takes A boolean |
A new parameter to toggle whether the stream will be closed should have at least a moderately strong use case to justify its existence. I can't think of any. If you turn over a stream to an asynchronous process, you effectively relinquish ownership of that stream, as you don't know when (if ever) it will be processed. But even then, you can very easily achieve the non-closing behavior without new JavaFX API, just by using existing stream APIs: var streamThatWillNotCloseUnderlyingStream = new FilterInputStream(myStream) {
@Override
public void close() {
// don't call super.close(), so underlying stream won't be closed
}
} |
If user is passing stream its better to keep the decision of closing the stream with user for synchronous loading. Asynchronous URL loading : Current changes takes care of closing the stream and follows already present behaviour. Its better to update the documentation about it. Giving an option to user about how to close the stream in case of asynchronous loading can be taken up as future task, if needed. CI testing is green with current code update. |
When you have a
Since the supplier must create a new stream each time (as it can't know how often it will be called), it makes sense that the caller of the supplier is also the one to close it, whether or not that is sync or async. |
Thanks for all the input. I think there are now two ways to proceed:
I get the impression the consensus leans towards option 1. I don't see a direct compelling need for the |
I prefer option 1. |
I agree with Kevin: option 1 is clearer. |
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.
Latest change looks good to me.
This update causes a failure in one of our closed white-box tests. It will be easy for us to fix it, but it will mean that down the road, when this is ready to go in, we will need to coordinate the timing of the integration with you.
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.
thank you for making the requested changes @hjohn !
looks good.
Support background loading of raw input streams
long
for progress as streams may exceed 2 GBProgress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1875/head:pull/1875
$ git checkout pull/1875
Update a local copy of the PR:
$ git checkout pull/1875
$ git pull https://git.openjdk.org/jfx.git pull/1875/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 1875
View PR using the GUI difftool:
$ git pr show -t 1875
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1875.diff
Using Webrev
Link to Webrev Comment