users@glassfish.java.net

Re: Grizzly Connector - Servlet NIO Channel

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Tue, 11 Nov 2008 10:27:17 -0500

Salut,

{cross posting to users_at_grizzly}

Burak Oguz wrote:
> Hi all,
>
> I started to use Glassfish v3 recently. Before that I was using Tomcat
> Comet for some rapid data transfer, http tunneling issues. But Tomcat
> started to bottleneck. I wonder if there is such a way that I can handle
> "chunked" requests in Grizzly Comet in a Servlet over Glassfish. In
> grizzly comet as far as I can see it only does async push. I want to do
> async pull too. I read all Jean-Francois's tutos but I could not see any
> such example.

You are right. I've never had a chance to blog about it. Mainly, you
need to register for async read or write event like this:

CometContext ctx = CometEngine.getEngine().register("foo");

CometHandler myAsyncHandler = new MyAsyncCometHandler();
ctx.registerAsyncRead(myAsyncHandler);

As soon as async read bytes are available, they will be pushed via the
CometHandler.onEvent() with the CometEvent.READ event. Then you can read
by using the CometReader[1]:

if (event.getType() == CometEvent.READ){

     CometReader asyncReader = (CometReader)event.getEvent();
     asyncReader.read(...); //async read

}

I will try to add a sample soon inside the Comet workspace and
eventually blog about it.

Thanks

-- Jeanfrancois

[1]
https://grizzly.dev.java.net/nonav/apidocs/com/sun/grizzly/comet/CometReader.html

>
> Thanks in advance..