dev@grizzly.java.net

Re: Grizzly 2.0.0 http serve implementation question

From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Date: Mon, 09 Nov 2009 15:20:06 +0100

Hi Ming Qin,

for HTTP module we recommend to use higher level API: GrizzlyWebServer
and GrizzlyAdapter, this API is more simple to use with HTTP.
Grizzly 2.0 supports it similar way as 1.9.x [1].

WBR,
Alexey.

[1] http://weblogs.java.net/blog/jfarcand/archive/2008/07/extending_the_g.html


On Nov 9, 2009, at 9:19 , ming qin wrote:

> Hi Oleksiy Stashok:
>
> Gizzly 2.0.0 http server implementation is clear and straight
> forward, thanks for bringing in main concepts ( Connection,
> StreamReader, StreamWriter ). But, I could not figure out how do you
> resolve the below problem mentioned in Jean-Frrancois Arcand’s blog
> - http://weblogs.java.net/blog/jfarcand/archive/2005/06/grizzly_an_http.html
>
> Here is a quote to remind: “The problem with NIO non blocking and
> HTTP is your never know when all the bytes have been read (this is
> how non blocking works). With blocking, you just wait on the
> socket's input stream. With non-blocking, you cannot wait on the
> socket input stream because it will return as soon as you have read
> all the available data. But that doesn't means you have received all
> the request bytes. Technically, you have no guarantee than all the
> bytes has been read from the socket channel:
>
> count = socketChannel.read(byteBuffer));
>
> This may not read the entire stream bytes, and may require several
> extra read operations. Unfortunately, this situation occurs
> frequently when reading HTTP requests. I've explored several
> strategies (which I will details in my next blog) and kept the most
> performant one, which consist of a state machine used to parse the
> content-length header and predict the end of the stream. “
>
> For Grizzly prior to Gizzly 2.0.0, Grizzly has some state machine
> implementation such as StateMachineAlgorith.java,
> ConetnetLenghtAlgorith.java,
>
>
>
> In Oleksiy Stashok’s blog , you mentioned : “
>
> In order to use StreamReader in non-blocking mode - we may want to
> check if StreamReader has enough data to be read:
> streamReader.availableDataSize(); So once StreamReader has enough
> data - we can safely read it without blocking.
>
> It is also possible to ask StreamReader to notify us once it will
> have enough data, or provide any other custom Condition, which
> StreamReader should check each time new data come - and notify us,
> once this Condition is met.”
>
>
> In Girzzly 2.0.0 http server implementation, how is the mechanism
> of notification and condition working out with http request and reply?
>
>
>
>
>
> Ming Qin
> Cell Phone 858-353-2839
>