Aklakan commented on code in PR #3464:
URL: https://github.com/apache/jena/pull/3464#discussion_r2394816671
##########
jena-arq/src/main/java/org/apache/jena/sparql/exec/http/QueryExecHTTP.java:
##########
@@ -624,22 +649,69 @@ private static void logQuery(String queryString,
HttpRequest request) {}
/**
* Cancel query evaluation
*/
- public void cancel() {
- closed = true;
- }
-
@Override
public void abort() {
- try {
- close();
- } catch (Exception ex) {
- Log.warn(this, "Error during abort", ex);
+ // Setting abort to true causes the next read from
+ // retainedConnectionView (if already created) to
+ // fail with a QueryCancelledException.
+ isAborted = true;
+ if (cancelFutureOnAbort) {
+ cancelFuture(future);
+ }
+ }
+
+ private InputStream registerInputStream(HttpResponse<InputStream>
httpResponse) {
+ InputStream in = HttpLib.getInputStream(httpResponse);
+ registerInputStream(in);
+ return in;
+ }
+
+ /**
+ * Set the given input stream as the 'retainedConnection' and create a
corresponding
+ * asynchronously abortable 'retainedConnectionView'. The latter is
returned.
+ * If execution was already aborted then a {@link QueryCancelledException}
is raised.
+ */
+ private InputStream registerInputStream(InputStream in) {
+ synchronized (abortLock) {
+ this.retainedConnection = in;
+ // Note: Used ProxyInputStream because the ctor of
CloseShieldInputStream is deprecated.
+ this.retainedConnectionView = new ProxyInputStream(in) {
+ @Override
+ protected void beforeRead(int n) throws IOException {
+ checkNotAborted();
+ super.beforeRead(n);
+ }
Review Comment:
Just as a note: This is still not the nicest solution because it pulls the
rug from under the parsers' feet - but the original solution also just closed
the physical HTTP input stream.
Now `abort()` just closes the ProxyInputStream (instant action) - whereas
only `close()` closes the physical stream (may take time to consume remaining
data).
If really needed, further revisions could go into future PRs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]