Hi Jakub,
Thanks for your reply.
Indeed JerseyClient can create a listener that gets passed the ClientRequest.
The difficulty that I am having is that I don't see straightforward way to match up that ClientRequest with the one that I have (indirectly) created.
E.g., if in two different threads I call something like:
Future<ClientResponse> response = webClient.asyncResource("
http://www.cnn.com").get(ClientResponse.class);
I expect two listeners will be created by the request filter, but since the calling threads do not have a handle on the ClientRequests being instantiated, I don't know which listener corresponds to which call.
The api does have allow for a .get(TypeListener<ClientResponse>) call that provides a callback for the completion of the request, but it does not provide for bytes sent, like the Listeners do.
One way that I have thought of solving the problem was to create a single queue of requests, and then I can match listeners with requests because I am enforcing a call order. This seems to me like a workaround though.
I had hoped that TypeListener included bytesSent and bytesReceived, but these methods are not there.
Is there a more direct way to get some kind of progress listener on a specific web request?
Thanks,
Marco
________________________________
From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
To: users_at_jersey.java.net
Sent: Friday, June 17, 2011 9:49 AM
Subject: [Jersey] Re: Monitoring progress on an asynchronous request
Hi Marco,
On 06/15/2011 09:27 PM, marco.ocana_at_balboasystems.com wrote:
> Hi,
>
> How would I go about monitoring the progress of an asynchronous request
> using the Jersey client?
> I am aware of the ContainerListener mechanism using a
> ConnectionListenerFilter, but I could not find a straightforward way to
> associate a listener to a specific request.
The above listener should work the same way for async/non-async
requests. You are getting a concrete ClientRequest instance passed
to your OnStartConnectionListener.onStart method:
client.addFilter(new ConnectionListenerFilter(new
OnStartConnectionListener() {
public ContainerListener onStart(ClientRequest clientRequest) {
return createYourContainerListenerHereAwareOfThe(clientRequest);
}
});
~Jakub
> I also found the FutureListener with the onComplete callback, but it
> does not provide information on the bytes sent/received like the
> ContainerListener does.
>
> I am currently on Jersey Client 1.5.
>
> Thanks
>
> Marco
>