I think I have been confusing comet and cometd this whole time. I assumed
cometd was the server side of comet, controlled by java, whereas the client
side was controlled by javascript libraries.
Thanks!
Jeanfrancois Arcand-2 wrote:
>
> Salut,
>
> falcon wrote:
>> 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)
>>
>
> This is interesting :-) If you want to use Java instead of JavaScript
> (hence cometd), you need to use the Grizzly Comet Framework (not the
> cometd/bayeux implementation). With Grizzly Comet, you can do exactly
> what you described above. Take a look at:
>
> http://weblogs.java.net/blog/jfarcand/archive/2006/10/writting_a_come.html
>
> Mainly, You can push data using:
>
> CometContext.notify()[1]
>
> You can broadcast to all or to a limited subset using:
>
> CometContext.getNotificationHandler().notify(..)[2]
>
> You can decide which page gets updated:
>
> CometHandler.onEvent(..)[3]
>
>
>> 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
>
>
> CometContext.addCometListener() [4]
>
>
>>
>> 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).
>
> Thanks. Hopefully the above helps. Let us know if you need more info.
>
> A+
>
> -- Jeanfrancois
>
> [1]https://grizzly.dev.java.net/nonav/apidocs/com/sun/grizzly/comet/CometContext.html#notify(E)
> [2]https://grizzly.dev.java.net/nonav/apidocs/com/sun/grizzly/comet/NotificationHandler.html
> [3]https://grizzly.dev.java.net/nonav/apidocs/com/sun/grizzly/comet/CometHandler.html#onEvent(com.sun.grizzly.comet.CometEvent)
> [4]https://grizzly.dev.java.net/nonav/apidocs/com/sun/grizzly/comet/CometContext.html#addCometHandler(com.sun.grizzly.comet.CometHandler)
>
>
>
>
>>
>>
>> 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
>>>
>>>
>>>
>>
>
> ---------------------------------------------------------------------
> 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-tp20511957p20609759.html
Sent from the Grizzly - Users mailing list archive at Nabble.com.