users@jersey.java.net

[Jersey] Re: Async client and Response.readEntity

From: Robert DiFalco <robert.difalco_at_gmail.com>
Date: Wed, 31 Dec 2014 12:06:43 -0800

Did you ever get an answer to this?

On Mon, Oct 6, 2014 at 7:45 AM, Mikael Ståldal <
mikael.staldal_at_appearnetworks.com> wrote:

> Consider using Jersey client in async mode with an
> InvocationCallback<Response>, and then use readEntity() on the Response.
> Order is a custom domain object for which we have a MessageBodyReader
> available.
>
> Invocation invocation = client.target(someURL).request().buildGet();
> invocation.submit(new InvocationCallback<Response> {
> public void completed(Response response) {
> int status = response.getStatus();
> if (status == 200) {
> Order order = response.readEntity(Order.class); // blocking ?
> process(order);
> } else {
> error();
> }
> }
> public void failed(Throwable throwable) {
> error();
> }
> });
>
> Is the response.readEntity() call blocking? Is it I/O bound if the
> response is large? Or is the whole response read from network before the
> completed() callback is invoked?
>
> Will the asynchronicity be improved if I do InvocationCallback<Order>
> instead? What if I want to get other information from the Response?
>
> --
> Mikael Ståldal
> Chief Software Architect
> *Appear*
> Phone: +46 8 545 91 572
> Email: mikael.staldal_at_appearnetworks.com
>