New Cometd client and server demo

On and off for the last couple weeks I have really been pushing myself to learn Java better. I constantly find myself unable to do things I want to with the languages I usually use (PHP specifically). As I am getting better I am coming to like it a lot more. As any reader of my blog (do I actually have ‘readers’?) know, I am really into Cometd, which the most major implementation of is written in Java. So in order to utilize Cometd Java and push my jQuery plugin further along, I figured it was high time I learn Java. I am really glad I am too. Just in time for my new Android phone too :)

CometdMap
Almost every demo of Cometd out there is a chat application, next up is stock tickers. There are one or two more I can think of off hand, none of which could be made into something more useful. I have had an application idea in the back of my head for quick some time. I really like doing work with maps, have been doing professional Google Maps work for a couple years, had to get the (second) dorkiest bike computer with GPS to map my rides. I have wanted for some time to do a real-time map. CometdMap is a proof of concept of that. It has no actually data input at the moment, infact, it is really basic right now. What it really does is show how simply you can build a Cometd Java app. I was really surprised at how easily I built this with my limited knowledge of Java.

What does it do
Right now, if you build and run the application you will get a simple Google Map. Clicking on the map will place a marker. Wowee! Pretty basic yeah, but what is going on here. Clicking the map publishes the point to the server, it is not until the server returns the data to the subscription callback that it is added. That is about all for the client side. On the server side two things are going on. First, when a new client joins they are added to a list, very similar to the way the Cometd Chat demo handles clients for private messages. Second, when points are published they are tracked on another list. So what can we do with these lists? Add a couple points and reload your browser. Since you are now a new client and there are points on the list, the old points are sent back to you. This will work for any new clients joining also. With multiple clients connected markers are updated to each in real-time.

Download & Build
Download
As I have mentioned before, the Java build environment and I do not exactly get along. In the tarball there is a script call build (partially ripped from the Harmony build script). If you have built the Cometd demo from Jetty with Maven this script should work just fine. Otherwise change the paths in the build (and server) scripts to point to the directories where your Jetty and Comet components are.

Enjoy, hopefully everyone is able to build with few problems. Check back in a couple weeks to see what I have in store next. Cheers, Morgan.

Leave a Comment