users@grizzly.java.net

Question on how to design statless filters

From: Johan Maasing <johan_at_zoom.nu>
Date: Wed, 21 May 2014 14:28:30 +0200

I'm going through the tutorials (for 2.3.12) making a simple HTTP client. I
followed this https://grizzly.java.net/httpframework.html#/Samples which
works fine.

However I get a bit stuck on how to modify the sample to make the filter
stateless.
My use case is that I will have many threads making the same type of
HTTP-requests to the same end-point. So I guess that I should set up the
filter chain and start the transport once as a singleton. Then I use
transport.connect and transport.write in each "client" thread.
Will there ever be the case that my filter will be called several time for
the same response - I'm thinking about how/where to accumulate in memory
the entire response body if that is the case?

How do I return the response to the calling thread? In the sample the
filter gets a future from the caller in the constructor to return the
result to the caller. But this won't work if I set up the chain once and it
is shared between threads.

Any pointers are appreciated.

Cheers,
JM