Nirvana JavaScript : Nirvana Events

A Nirvana Event (nConsumeEvent) is the object that is published to a Nirvana channel, queue or P2P service. It is stored by the server and then passed to consumers as and when required.

Events can contain simple byte array data, or more complex data structures such as an Nirvana Event Dictionary (nEventProperties).

Constructing an Event

In this JavaScript code snippet, we construct our Nirvana Event object (nConsumeEvent), as well as a Nirvana Event Dictionary object (nEventProperties) for our Nirvana Event:

var event = new nConsumeEvent();
var dictionary = new nEventProperties();
dictionary.put("exampleKey", "Hello World");
event.setDictionary(dictionary);

Handling a Received Event

When a client subscribes to a channel and specifies a callback function to handle received events, the callback function will be invoked with the event as its parameter whenever an event is received.

In this JavaScript code snippet, we demonstrate a simple implementation of such a callback function. In this example, we assume that the event contains an Event Dictionary with two keys: name and price.

function eventHandlerCallbackFunc(event) {
	var dictionary = event.getDictionary();
	var name = dictionary.get("name");
	var price = dictionary.get("price");
	alert("Name = " + name + " and Price = " + price);
}
Share this page with others:
Tell Your Tweets Facebook It! Add to Delicious Reddit! Digg It! Stumble Upon Add to Your Faves Mixx it
Follow Us:
Keep up with my-Channels on Twitter Become a fan on Facebook LinkedIn Profile Recent Highlights RSS Feed