Nirvana J2ME : Nirvana Events
A Nirvana Event (nObject) 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 an event tag, simple byte array data, or more complex data structures such as an Nirvana Event Dictionary (nEventProperties).
Constructing an Event
In this J2ME code snippet, we construct our Nirvana Event object (nObject), as well as a Nirvana Event Dictionary object for our Nirvana Event:
String tag="someTag"; nObject evt=nObject.createConsumeEvent(myProps,tag.getBytes());
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 J2ME 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 three keys: messageID, value and open.
public void go(nObject evt){
if (nObject.getEventProperties(evt) != null){
nEventProperties props = nObject.getEventProperties(evt);
String messageID = props.getString("messageID");
J2MEFloat value = props.getFloat("value");
J2MEFloat open = props.getFloat("open");
//....
}
}
