users@grizzly.java.net

Re: GrizzlyWebServer to working comet/bayeux web client

From: falcon <shahbazc_at_gmail.com>
Date: Sun, 16 Nov 2008 22:18:17 -0800 (PST)

I think part of the reason I am struggling is that the programming model of
comet is different from that of core, non-web, java.

Many comet (or bayeux) examples seem to work through channels. If, in
Javascript, I subscribe to a channel as
"comet.subscribe("/somechannel",callbackfunction);" somewhere in Java, I
expect to be able to do the following:

comet.sendMessage("/somechannel","message:"+rnd.next());//java code
(along with the ability to control who the message is sent to...broadcast to
everyone on the target web page, or only to a specific web page viewer)

Correpondingly, in Java, I expect to be able to listen to messages in a
manner similar to the following:
comet.addListener("/somechannel",new cometMessageHandler());//java code

DWR works somewhat like this, but I prefer to use grizzly's implementation
which lets me get at very low level comet if I need to (althouhg right now
that is proving to be a bit of a problem).


Jeanfrancois Arcand-2 wrote:
>
> Salut,
>
> falcon wrote:
>> Hi,
>> I need to embed a web/comet server inside another server. Whenever the
>> main
>> server is updated, I need to send out these updates to client's browsers
>> using comet. Since I need to embed the server, I am using some examples
>> from Jean-Francois's blog in the following manner:
>>
>> public static void main(String[] args) throws IOException {
>> GrizzlyWebServer ws = new GrizzlyWebServer(8080,"./web/");
>> ws.addGrizzlyAdapter(new GrizzlyAdapter(){
>>
>> @Override
>> public void service(GrizzlyRequest arg0, GrizzlyResponse arg1) {
>> //for some reason, if I don't add this dummy adapter, I get a 404
>> error
>> //with this, I get the index.html correctly...but this is not the
>> issue
>>
>> }});
>> ws.addAsyncFilter(new CometAsyncFilter());
>> ws.addGrizzlyAdapter(new CometdAdapter());
>>
>> ws.start();
>> }
>>
>> The problem is, I don't really understand where my cometd logic goes.
>
> As soon as you add the CometdAdapter, you have installed bayeux support.
> Hence you are ready to start the Grizzly WS and listen to "bayeux"
> request.
>
>>
>> Do I need to create a servlet (as in this document:
>> http://docs.sun.com/app/docs/doc/820-4496/ghgxk?a=view)? That would mean
>> that I have to add a servlet adapter. I have no problem adding a servlet
>> adapter, but then what is the purpose of CometdAdapter?
>
> No, with Bayeux/Cometd, you don't need to add anything. If you want to
> see an example, take a look at:
>
>> https://grizzly.dev.java.net/nonav/xref/com/sun/grizzly/standalone/cometd/Cometd.html#139
>
> It not exactly what you are looking at, but it gives you an idea of how
> internally, when using:
>
> java -jar grizzly-cometd-webserver.jar -p 8080
>
>
>>
>> I actually expected that I would pass in some sort of handler to the
>> CometdAdapter.
>>
>> Can someone please help me out of this confusion?
>
> Does the above help? Let me know if not and I will try to write a code
> snippet that can help you. What do you want to do with Cometd? Are you
> planning to do update using Java or using Javascript?
>
> Thanks
>
> -- Jeanfrancois
>
>
>>
>> Thanks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>
>
>

-- 
View this message in context: http://www.nabble.com/GrizzlyWebServer-to-working-comet-bayeux-web-client-tp20511957p20534337.html
Sent from the Grizzly - Users mailing list archive at Nabble.com.