Skip to content
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

documentation for CompletionCallback implementation change since Jersey 3.1.0 #4895

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions docs/src/main/docbook/async.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,57 @@ public class AsyncResource {
}
}</programlisting>
</example>
Since Jersey 3.1.0 and JAX-RS 3.1 there are significant changes in the &lit.jaxrs.container.CompletionCallback;
<literal>onComplete(...)</literal> method. The <literal>(Throwable throwable)</literal> parameter is deprecated
and the <literal>onComplete()</literal> method should be called without parameters.
So, the proper code for the example above since Jersey 3.1.0 would be:
<example>
<title>CompletionCallback updated (JAX-RS 3.1) example</title>
<programlisting language="java" linenumbering="numbered">@Path("/resource")
public class AsyncResource {
private static int numberOfSuccessResponses = 0;
private static int numberOfFailures = 0;
private static Throwable lastException = null;

@GET
public void asyncGetWithTimeout(@Suspended final AsyncResponse asyncResponse) {
asyncResponse.register(new CompletionCallback() {
@Override
public void onComplete() (Throwable throwable) {
}
@Override
public void onComplete() {
if (throwable == null) {
// no throwable - the processing ended successfully
// (response already written to the client)
numberOfSuccessResponses++;
} else {
numberOfFailures++;
lastException = throwable;
}
}
});

new Thread(new Runnable() {
@Override
public void run() {
String result = veryExpensiveOperation();
asyncResponse.resume(result);
}

private String veryExpensiveOperation() {
// ... very expensive operation
}
}).start();
}
}</programlisting>
</example>

but for backwards compatibility the method <literal>void onComplete()</literal> is declared as
<literal>default</literal> and for any current code no re-work is required. However it's required to keep
in mind that in feature releases the method <literal>void onComplete(Throwable throwable)</literal> will
be replaced by the <literal>void onComplete()</literal> method without parameters.

A completion callback is registered using <literal>register(...)</literal> method
on the &lit.jaxrs.container.AsyncResponse; instance. A registered completion callback is bound only
to the response(s) to which it has been registered. In the example the &lit.jaxrs.container.CompletionCallback;
Expand Down