JEP 110 HTTP 2 client API

Michael McMahon michael.x.mcmahon at oracle.com
Fri Apr 10 12:01:07 UTC 2015


On 10/04/15 12:32, Kasper Nielsen wrote:
>
>

Sorry, I've been away and am catching up on email

> On Fri, Apr 3, 2015 at 3:20 PM, Pavel Rappo <pavel.rappo at oracle.com 
> <mailto:pavel.rappo at oracle.com>> wrote:
>
>     Hi Kasper,
>
>     I assume your questions are all about WebSocket part, right? If
>     so, then
>
>     > 1)
>     > Would it possible to add a connect timeout parameter.
>     > builder.setConnectTimeout(long timeout, TimeUnit unit)
>     >
>     > For some reason it was left out of the javax.websocket API. And
>     working
>     > around it is a serious PITA.
>
>     What's the purpose of this timeout? Could you please explain it a
>     bit more?
>
> It is pretty normal to not want to block indefinitely on I/O methods.
> For example, in java.net.Socket you have both
> connect(SocketAddress endpoint)
> connect(SocketAddress endpoint, int timeout)
>
> the way I work around it in the javax.websocket api. Is spawning a 
> thread that can interrupt the blocking thread after XX seconds.
> But that is pretty annoying.
>

You can use the connectAsync() method which returns a CompletableFuture 
and then do a timed
get() on that object. That's the nice thing about CompletableFuture in 
that these concerns
are just delegated to that class rather than being replicated in each 
non-blocking API

>     > 4)
>     > I find the use of byte[] vs ByteBuffer a bit inconsistent.
>     > For example, HttpResponseBodyProcessor uses ByteBuffer while
>     > WebSocketMessage uses byte[]
>
>     I believe this is done solely for simplicity. HttpClient is a more
>     "general
>     purpose" kind of thing.
>
>  I'm not sure I understand what you mean here. ByteBuffer is for 
> general purpose things.
> While byte[] is for special things? I would say it was the other way 
> around.

Our view is that ByteBuffer is a complicated class (relatively speaking) 
and even in the
general HttpClient API, most developers won't use it. Only someone who 
wants to implement
a specific response processor would need to use it. So, I think 
programmers will in both cases
use familiar types like String or byte[] or application specific classes 
in the Http client api.

Michael



More information about the core-libs-dev mailing list