Additional Libraries

Here you can find a set of complementary libraries

Json

Download

The Json library allows easy and fast object serializations<./p>

API

The Json library has a single static method:

public static String json(Object o)

This method returns the JSON representation of the object (o).

Comet

Download

Comet (aka ajax push) allows the server to "push" messages to the client. The comet library handle all the communication tasks and lets you send events with minimum effort.

API

The Comet class has two static methods:

void send(HttpSession s, String ch, Object msg)

This method sends a message (msg) to a specific client (s) on a specific channel (ch)

void reset(HttpSession s, String ch)

This method resets all the messages sent to the client.

Settings

To use the comet library you need to do the following:

Client Side

The server can't really push messages to the client, instead the client has to listen to the server's messages. To do that you need to send a request with the following format

/comet/<channel>?mid=<mid>
			

Where channel is the channel the clients listen to and mid is the message number the client wants. A typical client's code, using the jj library, should look like that:

var mid = 0;
function listen(m) {
	if (m && m.mid == mid) {
		mid++;
		var msg = m.msg;
		//do something with msg
	}
	jj("/comet/news", {
		mid : mid
	}, listen);
}	
listen();