Universal Messaging JavaScript API
Pure JavaScript API For JavaScript/HTML5 Clients
The Universal Messaging JavaScript API is intended to be simple to use, while being sufficiently comprehensive to accommodate a range of application requirements and infrastructures. Though the full API is extensive, its ease of use for typical use cases should be clear from the following simple example, which in only a few lines of code, sets up a Session, subscribes to a Channel, and receives, processes and publishes Events:
var session = Nirvana.createSession();
var channel = session.getChannel("/demo/channel");
function demoHandler(event) {
if (event.getDictionary().get("demoMessage") == "ping") {
newEvent = Nirvana.createEvent();
newEvent.getDictionary().putString("demoMessage", "pong");
channel.publish(newEvent);
}
}
session.start();
channel.on(Nirvana.Observe.DATA, demoHandler);
channel.subscribe();
Universal Messaging streams events to web clients asynchronously, without the requirement for any additional technology components or plugins on client browsers. The API will automatically detect client capabilities and make use of the optimum underlying transport driver in each case. See Nirvana.Driver for more details of the many available Web Socket and Comet drivers.
Universal Messaging JavaScript API | Pure JavaScript API For JavaScript/HTML5 Clients |
Version & Support | JavaScript API Version BuildNumberHere. |
Copyright & License | Copyright 1999-2011 © My-Channels Copyright © 2012–2015 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors. |
Nirvana | Nirvana is the API namespace which provides a number of static methods and properties for creating Universal Messaging Sessions, Events, and EventDictionaries along with definitions of constants used throughout. |
Constants | |
Observe | Nirvana.Observe defines constants which identify observable events that, when fired, notify interested listeners (see the on() and removeListener() methods in the Nirvana, Session, Channel, Queue and TransactionalQueue objects). |
Driver | Nirvana.Driver defines the names of all available transport drivers that may be used by a Session. |
VERSION_NUMBER | Nirvana.VERSION_NUMBER is an integer constant representing the API version number. |
BUILD_NUMBER | Nirvana.BUILD_NUMBER is an integer constant representing the API build number. |
BUILD_DATE | Nirvana.BUILD_DATE defines the API build date. |
CHANNEL_RESOURCE | Nirvana.CHANNEL_RESOURCE is an integer constant representing a Channel’s type. |
QUEUE_RESOURCE | Nirvana.QUEUE_RESOURCE is an integer constant representing a Queue’s type. |
TRANSACTIONAL_QUEUE_RESOURCE | Nirvana.TRANSACTIONAL_QUEUE_RESOURCE is an integer constant representing a TransactionalQueue’s type. |
Functions | |
createSession() | Creates and initializes (but does not start) a session object for communication with a Universal Messaging Realm Server. |
createEvent() | Factory method to create a new, empty Universal Messaging Event (typically for subsequent publishing to a resource such as a Channel or Queue). |
createDictionary() | Factory method to create a new, empty EventDictionary (typically for subsequent addition to an existing EventDictionary using EventDictionary.putDictionary()). |
on() | Registers a single event listener on the Nirvana object for observable events of the specified type (see Nirvana.Observe for a list of applicable observables). |
removeListener() | Removes a specific listener for observable events of the specified type (see Nirvana.Observe for a list of applicable observables). |
Session | A Session object is returned by a call to Nirvana.createSession(). |
Functions | |
start() | Starts the Session. |
stop() | Stops the Session. |
subscribe() | Batch-subscribes to multiple Channel, Queue and/or TransactionalQueue resources with a single call to the server. |
getChannel() | Returns the Channel object for the supplied channel name. |
getQueue() | Returns the Queue or TransactionalQueue object for the supplied queue name. |
on() | Registers a single event listener on the Session for observable events of the specified type (see Nirvana.Observe for a list of applicable observables). |
removeListener() | Removes a specific listener for observable events of the specified type (see Nirvana.Observe for a list of applicable observables). |
getUsername() | Returns the username used in this Session. |
getCurrentDriver() | Returns the name of the Session’s current transport driver. |
getCurrentRealm() | Returns the RNAME (in protocol://host:port format) of the realm server to which the Session is currently connected. |
getSessionID() | Returns the Session’s current session ID. |
getDataStreamID() | Returns the Session’s current DataStream ID. |
getConfig() | Returns the configuration object for the Session. |
getStatus() | Returns the Session’s current status, which describes whether it is, for example, not yet started, connected, disconnected, or stopped. |
isDataStreamEnabled() | Returns true or false, depending on whether the Session was configured to be DataStream-enabled (via setting of the dataStreamEnabled key in the configuration object passed as an optional parameter to Nirvana.createSession(). |
Channel | A Channel object is returned by any call to Session.getChannel(). |
Functions | |
subscribe() | Subscribes to the Channel, and begins receiving events. |
unsubscribe() | Unsubscribes from the Channel, and stops receiving events. |
isSubscribed() | Returns true or false, depending on whether a subscription exists for the Channel. |
publish() | Publishes a Universal Messaging Event to the Channel. |
createTransaction() | Factory method to create a new Transaction for use on the Channel. |
getStartEID() | Returns the Event ID (the “EID”) from which an existing subscription to the Channel started, or from which a subsequent subscription to the Channel will start. |
setStartEID() | Sets the Event ID (the “EID”) from which a subsequent subscription to the Channel shall start. |
getCurrentEID() | Returns the Event ID (the “EID”) which an existing subscription to the Channel is at. |
getFilter() | Returns the SQL-style filter applied to an existing or subsequent subscription to the Channel. |
setFilter() | Sets the SQL-style filter to be applied to a subsequent subscription to the Channel. |
getName() | Returns the Channel’s fully qualified name (e.g. |
getResourceType() | Returns the constant Nirvana.CHANNEL_RESOURCE, which identifies this resource as a Channel. |
on() | Registers a single event listener on the Channel for observable events of the specified type (see Nirvana.Observe for applicable observables). |
removeListener() | Removes a specific listener for observable events of the specified type (see Nirvana.Observe for applicable observables). |
Queue | A Queue object is returned by any call to Session.getQueue() when the optional second Queue, isTransactionalReader, is either not supplied or is false. |
Functions | |
subscribe() | Subscribes to the Queue, and begins receiving events. |
unsubscribe() | Unsubscribes from the Queue, and stops receiving events. |
isSubscribed() | Returns true or false, depending on whether a subscription exists for the Queue. |
publish() | Publishes a Universal Messaging Event to the Queue. |
createTransaction() | Factory method to create a new Transaction for use on the Queue. |
getFilter() | Returns the SQL-style filter applied to an existing or subsequent subscription to the Queue. |
setFilter() | Sets the SQL-style filter to be applied to a subsequent subscription to the Queue. |
getName() | Returns the Queue’s fully qualified name (e.g. |
getResourceType() | Returns the constant Nirvana.QUEUE_RESOURCE, which identifies this resource as a Queue. |
on() | Registers a single event listener on the Queue for observable events of the specified type (see Nirvana.Observe for applicable observables). |
removeListener() | Removes a specific listener for observable events of the specified type (see Nirvana.Observe for applicable observables). |
TransactionalQueue | A TransactionalQueue object is returned by any call to Session.getQueue() when the optional second parameter, isTransactionalReader, is true. |
Functions | |
subscribe() | Subscribes to the TransactionalQueue, and begins receiving events. |
unsubscribe() | Unsubscribes from the TransactionalQueue, and stops receiving events. |
isSubscribed() | Returns true or false, depending on whether a subscription exists for the TransactionalQueue. |
publish() | Publishes a Universal Messaging Event to the TransactionalQueue. |
createTransaction() | Factory method to create a new Transaction for use on the TransactionalQueue. |
commit() | Commits the read of the supplied Event on the TransactionalQueue. |
commitAll() | Commits the read of all received Events on the TransactionalQueue. |
rollback() | Performs a Roll back of the TransactionalQueue to the supplied Event. |
getFilter() | Returns the SQL-style filter applied to an existing or subsequent subscription to the TransactionalQueue. |
setFilter() | Sets the SQL-style filter to be applied to a subsequent subscription to the TransactionalQueue. |
getWindowSize() | Returns the window size for transactional reading on the TransactionalQueue. |
setWindowSize() | Sets the window size for transactional reading on the TransactionalQueue. |
getName() | Returns the TransactionalQueue’s fully qualified name (e.g. |
getResourceType() | Returns the constant Nirvana.TRANSACTIONAL_QUEUE_RESOURCE, which identifies this resource as a TransactionalQueue. |
on() | Registers a single event listener on the TransactionalQueue for observable events of the specified type (see Nirvana.Observe for applicable observables). |
removeListener() | Removes a specific listener for observable events of the specified type (see Nirvana.Observe for applicable observables). |
Event | An Event object is returned by any call to Nirvana.createEvent(). |
Functions | |
getSession() | Returns the Session with which this Event is associated, or null if this is a new client-created Event. |
getResource() | Returns the resource object from which the Event was received, or null if this is a new client-created Event. |
getResourceName() | Returns the name of the resource with which the Event is associated, or null if this is a new client-created Event. |
getTTL() | Returns the Event’s TTL (Time-to-live) in milliseconds. |
setTTL() | Sets the Event’s TTL (Time-to-live) in milliseconds. |
getEID() | Returns the Event’s ID (the EID). |
getData() | Returns the Event’s raw data, or undefined if it has no data. |
setData() | Sets the Event’s raw data. |
getTag() | Returns the Event’s tag, or undefined if it has no data. |
setTag() | Sets the Event’s tag. |
getDictionary() | Returns the Event’s EventDictionary. |
getEventAttributes() | Returns the Event’s EventAttributes. |
hasData() | Returns true if the Event has data, or false otherwise. |
hasTag() | Returns true if the Event has a tag, or false otherwise. |
hasDictionary() | Returns true if the Event has an EventDictionary, or false otherwise. |
EventDictionary | An EventDictionary object is returned by any call to Event.getDictionary() or Nirvana.createDictionary(). |
Constants | |
STRING | EventDictionary.STRING is an integer constant representing the String data type. |
LONG | EventDictionary.LONG is an integer constant representing the Long data type. |
DOUBLE | EventDictionary.DOUBLE is an integer constant representing the Double data type. |
BOOLEAN | EventDictionary.BOOLEAN is an integer constant representing the Boolean data type. |
INTEGER | EventDictionary.INTEGER is an integer constant representing the Integer data type. |
FLOAT | EventDictionary.FLOAT is an integer constant representing the Float data type. |
CHARACTER | EventDictionary.CHARACTER is an integer constant representing the Character data type. |
BYTE | EventDictionary.BYTE is an integer constant representing the Byte data type. |
DICTIONARY | EventDictionary.DICTIONARY is an integer constant representing the EventDictionary data type (useful for nested EventDictionaries). |
ARRAY | EventDictionary.ARRAY is an integer constant representing the Array data type. |
Functions | |
getKeys() | Returns an array of the keys contained in the EventDictionary. |
get() | Returns the value to which the EventDictionary maps the specified key. |
getType() | Returns the type of the value to which the EventDictionary maps the specified key. |
getArrayType() | Returns the type of the entries in the array value to which the EventDictionary maps the specified key. |
putString() | Associates the specified String value with the specified key in this EventDictionary. |
putLong() | Associates the specified String value with the specified key in this EventDictionary. |
putDouble() | Associates the specified EventDictionary.DOUBLE value with the specified key in this EventDictionary. |
putBoolean() | Associates the specified EventDictionary.BOOLEAN value with the specified key in this EventDictionary. |
putInteger() | Associates the specified EventDictionary.INTEGER value with the specified key in this EventDictionary. |
putFloat() | Associates the specified EventDictionary.FLOAT value with the specified key in this EventDictionary. |
putChar() | Associates the specified EventDictionary.CHARACTER value with the specified key in this EventDictionary. |
putByte() | Associates the specified EventDictionary.BYTE value with the specified key in this EventDictionary. |
putDictionary() | Associates the specified EventDictionary value with the specified key in this EventDictionary. |
putArray() | Associates the specified EventDictionary.ARRAY value with the specified key in this EventDictionary. |
EventAttributes | An EventAttributes object is returned by any call to Event.getEventAttributes(). |
Getters/ | |
getSubscriberHost() | Returns a string representing the subscriber host. |
getSubscriberName() | Returns a string representing the subscriber name. |
getSubscriberID() | Returns a string representing the subscriber ID. |
getPublisherHost() | Returns a string representing the publisher host. |
getPublisherName() | Returns a string representing the publisher name. |
setSubscriberHost() | Sets the subscriber host. |
setSubscriberName() | Sets the subscriber name. |
setPublisherName() | Sets the publisher name. |
setPublisherHost() | Sets the publisher host. |
Low-Level Getters/ | |
getAttribute() | Returns the value to which the EventAttributes maps the specified name. |
getAttributeNames() | Returns an array of an attribute names in this EventAttributes object. |
setAttribute() | Associates the specified value with the specified attribute name in this EventAttributes object. |
Read-Only methods accessing Immutable Server-Side Values | |
getTimeStamp() | Returns the Event’s publication timestamp as an integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC (Unix Epoch). |
getAllowMerge() | Returns true if the Event can be merged, or false otherwise. |
isDelta() | Returns true if the Event is a delta. |
isRedelivered() | Returns true if the Event is redelivered. |
isRegistered() | Returns true if the Event is a “registered event”, or false otherwise. |
Join-Specific Functions | Methods for working with Events received via Joined Channels. |
getJoinChannel() | Returns a string representing the name of the Channel from which the Event originated. |
getJoinEID() | Returns an integer representing the EID of the original Event on the joined Channel. |
getJoinPath() | Returns the names of all the Channels in the join path for the Event. |
getJoinRealm() | Returns a string representing the details of the realm on which the joined Channel exists. |
Dead-Event Functions | |
getDeadEID() | Returns the EID of the Dead Event |
getDeadEventStore() | Returns a string representing the name of the Dead Event’s dead event store (assuming it was consumed from a dead event store). |
JMS Functions | |
getApplicationID() | Returns the application ID allocated to the Event. |
getCorrelationID() | Returns the correlation ID allocated to the Event. |
getDeliveryMode() | Returns the delivery mode used for the Event. |
getDestination() | Returns the destination allocated to the Event. |
getExpiration() | Returns the expiration value allocated to the Event. |
getMessageID() | Returns the message ID allocated to the Event. |
getMessageType() | Returns an integer representing the message type of the Event. |
getPriority() | Returns an integer representing the Event priority. |
getRedeliveredCount() | Returns an integer representing the number of times the Event has been redelivered. |
getReplyToName() | Returns the “reply to” name allocated to the Event. |
getReplyType() | Returns an integer representing the reply type of the Event. |
getType() | Returns the arbitrary type of the Event. |
getUserID() | Returns the user ID given to the Event. |
setAllowMerge() | |
setApplicationID() | |
setCorrelationID() | |
setDeliveryMode() | |
setDestination() | |
setExpiration() | |
setMessageID() | |
setMessageType() | |
setPriority() | |
setReplyToName() | |
setReplyType() | |
setType() | |
setUserID() | |
setSubscriberID() | |
Transaction | A Transaction object is returned by any call to Channel.createTransaction(). |
Functions | |
publishAndCommit() | |
checkCommitStatus() | |
setEvent() | |
on() | Registers a single event listener on the Transaction for observable events of the specified type (see Nirvana.Observe for applicable observables). |
removeListener() | Removes a specific listener for observable events of the specified type (see Nirvana.Observe for applicable observables). |
Nirvana. | Nirvana.Utils provides access to a number of utility methods. |
Functions | |
isLoggingEnabled() | Returns true or false, depending on the value of a debugLevel key in the configuration object passed as an optional parameter to Nirvana.createSession(). |
Logger. | Assigns a user-defined function as the default log function which is invoked as appropriate, depending on the value of a debugLevel key in the configuration object passed as an optional parameter to Nirvana.createSession(). |
Logger. | Log a message to the debug log. |
Logger. | Log an exception to the debug log. |
base64Encode() | Takes a string and returns a base64 encoded representation of it. |
base64Decode() | Takes a base64-encoded string and returns the base64 decoded value. |
Nirvana. | Nirvana.EventDictionary provides the options for dictionary types |
Version & Support
JavaScript API Version BuildNumberHere. Released 12-Feb-1964.
For support, please open a Support Incident via Empower eServices at
https://empower.softwareag.com/
Telephone numbers for your local Support Center can be found at
https://empower.softwareag.com
If you have forgotten your Empower password, you can request a new one from
Copyright & License
Copyright 1999-2011 © My-Channels Copyright © 2012–2015 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.
Nirvana
Nirvana is the API namespace which provides a number of static methods and properties for creating Universal Messaging Sessions, Events, and EventDictionaries along with definitions of constants used throughout.
Constants | |
Observe | Nirvana.Observe defines constants which identify observable events that, when fired, notify interested listeners (see the on() and removeListener() methods in the Nirvana, Session, Channel, Queue and TransactionalQueue objects). |
Driver | Nirvana.Driver defines the names of all available transport drivers that may be used by a Session. |
VERSION_NUMBER | Nirvana.VERSION_NUMBER is an integer constant representing the API version number. |
BUILD_NUMBER | Nirvana.BUILD_NUMBER is an integer constant representing the API build number. |
BUILD_DATE | Nirvana.BUILD_DATE defines the API build date. |
CHANNEL_RESOURCE | Nirvana.CHANNEL_RESOURCE is an integer constant representing a Channel’s type. |
QUEUE_RESOURCE | Nirvana.QUEUE_RESOURCE is an integer constant representing a Queue’s type. |
TRANSACTIONAL_QUEUE_RESOURCE | Nirvana.TRANSACTIONAL_QUEUE_RESOURCE is an integer constant representing a TransactionalQueue’s type. |
Functions | |
createSession() | Creates and initializes (but does not start) a session object for communication with a Universal Messaging Realm Server. |
createEvent() | Factory method to create a new, empty Universal Messaging Event (typically for subsequent publishing to a resource such as a Channel or Queue). |
createDictionary() | Factory method to create a new, empty EventDictionary (typically for subsequent addition to an existing EventDictionary using EventDictionary.putDictionary()). |
on() | Registers a single event listener on the Nirvana object for observable events of the specified type (see Nirvana.Observe for a list of applicable observables). |
removeListener() | Removes a specific listener for observable events of the specified type (see Nirvana.Observe for a list of applicable observables). |
Observe
Nirvana.Observe defines constants which identify observable events that, when fired, notify interested listeners (see the on() and removeListener() methods in the Nirvana, Session, Channel, Queue and TransactionalQueue objects).
Observable Events for Nirvana
Nirvana.Observe.ERROR | Fires when an unexpected error occurs. Two parameters are passed to all listeners: the relevant Session object, and an exception with details of the error. |
Observable Events for Session
Nirvana.Observe.START | Fires when the Session successfully starts. The Session object itself is passed as a parameter to all listeners. |
Nirvana.Observe.STOP | Fires when the Session is cleanly closed. The Session object itself is passed as a parameter to all listeners. |
Nirvana.Observe.DISCONNECT | Fires when the Session is disconnected and automatically attempts to reconnect. The Session object itself is passed as a parameter to all listeners. |
Nirvana.Observe.RECONNECT | Fires when the Session has successfully automatically reconnected following temporary disconnection. The Session object itself is passed as a parameter to all listeners. |
Nirvana.Observe.DATA | Fires when a Universal Messaging Event is received by a DataStream-enabled Session. The Universal Messaging Event is passed as a parameter to all listeners. |
Nirvana.Observe.DRIVER_CHANGE- Fires when the Session’s transport driver changes for any reason. Two parameters are passed to all listeners: the Session object itself, and a string representing the name of the new driver (See Nirvana.Driver).
Nirvana.Observe.ERROR | Fires when an unexpected error occurs. Two parameters are passed to all listeners: the Session object itself, and an exception with details of the error. |
Observable Events for Resource Objects (Channels, Queues and TransactionalQueues)
Nirvana.Observe.SUBSCRIBE | Fires when a subscription to a resource such as a Channel or a Queue is successfully started. The resource itself is passed as a parameter to all listeners. |
Nirvana.Observe.DATA | Fires when a Universal Messaging Event is received by a Channel, Queue or TransactionalQueue resource. The Universal Messaging Event is passed as a parameter to all listeners. |
Nirvana.Observe.UNSUBSCRIBE | Fires when a subscription to a resource such as a Channel or a Queue is ended. The resource object itself is passed as a parameter to all listeners. |
Nirvana.Observe.PUBLISH | Fires when an event is successfully published to a resource such as a Channel or a Queue. Two parameters are passed to all listeners: the resource object itself, and a string representing the server’s response. |
Nirvana.Observe.ERROR | Fires when an unexpected error occurs. Two parameters are passed to all listeners: the resource object itself, and an exception with details of the error. |
Additional Observable Events TransactionalQueues
Nirvana.Observe.COMMIT | Fires when a transactional read is successfully committed to the server. Two parameters are passed to all listeners: The TransactionalQueue itself, and the response status. |
Nirvana.Observe.ROLLBACK | Fires when a transactional read is rolled back on the server. Two parameters are passed to all listeners: The TransactionalQueue itself, and the response status. |
Observable Events on Transactions
Nirvana.Observe.COMMIT | Fires when a transactional publish is successfully committed to the server. Two parameters are passed to all listeners: The Transaction itself, and the response status. |
Example Usage
function myHandler(evt) {
console.log(evt.getEID());
}
myChannel.on(Nirvana.Observe.DATA, myHandler);
myChannel.subscribe();
Note that the above example uses a named listener, myHandler, in the call to Channel.on(). This allows a developer to make a corresponding call to Channel.removeListener() when desired.
It is also possible to use an anonymous function as a listener.
myChannel.on(Nirvana.Observe.DATA, function(evt) {
console.log(evt.getEID());
});
myChannel.subscribe();
Use of an anonymous function as a listener is not recommended, however, as the lack of a reference to the anonymous function makes it impossible for a developer to remove the listener via removeListener(). It is almost always better to use a named listener as in the first example above.
See Also
Nirvana.on(), Session.on(), Channel.on(), Queue.on(), TransactionalQueue.on(), Transaction.on()
Driver
Nirvana.Driver defines the names of all available transport drivers that may be used by a Session. By default, a client will attempt to use all drivers in the order defined below, settling on the first driver that allows it to initialize a Session.
WEBSOCKET | Streaming driver for browsers supporting HTML5 Web Sockets. |
XHR_STREAMING_CORS | Streaming driver for browsers supporting XMLHTTPRequest with CORS (Cross-Origin Resource Sharing). Intended for Chrome, Firefox, Safari, IE10+ and MS Edge. |
IFRAME_STREAMING_POSTMESSAGE | Streaming driver for browsers supporting the cross-window postMessage API (per https://developer.mozilla.org |
EVENTSOURCE_STREAMING_POSTMESSAGE | Streaming driver for browsers supporting both Server-Sent-Events and the cross-window postMessage API. Intended for Chrome, Firefox and Safari. |
XHR_LONGPOLL_CORS | Longpoll driver for browsers supporting XMLHTTPRequest with CORS (Cross-Origin Resource Sharing). Intended for Chrome, Firefox, Safari, IE10+ and MS Edge. |
XHR_LONGPOLL_POSTMESSAGE | Longpoll driver for browsers supporting the cross-window postMessage API. Intended for Chrome, Firefox, Safari, IE8+ and MS Edge. |
NOXD_IFRAME_STREAMING | Legacy non-cross domain streaming driver for older clients requiring streaming from the realm that serves the application itself. Intended for Chrome, Firefox, Safari, IE6+ and MS Edge. |
JSONP_LONGPOLL | Longpoll driver for older browsers relying on DOM manipulation only. Browser will show “busy indicator/throbber” when in use. Intended for Chrome, Firefox, Safari, IE6+ and MS Edge. |
More about Drivers
Developers may override which transport drivers are available for use by specifying a drivers key (whose value is an array of driver names in order of preference) in the optional configuration object passed to Nirvana.createSession() - see example usage below.
Note that streaming drivers are, in general, to be preferred over longpoll drivers for many reasons. Some clients, however, may be restricted by intermediate infrastructure (such as poorly configured proxy servers) which may prevent them from successfully using a streaming driver. The various longpoll drivers provide a fallback for such clients.
All drivers, except the legacy NOXD IFRAME STREAMING driver, are fully cross domain.
Understanding Driver and Realm Failover
Each driver gets 3 consecutive attempts to initialise a session. If the client has to switch to a new driver, it will immediately try to connect and initialise a session. The second connection attempt has a delay of 1 second. The third attempt has a delay of 2 seconds. This is to avoid compounding problems on a server that may be undergoing maintenance or other load issues.
If the client’s session object has been configured to connect to just a single realm, then
- If the client gets a confirmed session to the realm, then, for the rest of the browsing session (until page reload) it will always use that driver thereafter. It will never attempt to fail over to a different driver as the selected driver will be the best option for the infrastructural environment.
- If it gets disconnected, it will continue retrying to connect with the same driver forever. To avoid any potential overloading issues, it will increase the delay between connection attempts by 1 second up to a maximum of rand(30,60) seconds.
If the client’s session object has been configured to connect to an array of more than one realm (e.g. realms in a cluster), then
- If the client gets a confirmed session to realm X, then it will always try to use that driver thereafter.
- If it gets disconnected from realm X, it will continue retrying to connect with the same driver for a maximum of 5 consecutive failed attempts (any successful connection will reset the failure count to 0). If the 5th attempt fails, it will switch to the next realm, re-enable all drivers, and start cycling through them again (giving each one 3 chances to connect as usual).
Example Usage
var session = Nirvana.createSession({
drivers : [
Nirvana.Driver.WEBSOCKET,
Nirvana.Driver.XHR_STREAMING_CORS,
Nirvana.Driver.XHR_LONGPOLL_CORS
]
});
session.start();
var driverName = session.getCurrentDriver();
See Also
VERSION_NUMBER
Nirvana.VERSION_NUMBER is an integer constant representing the API version number.
BUILD_NUMBER
Nirvana.BUILD_NUMBER is an integer constant representing the API build number.
BUILD_DATE
Nirvana.BUILD_DATE defines the API build date.
CHANNEL_RESOURCE
Nirvana.CHANNEL_RESOURCE is an integer constant representing a Channel’s type.
See Also
QUEUE_RESOURCE
Nirvana.QUEUE_RESOURCE is an integer constant representing a Queue’s type.
See Also
TRANSACTIONAL_QUEUE_RESOURCE
Nirvana.TRANSACTIONAL_QUEUE_RESOURCE is an integer constant representing a TransactionalQueue’s type.
See Also
createSession()
function createSession( config )
Creates and initializes (but does not start) a session object for communication with a Universal Messaging Realm Server.
Optional Parameter
config | An optional Session configuration object containing key/value value pairs. Any key/value pair in this configuration object is also optional. |
Configuration Object Keys (Optional)
drivers | An array of communication Drivers, in order of preference. Defaults to [ Nirvana.Driver.WEBSOCKET, Nirvana.Driver.XHR_STREAMING_CORS, Nirvana.Driver.IFRAME_STREAMING_POSTMESSAGE, Nirvana.Driver.EVENTSOURCE_STREAMING_POSTMESSAGE, Nirvana.Driver.XHR_LONGPOLL_CORS, Nirvana.Driver.XHR_LONGPOLL_POSTMESSAGE, Nirvana.Driver.NOXD_IFRAME_STREAMING, Nirvana.Driver.JSONP_LONGPOLL] |
rememberDriver | True or false. Defaults to false. If true, will store the first driver that results in a successful session in a cookie so that the client will try to start with the same driver (bypassing any drivers that would otherwise fail) the next time the application is loaded. This feature will only work if the client supports persistent cookies. |
applicationName | Defaults to “GenericJSClient”. |
sessionName | Defaults to “GenericJSSession”. |
username | Will be generated randomly if not supplied. |
realms | An array of (optionally, but typically, clustered) realms, each specified as “protocol://fqdn:port”. For example: [“http://node1.um.softwareag.com:80, http://node2.um.softwareag.com:80”, http://node3.um.softwareag.com:80”] If a client fails to connect to the current realm using any of the user-specified drivers (or the default drivers, if none are specified), then it will move on to the next realm in the array, repeating at the end of the array. |
debugLevel | 0 to 9, where 0 is maximum debug output and 9 is no debug output. Defaults to 9. A commonly used value in development might be 4. |
serverLogging | True or false. Defaults to false. |
verboseKeepAlives | True or false. Defaults to false. |
enableDataStreams | True or false. Defaults to true. |
sessionTimeoutMs | Time with no communication with server before session times out and resets. Defaults to 120000 (ms) = 2 Minutes. |
sendResponseTimeout | Time with no response from a request. Defaults to 10000 (ms) = 10 seconds. |
openDriverTimeout | Time to allow a session to initialise, with postMessage this may need to be increased if latency is high as there can be multiple files to download before a session can be initialised allowing a time out unnecessarily. Defaults to 15000 (ms) = 15 seconds. |
maxStreamLengthStreamingCors | Maximum streaming response content-length in bytes for XHR_STREAMING_CORS. As with all other keys in this object, maxStreamLengthStreamingCors is optional, but is useful for clients which have high data throughput or are long running as memory will be consumed due to browser implementation of responseText growing without cleaning up. Defaults to 10000000 (approximately 10mb). |
Returns
An object representing a Universal Messaging session.
Example Usage
var session = Nirvana.createSession();
session.start();
session.stop();
A session can be customized by passing in a configuration object containing keys which override default values, as follows:
var session = Nirvana.createSession({
realms : [ "https://showcase.um.softwareag.com:443" ],
debugLevel : 4
});
See Also
createEvent()
function createEvent()
Factory method to create a new, empty Universal Messaging Event (typically for subsequent publishing to a resource such as a Channel or Queue).
Returns
A new, empty Event.
Example Usage
var myEvent = Nirvana.createEvent();
var myDict = myEvent.getDictionary();
myDict.putString("message", "Hello World");
myChannel.publish(myEvent);
See Also
createDictionary()
function createDictionary()
Factory method to create a new, empty EventDictionary (typically for subsequent addition to an existing EventDictionary using EventDictionary.putDictionary()).
Returns
A new, empty EventDictionary.
Example Usage
var myEvent = Nirvana.createEvent();
var myDict = myEvent.getDictionary();
var newDict = Nirvana.createDictionary();
newDict.putString("message", "Hello World");
myDict.putDictionary("aNestedDictionary", newDict);
myChannel.publish(myEvent);
See Also
on()
function on( observable, listener )
Registers a single event listener on the Nirvana object for observable events of the specified type (see Nirvana.Observe for a list of applicable observables).
To register more than one observable listener for the same type, invoke on() with a different listener function as many times as needed.
Parameters
observable | the type of observable event in which the listener is interested. |
listener | the listener function you have implemented, which should handle the parameters associated with the relevant observable event as defined in Nirvana.Observe. |
Returns
The Nirvana object (making this a chainable method).
Example Usage
function myErrorHandler(session, exception) {
// This will receive errors such as total transport driver failures
}
Nirvana.on(Nirvana.Observe.ERROR, myErrorHandler);
// we can now also un-assign this listener any time we want to:
Nirvana.removeListener(Nirvana.Observe.ERROR, myErrorHandler);
See Also
removeListener()
function removeListener( observable, listener )
Removes a specific listener for observable events of the specified type (see Nirvana.Observe for a list of applicable observables).
Parameters
observable | the type of observable event in which the listener was interested. |
listener | the listener function originally assigned with on(), and which should now be removed. |
Returns
The Nirvana object (making this a chainable method).
Example Usage
Nirvana.removeListener(Nirvana.Observe.ERROR, myErrorHandler);
Notice that a reference to the listener is required if you wish to remove it. See the note about named and anonymous functions in the Nirvana.Observe Example Usage section.
See Also
Session
A Session object is returned by a call to Nirvana.createSession(). All Session objects are created with this factory method; Session has no built-in public constructor method.
This version of the API expects only one Session to be instantiated in any application. It is possible that future versions of the API will support concurrent Sessions.
Functions | |
start() | Starts the Session. |
stop() | Stops the Session. |
subscribe() | Batch-subscribes to multiple Channel, Queue and/or TransactionalQueue resources with a single call to the server. |
getChannel() | Returns the Channel object for the supplied channel name. |
getQueue() | Returns the Queue or TransactionalQueue object for the supplied queue name. |
on() | Registers a single event listener on the Session for observable events of the specified type (see Nirvana.Observe for a list of applicable observables). |
removeListener() | Removes a specific listener for observable events of the specified type (see Nirvana.Observe for a list of applicable observables). |
getUsername() | Returns the username used in this Session. |
getCurrentDriver() | Returns the name of the Session’s current transport driver. |
getCurrentRealm() | Returns the RNAME (in protocol://host:port format) of the realm server to which the Session is currently connected. |
getSessionID() | Returns the Session’s current session ID. |
getDataStreamID() | Returns the Session’s current DataStream ID. |
getConfig() | Returns the configuration object for the Session. |
getStatus() | Returns the Session’s current status, which describes whether it is, for example, not yet started, connected, disconnected, or stopped. |
isDataStreamEnabled() | Returns true or false, depending on whether the Session was configured to be DataStream-enabled (via setting of the dataStreamEnabled key in the configuration object passed as an optional parameter to Nirvana.createSession(). |
start()
this.start = function ()
Starts the Session. This will launch the first preferred transport driver and attempt to contact the first preferred realm to initialize a session. If the Session initializes successfully as a result of this call to Session.start(), then any listeners of the Nirvana.Observe.START observable event will be invoked with the new session as a parameter.
Note that there is no requirement that the developer wait for the Nirvana.Observe.START observable event to fire before attempting to interact with the Session; any such interactions will be transparently queued until the session has successfully initialized.
Returns
The Session object on which Session.start() was invoked (making this a chainable method).
Example Usage
Starting a Session can be very simple:
var mySession = Nirvana.createSession();
mySession.start();
Sessions support arbitrary orders of interaction (transparently queueing commands until realm server communication is possible). It is possible to start a session and subscribe to a channel as follows:
var mySession = Nirvana.createSession();
mySession.start();
mySession.subscribe(mySession.getChannel("/some/channel"));
The placement of the Session.start() call is flexible. The following would work just as well, for instance:
var mySession = Nirvana.createSession();
mySession.subscribe(mySession.getChannel("/some/channel"));
mySession.start();
Client code can be asynchronously notified of the actual session initialization. To do this, simply assign a listener to the Session’s Nirvana.Observe.START observable event:
function sessionStarted(s) {
console.log("Session started with ID " + s.getSessionID());
}
mySession.on(Nirvana.Observe.START, sessionStarted);
mySession.start();
See Also
stop()
this.stop = function ( forceClose )
Stops the Session. This will close the connection with the realm server, and set the Session’s status to STOPPED.
Returns
The Session object on which Session.stop() was invoked (making this a chainable method).
Example Usage
mySession.stop();
If a developer wishes to be asynchronously notified when the session has stopped, they can assign a listener to the Session’s Nirvana.Observe.STOP observable event.
function sessionStopped(session) {
console.log("Session " + session.getSessionID() + " explicitly stopped");
}
mySession.on(Nirvana.Observe.STOP, sessionStopped);
mySession.stop();
See Also
subscribe()
this.subscribe = function ( resourceArray )
Batch-subscribes to multiple Channel, Queue and/or TransactionalQueue resources with a single call to the server.
If attempting to subscribe to more than one resource at a time, this is considerably more efficient than using the resource-level subscription methods such as Channel.subscribe().
This method may be used in place of resource-level subscription methods such as Channel.subscribe() even if intending to subscribe only to a single resource; either approach is a matter of developer preference.
Each successful subscription or failure will fire an observable event both on the respective Channel, Queue, and/or TransactionalQueue resource object, and on the Session.
Parameters
resourceArray | an array of Channel, Queue, and/or TransactionalQueue resource objects. |
Returns
The Session object on which Session.subscribe() was invoked (making this a chainable method).
Example Usage
var myChannel = mySession.getChannel("/some/channel");
var myChannel2 = mySession.getChannel("/some/other/channel");
var myQueue = mySession.getQueue("/some/queue");
mySession.subscribe([myChannel, myChannel2, myQueue]);
If a developer wishes to be asynchronously notified when a resource subscription is successful (or if a subscription error occurs), they can assign appropriate listeners to the respective resource, as shown below:
function subscriptionCompleteHandler(resource) {
// subscription to this resource was successful
}
function errorHandler(resource, ex) {
if (ex instanceof MissingResourceException) {
console.log("Resource " + resource.getName() + " not found: " + ex.message);
}
else if (ex instanceof AlreadySubscribedException) {
console.log("Already subscribed to " + resource.getName());
}
else if (ex instanceof SecurityException) {
console.log("ACL error for " + resource.getName() + ": " + ex.message);
}
}
function eventHandler(evt) {
console.log("Received event from: " + evt.getResourceName());
}
myChannel.on(Nirvana.Observe.SUBSCRIBE, subscriptionCompleteHandler);
myChannel.on(Nirvana.Observe.ERROR, errorHandler);
myChannel.on(Nirvana.Observe.DATA, eventHandler);
mySession.subscribe([myChannel, myChannel2, myQueue]);
See Also
Nirvana.Observe, Channel.subscribe(), Queue.subscribe(), TransactionalQueue.subscribe()
getChannel()
this.getChannel = function ( channelName )
Returns the Channel object for the supplied channel name. Note that a valid object will be returned irrespective of whether this resource actually exists on the realm server.
Parameters
channelName | a string representation of the fully qualified channel name (e.g. “/some/channel”). |
Returns
A Channel object for the supplied channel name.
Example Usage
var myChannel = mySession.getChannel("/some/channel");
getQueue()
this.getQueue = function ( queueName, isTransactionalReader )
Returns the Queue or TransactionalQueue object for the supplied queue name. If the optional second parameter is not supplied (or has a false value), then a Queue is returned. If the value of the second parameter is true, then a TransactionalQueue is returned. Note that a valid object will be returned irrespective of whether this resource actually exists on the realm server.
Parameters
queueName | a string representation of the fully qualified channel name (e.g. “/some/queue”). |
isTransactionalReader | a boolean representing whether this should be a transactional reader. |
Returns
A Queue or TransactionalQueue object for the supplied queue name.
Example Usage
var myQueue = mySession.getQueue("/some/queue");
on()
this.on = function ( observable, listener )
Registers a single event listener on the Session for observable events of the specified type (see Nirvana.Observe for a list of applicable observables).
To register more than one observable listener for the same type, invoke on() with a different listener function as many times as needed.
Parameters
observable | the type of observable event in which the listener is interested. |
listener | the listener function you have implemented, which should handle the parameters associated with the relevant observable event as defined in Nirvana.Observe. |
Returns
The Session object on which Session.on() was invoked (making this a chainable method).
Example Usage
function myHandler(evt) {
// do something with the evt passed to us as a parameter
}
session.on(Nirvana.Observe.DATA, myHandler);
// we can now also un-assign this listener any time we want to:
session.removeListener(Nirvana.Observe.DATA, myHandler);
See Also
removeListener()
this.removeListener = function ( observable, listener )
Removes a specific listener for observable events of the specified type (see Nirvana.Observe for a list of applicable observables).
Parameters
observable | the type of observable event in which the listener was interested. |
listener | the listener function originally assigned with on(), and which should now be removed. |
Returns
The Session object on which Session.removeListener() was invoked (making this a chainable method).
Example Usage
session.removeListener(Nirvana.Observe.DATA, myHandler);
Notice that a reference to the listener is required if you wish to remove it. See the note about named and anonymous functions in the Nirvana.Observe Example Usage section.
See Also
getUsername()
this.getUsername = function ()
Returns the username used in this Session. A username can be optionally set when invoking Nirvana.createSession() with a suitable configuration object parameter.
Returns
The Session’s username.
Example Usage
var username = mySession.getUsername();
See Also
getCurrentDriver()
this.getCurrentDriver = function ()
Returns the name of the Session’s current transport driver. This will be one of the names defined in Nirvana.Driver, and, if the call to Nirvana.createSession() included a configuration object parameter with a “drivers” key, will be restricted to one of the user-specified drivers.
Returns
The name of the Session’s current transport driver.
Example Usage
var driverName = mySession.getCurrentDriver();
See Also
getCurrentRealm()
this.getCurrentRealm = function ()
Returns the RNAME (in protocol://host:port format) of the realm server to which the Session is currently connected. This will be one of the RNAMEs defined in the realms value in the configuration object passed into Nirvana.createSession(), or, if not configured, willbe derived from the protocol, host and port of the server which served the application itself.
Returns
The name of the realm to which the Session is connected.
Example Usage
var rname = mySession.getCurrentRealm();
See Also
getSessionID()
this.getSessionID = function ()
Returns the Session’s current session ID. This will be a string, generated and assigned by the realm server after a successful session start or reconnection.
Returns
A string representing the Session’s current session ID.
Example Usage
var sessionID = mySession.getSessionID();
See Also
getDataStreamID()
this.getDataStreamID = function ()
Returns the Session’s current DataStream ID. This will be a string, generated and assigned by the realm server after a successful session start or reconnection IF the session was DataStream-enabled (see enableDataStreams property of session configuration object).
Returns
A string representing the Session’s current DataStream ID.
Example Usage
var dataStreamID = mySession.getDataStreamID();
See Also
getConfig()
this.getConfig = function ()
Returns the configuration object for the Session. Its key/value pairs will be affected by any user-specified values in the optional configuration object if passed as a parameter to Nirvana.createSession(). Some such values (such as the drivers value) may have changed over time, depending on client capabilities.
Returns
The configuration object for the Session.
Example Usage
var config = mySession.getConfig();
var myRealmArray = config.realms;
See Also
getStatus()
this.getStatus = function ()
Returns the Session’s current status, which describes whether it is, for example, not yet started, connected, disconnected, or stopped. The actual status value is represented by of the following string constants:
NOTSTARTED | Session.start() has not yet been invoked. |
CONNECTING | Session.start() has been invoked, but the Session has not yet been initialized with a sessionID. |
CONNECTED | The Session is successfully connected, and a sessionID has been assigned. |
RECONNECTING | The Session has been temporarily disconnected and is automatically attempting to reconnect. |
STOPPED | Session.stop() has been invoked and the Session is disconnected. |
Returns
A string representing the Session’s current status.
Example Usage
var status = mySession.getStatus();
isDataStreamEnabled()
this.isDataStreamEnabled = function ()
Returns true or false, depending on whether the Session was configured to be DataStream-enabled (via setting of the dataStreamEnabled key in the configuration object passed as an optional parameter to Nirvana.createSession().
Returns
A boolean value of true or false.
Example Usage
if ( mySession.isDataStreamEnabled() ) {
console.log("This DataStream session receives events from any DataGroup of which it is a member.");
}
See Also
Channel
A Channel object is returned by any call to Session.getChannel(). All Channel objects are created with this factory method; Channel has no built-in public constructor method.
Functions | |
subscribe() | Subscribes to the Channel, and begins receiving events. |
unsubscribe() | Unsubscribes from the Channel, and stops receiving events. |
isSubscribed() | Returns true or false, depending on whether a subscription exists for the Channel. |
publish() | Publishes a Universal Messaging Event to the Channel. |
createTransaction() | Factory method to create a new Transaction for use on the Channel. |
getStartEID() | Returns the Event ID (the “EID”) from which an existing subscription to the Channel started, or from which a subsequent subscription to the Channel will start. |
setStartEID() | Sets the Event ID (the “EID”) from which a subsequent subscription to the Channel shall start. |
getCurrentEID() | Returns the Event ID (the “EID”) which an existing subscription to the Channel is at. |
getFilter() | Returns the SQL-style filter applied to an existing or subsequent subscription to the Channel. |
setFilter() | Sets the SQL-style filter to be applied to a subsequent subscription to the Channel. |
getName() | Returns the Channel’s fully qualified name (e.g. |
getResourceType() | Returns the constant Nirvana.CHANNEL_RESOURCE, which identifies this resource as a Channel. |
on() | Registers a single event listener on the Channel for observable events of the specified type (see Nirvana.Observe for applicable observables). |
removeListener() | Removes a specific listener for observable events of the specified type (see Nirvana.Observe for applicable observables). |
subscribe()
this.subscribe = function ()
Subscribes to the Channel, and begins receiving events.
Each successful subscription or failure will fire an observable event both on the respective Channel resource object, and on the Session (see Nirvana.Observe for applicable observables).
Returns
The Channel object on which Channel.subscribe() was invoked (making this a chainable method).
Example Usage
var myChannel = mySession.getChannel("/some/channel");
function eventHandler(evt) {
console.log("Received event from: " + evt.getResourceName());
}
myChannel.on(Nirvana.Observe.DATA, eventHandler);
myChannel.subscribe();
Additional Information
For more information on assignment of listeners for subscription success or failure and for receipt of individual events, please see Session.subscribe(), as the techniques and caveats discussed there also apply.
See Also
unsubscribe()
this.unsubscribe = function ()
Unsubscribes from the Channel, and stops receiving events.
A successful or failed unsubscription attempt will fire an observable event on the Channel (see Nirvana.Observe for applicable observables).
Returns
The Channel object on which Channel.unsubscribe() was invoked (making this a chainable method).
Example Usage
function unsubscribeHandler(resource) {
console.log("Unsubscribed from: " + resource.getName());
}
myChannel.on(Nirvana.Observe.UNSUBSCRIBE, unsubscribeHandler);
myChannel.unsubscribe();
See Also
isSubscribed()
this.isSubscribed = function ()
Returns true or false, depending on whether a subscription exists for the Channel.
Returns
A boolean value of true or false.
Example Usage
if ( !myChannel.isSubscribed() ) {
myChannel.subscribe();
}
See Also
publish()
this.publish = function ( event )
Publishes a Universal Messaging Event to the Channel.
Parameters
event | the Universal Messaging Event which is to be published to this Channel. |
Returns
The Channel object on which Channel.publish() was invoked (making this a chainable method).
Example Usage
var myEvent = Nirvana.createEvent();
var myDict = myEvent.getDictionary();
myDict.putString("message", "Hello World");
myChannel.publish(myEvent);
createTransaction()
this.createTransaction = function ()
Factory method to create a new Transaction for use on the Channel.
Returns
A new Transaction object.
Example Usage
var myTransaction = myChannel.createTransaction();
getStartEID()
this.getStartEID = function ()
Returns the Event ID (the “EID”) from which an existing subscription to the Channel started, or from which a subsequent subscription to the Channel will start. This defaults to 0 unless it is set with setStartEID().
Returns
An integer representing the EID from which any subscription on the Channel will start.
Example Usage
var startEID = myChannel.getStartEID();
See Also
Channel.setStartEID(), Channel.subscribe(), Channel.getFilter(), Channel.setFilter()
setStartEID()
this.setStartEID = function ( eid )
Sets the Event ID (the “EID”) from which a subsequent subscription to the Channel shall start. This defaults to 0 if not set explicitly.
Parameters
eid | the Event ID (the “EID”) from which any subsequent subscription to the Channel shall start. |
Returns
The Channel object on which Channel.setStartEID() was invoked (making this a chainable method).
Example Usage
var myChannel = mySession.getChannel("/some/channel");
myChannel.setStartEID(5106); // receive only events with EID 5016 or higher
myChannel.subscribe();
See Also
Channel.getStartEID(), Channel.subscribe(), Channel.getFilter(), Channel.setFilter()
getCurrentEID()
this.getCurrentEID = function ()
Returns the Event ID (the “EID”) which an existing subscription to the Channel is at. This defaults to -1 before any events are received.
Returns
An integer representing the EID which the subscription on the Channel is up to.
Example Usage
var currentEID = myChannel.getCurrentEID();
See Also
<Channel.setCurrentEID()>, Channel.subscribe(), Channel.getFilter(), Channel.setFilter()
getFilter()
this.getFilter = function ()
Returns the SQL-style filter applied to an existing or subsequent subscription to the Channel. By default, no filter is used unless one is set with setFilter().
Returns
A string representing the filter applied to an existing or subsequent subscription to the Channel.
Example Usage
var filter = myChannel.getFilter();
See Also
Channel.setFilter(), Channel.subscribe(), Channel.getStartEID(), Channel.setStartEID()
setFilter()
this.setFilter = function ( newFilter )
Sets the SQL-style filter to be applied to a subsequent subscription to the Channel. No filter is applied to a subscription if one is not set explicitly using this method.
Parameters
filter | the SQL-style filter to be applied to a subsequent subscription to the Channel. |
Returns
The Channel object on which Channel.setFilter() was invoked (making this a chainable method).
Example Usage
var myChannel = mySession.getChannel("/some/channel");
// receive only events matching the following filter:
myChannel.setFilter("currencypair = 'USDGBP' AND price < 0.6385");
myChannel.subscribe();
See Also
Channel.getFilter(), Channel.subscribe(), Channel.getStartEID(), Channel.setStartEID()
getResourceType()
this.getResourceType = function ()
Returns the constant Nirvana.CHANNEL_RESOURCE, which identifies this resource as a Channel.
Returns
A integer constant equal to Nirvana.CHANNEL_RESOURCE.
Example Usage
if (myChannel.getResourceType() === Nirvana.CHANNEL_RESOURCE) {
console.log("myChannel is a channel");
}
on()
this.on = function ( observable, listener )
Registers a single event listener on the Channel for observable events of the specified type (see Nirvana.Observe for applicable observables).
Parameters
observable | the type of observable event in which the listener is interested. |
listener | the listener function you have implemented, which should handle the parameters associated with the relevant observable event as defined in Nirvana.Observe. |
Returns
The Channel object on which Channel.on() was invoked (making this a chainable method).
Example Usage
function myHandler(evt) {
console.log("Received event from: " + evt.getResourceName());
}
myChannel.on(Nirvana.Observe.DATA, myHandler);
Additional Information
For more information on assigning listeners for Nirvana.Observe.DATA or any other observable event, please see the Nirvana.Observe Example Usage section.
See Also
removeListener()
this.removeListener = function ( observable, listener )
Removes a specific listener for observable events of the specified type (see Nirvana.Observe for applicable observables).
Parameters
observable | the type of observable event in which the listener was interested. |
listener | the listener function originally assigned with on(), and which should now be removed. |
Returns
The Channel object on which Channel.removeListener() was invoked (making this a chainable method).
Example Usage
function myHandler(evt) {
// do something with the evt passed to us as a parameter
}
myChannel.on(Nirvana.Observe.DATA, myHandler);
// when we want to, we can un-assign the listener:
myChannel.removeListener(Nirvana.Observe.DATA, myHandler);
Additional Information
For more information on removing listeners for Nirvana.Observe.DATA or any other observable event, please see the Nirvana.Observe Example Usage section.
See Also
Queue
A Queue object is returned by any call to Session.getQueue() when the optional second Queue, isTransactionalReader, is either not supplied or is false.
If the optional second parameter is true, then a TransactionalQueue object is returned instead.
All Queue objects are created with this factory method; Queue has no built-in public constructor method.
See Also
Functions | |
subscribe() | Subscribes to the Queue, and begins receiving events. |
unsubscribe() | Unsubscribes from the Queue, and stops receiving events. |
isSubscribed() | Returns true or false, depending on whether a subscription exists for the Queue. |
publish() | Publishes a Universal Messaging Event to the Queue. |
createTransaction() | Factory method to create a new Transaction for use on the Queue. |
getFilter() | Returns the SQL-style filter applied to an existing or subsequent subscription to the Queue. |
setFilter() | Sets the SQL-style filter to be applied to a subsequent subscription to the Queue. |
getName() | Returns the Queue’s fully qualified name (e.g. |
getResourceType() | Returns the constant Nirvana.QUEUE_RESOURCE, which identifies this resource as a Queue. |
on() | Registers a single event listener on the Queue for observable events of the specified type (see Nirvana.Observe for applicable observables). |
removeListener() | Removes a specific listener for observable events of the specified type (see Nirvana.Observe for applicable observables). |
subscribe()
this.subscribe = function ()
Subscribes to the Queue, and begins receiving events.
Each successful subscription or failure will fire an observable event both on the respective Queue resource object, and on the Session (see Nirvana.Observe for applicable observables).
Returns
The Queue object on which Queue.subscribe() was invoked (making this a chainable method).
Example Usage
var myQueue = mySession.getChannel("/some/queue");
function eventHandler(evt) {
console.log("Received event from: " + evt.getResourceName());
}
myQueue.on(Nirvana.Observe.DATA, eventHandler);
myQueue.subscribe();
Additional Information
For more information on assignment of listeners for subscription success or failure and for receipt of individual events, please see Session.subscribe(), as the techniques and caveats discussed there also apply.
See Also
unsubscribe()
this.unsubscribe = function ()
Unsubscribes from the Queue, and stops receiving events.
A successful or failed unsubscription attempt will fire an observable event on the Queue (see Nirvana.Observe for applicable observables).
Returns
The Queue object on which Queue.unsubscribe() was invoked (making this a chainable method).
Example Usage
function unsubscribeHandler(resource) {
console.log("Unsubscribed from: " + resource.getName());
}
myQueue.on(Nirvana.Observe.UNSUBSCRIBE, unsubscribeHandler);
myQueue.unsubscribe();
See Also
isSubscribed()
this.isSubscribed = function ()
Returns true or false, depending on whether a subscription exists for the Queue.
Returns
A boolean value of true or false.
Example Usage
if ( !myQueue.isSubscribed() ) {
myQueue.subscribe();
}
See Also
publish()
this.publish = function ( event )
Publishes a Universal Messaging Event to the Queue.
Parameters
event | the Universal Messaging Event which is to be published to this Queue. |
Returns
The Queue object on which Queue.publish() was invoked (making this a chainable method).
Example Usage
var myEvent = Nirvana.createEvent();
var myDict = myEvent.getDictionary();
myDict.putString("message", "Hello World");
myQueue.publish(myEvent);
createTransaction()
this.createTransaction = function ()
Factory method to create a new Transaction for use on the Queue.
Returns
A new Transaction object.
Example Usage
var myTransaction = myQueue.createTransaction();
getFilter()
this.getFilter = function ()
Returns the SQL-style filter applied to an existing or subsequent subscription to the Queue. By default, no filter is used unless one is set with setFilter().
Returns
A string representing the filter applied to an existing or subsequent subscription to the Queue.
Example Usage
var filter = myQueue.getFilter();
See Also
setFilter()
this.setFilter = function ( newFilter )
Sets the SQL-style filter to be applied to a subsequent subscription to the Queue. No filter is applied to a subscription if one is not set explicitly using this method.
Parameters
filter | the SQL-style filter to be applied to a subsequent subscription to the Queue. |
Returns
The Queue object on which Queue.setFilter() was invoked (making this a chainable method).
Example Usage
var myQueue = mySession.getQueue("/some/queue");
// receive only events matching the following filter:
myQueue.setFilter("currencypair = 'USDGBP' AND price < 0.6385");
myQueue.subscribe();
See Also
getResourceType()
this.getResourceType = function ()
Returns the constant Nirvana.QUEUE_RESOURCE, which identifies this resource as a Queue.
Returns
A integer constant equal to Nirvana.QUEUE_RESOURCE.
Example Usage
if (myQueue.getResourceType() === Nirvana.QUEUE_RESOURCE) {
console.log("myQueue is a queue");
}
on()
this.on = function ( observable, listener )
Registers a single event listener on the Queue for observable events of the specified type (see Nirvana.Observe for applicable observables).
Parameters
observable | the type of observable event in which the listener is interested. |
listener | the listener function you have implemented, which should handle the parameters associated with the relevant observable event as defined in Nirvana.Observe. |
Returns
The Queue object on which Queue.on() was invoked (making this a chainable method).
Example Usage
function myHandler(evt) {
console.log("Received event from: " + evt.getResourceName());
}
myQueue.on(Nirvana.Observe.DATA, myHandler);
Additional Information
For more information on assigning listeners for Nirvana.Observe.DATA or any other observable event, please see the Nirvana.Observe Example Usage section.
See Also
removeListener()
this.removeListener = function ( observable, listener )
Removes a specific listener for observable events of the specified type (see Nirvana.Observe for applicable observables).
Parameters
observable | the type of observable event in which the listener was interested. |
listener | the listener function originally assigned with on(), and which should now be removed. |
Returns
The Queue object on which Queue.removeListener() was invoked (making this a chainable method).
Example Usage
function myHandler(evt) {
// do something with the evt passed to us as a parameter
}
myQueue.on(Nirvana.Observe.DATA, myHandler);
// when we want to, we can un-assign the listener:
myQueue.removeListener(Nirvana.Observe.DATA, myHandler);
Additional Information
For more information on removing listeners for Nirvana.Observe.DATA or any other observable event, please see the Nirvana.Observe Example Usage section.
See Also
TransactionalQueue
A TransactionalQueue object is returned by any call to Session.getQueue() when the optional second parameter, isTransactionalReader, is true.
If the optional second parameter is either not supplied or is false, then a basic Queue object is returned instead.
All TransactionalQueue objects are created with this factory method; TransactionalQueue has no built-in public constructor method.
A TransactionalQueue is a type of Queue, but with additional transactional read behaviour. It offers all of the methods of Queue, but also offers the following additional methods:
- TransactionalQueue.commit(),
- TransactionalQueue.commitAll(),
- TransactionalQueue.rollback(),
- TransactionalQueue.setWindowSize() and
- TransactionalQueue.getWindowSize().
See Also
Functions | |
subscribe() | Subscribes to the TransactionalQueue, and begins receiving events. |
unsubscribe() | Unsubscribes from the TransactionalQueue, and stops receiving events. |
isSubscribed() | Returns true or false, depending on whether a subscription exists for the TransactionalQueue. |
publish() | Publishes a Universal Messaging Event to the TransactionalQueue. |
createTransaction() | Factory method to create a new Transaction for use on the TransactionalQueue. |
commit() | Commits the read of the supplied Event on the TransactionalQueue. |
commitAll() | Commits the read of all received Events on the TransactionalQueue. |
rollback() | Performs a Roll back of the TransactionalQueue to the supplied Event. |
getFilter() | Returns the SQL-style filter applied to an existing or subsequent subscription to the TransactionalQueue. |
setFilter() | Sets the SQL-style filter to be applied to a subsequent subscription to the TransactionalQueue. |
getWindowSize() | Returns the window size for transactional reading on the TransactionalQueue. |
setWindowSize() | Sets the window size for transactional reading on the TransactionalQueue. |
getName() | Returns the TransactionalQueue’s fully qualified name (e.g. |
getResourceType() | Returns the constant Nirvana.TRANSACTIONAL_QUEUE_RESOURCE, which identifies this resource as a TransactionalQueue. |
on() | Registers a single event listener on the TransactionalQueue for observable events of the specified type (see Nirvana.Observe for applicable observables). |
removeListener() | Removes a specific listener for observable events of the specified type (see Nirvana.Observe for applicable observables). |
subscribe()
this.subscribe = function ()
Subscribes to the TransactionalQueue, and begins receiving events.
Each successful subscription or failure will fire an observable event both on the respective TransactionalQueue resource object, and on the Session (see Nirvana.Observe for applicable observables).
Returns
The TransactionalQueue object on which TransactionalQueue.subscribe() was invoked (making this a chainable method).
Example Usage
var myTransactionalQueue = mySession.getChannel("/some/queue");
function eventHandler(evt) {
console.log("Received event from: " + evt.getResourceName());
}
myTransactionalQueue.on(Nirvana.Observe.DATA, eventHandler);
myTransactionalQueue.subscribe();
Additional Information
For more information on assignment of listeners for subscription success or failure and for receipt of individual events, please see Session.subscribe(), as the techniques and caveats discussed there also apply.
See Also
unsubscribe()
this.unsubscribe = function ()
Unsubscribes from the TransactionalQueue, and stops receiving events.
A successful or failed unsubscription attempt will fire an observable event on the Queue (see Nirvana.Observe for applicable observables).
Returns
The TransactionalQueue object on which TransactionalQueue.unsubscribe() was invoked (making this a chainable method).
Example Usage
function unsubscribeHandler(resource) {
console.log("Unsubscribed from: " + resource.getName());
}
myTransactionalQueue.on(Nirvana.Observe.UNSUBSCRIBE, unsubscribeHandler);
myTransactionalQueue.unsubscribe();
See Also
TransactionalQueue.subscribe(), Session.subscribe(), Nirvana.Observe
isSubscribed()
this.isSubscribed = function ()
Returns true or false, depending on whether a subscription exists for the TransactionalQueue.
Returns
A boolean value of true or false.
Example Usage
if ( !myTransactionalQueue.isSubscribed() ) {
myTransactionalQueue.subscribe();
}
See Also
publish()
this.publish = function ( event )
Publishes a Universal Messaging Event to the TransactionalQueue.
Parameters
event | the Universal Messaging Event which is to be published to this TransactionalQueue. |
Returns
The TransactionalQueue object on which TransactionalQueue.publish() was invoked (making this a chainable method).
Example Usage
var myEvent = Nirvana.createEvent();
var myDict = myEvent.getDictionary();
myDict.putString("message", "Hello World");
myTransactionalQueue.publish(myEvent);
createTransaction()
this.createTransaction = function ()
Factory method to create a new Transaction for use on the TransactionalQueue.
Returns
A new Transaction object.
Example Usage
var myTransaction = myTransactionalQueue.createTransaction();
commit()
this.commit = function ( event )
Commits the read of the supplied Event on the TransactionalQueue. If there are any Event objects which the client has previously received but not called commit on, they will be implicitly committed.
Parameters
event | the Universal Messaging Event for which a read is to be committed on this TransactionalQueue. |
Returns
The TransactionalQueue object on which TransactionalQueue.commit() was invoked (making this a chainable method).
Example Usage
var dataCallback = function(event) {
myQueue.commit(event); // commit every event we receive
}
myQueue.on(Nirvana.Observe.DATA, dataCallback);
commitAll()
this.commitAll = function ()
Commits the read of all received Events on the TransactionalQueue. This behaves the same as committing the most recent event received by the client.
Returns
The TransactionalQueue object on which TransactionalQueue.commitAll() was invoked (making this a chainable method).
Example Usage
var dataCallback = function(event) {
myQueue.commitAll(); // Same as doing myQueue.commit(event)
}
myQueue.on(Nirvana.Observe.DATA, dataCallback);
rollback()
this.rollback = function ( event )
Performs a Roll back of the TransactionalQueue to the supplied Event. Any uncommitted events received after the given parameter will be added to the queue and redelivered to clients.
Note that different clients may receive the redelivered events.
Parameters
event | the Universal Messaging Event for which a read is to be rolled back from this TransactionalQueue. |
Returns
The TransactionalQueue object on which TransactionalQueue.rollback() was invoked (making this a chainable method).
Example Usage
var myEvents = [];
var dataCallback = function(event) {
myEvents.push(event);
if(myEvents.length === 5) {
myQueue.rollback(myEvents[0]); // Rolls back myEvents[1] to myEvents[4]
}
}
myQueue.on(Nirvana.Observe.DATA, dataCallback);
getFilter()
this.getFilter = function ()
Returns the SQL-style filter applied to an existing or subsequent subscription to the TransactionalQueue. By default, no filter is used unless one is set with setFilter().
Returns
A string representing the filter applied to an existing or subsequent subscription to the TransactionalQueue.
Example Usage
var filter = myTransactionalQueue.getFilter();
See Also
TransactionalQueue.setFilter(), TransactionalQueue.subscribe()
setFilter()
this.setFilter = function ( newFilter )
Sets the SQL-style filter to be applied to a subsequent subscription to the TransactionalQueue. No filter is applied to a subscription if one is not set explicitly using this method.
Parameters
filter | the SQL-style filter to be applied to a subsequent subscription to the TransactionalQueue. |
Returns
The TransactionalQueue object on which TransactionalQueue.setFilter() was invoked (making this a chainable method).
Example Usage
var myTransactionalQueue = mySession.getQueue("/some/queue");
// receive only events matching the following filter:
myTransactionalQueue.setFilter("currencypair = 'USDGBP' AND price < 0.6385");
myTransactionalQueue.subscribe();
See Also
TransactionalQueue.getFilter(), TransactionalQueue.subscribe()
getWindowSize()
this.getWindowSize = function ()
Returns the window size for transactional reading on the TransactionalQueue. By default, its value is 5 unless changed with TransactionalQueue.setWindowSize().
The window size for a TransactionalQueue indicates how many events will be delivered by the server to the client before the client must call TransactionalQueue.commit() or TransactionalQueue.rollback().
Returns
An integer representing the window size of the current or future subscription to this TransactionalQueue.
Example Usage
var windowSize = myTransactionalQueue.getWindowSize();
See Also
setWindowSize()
this.setWindowSize = function ( newWindowSize )
Sets the window size for transactional reading on the TransactionalQueue.
This defines the number of Events that can be read before the reads are committed with a call to <TransactionalQueue.commit(Event)> or TransactionalQueue.rollback().
If the window size is not explicitly set with a call to TransactionalQueue.setWindowSize(), then the default value is 5.
Parameters
A positive integer, greater than 0. Representing the new window size of this TransactionalQueue.
Returns
The TransactionalQueue object on which TransactionalQueue.setWindowSize() was invoked (making this a chainable method).
Example Usage
myTransactionalQueue.setWindowSize(10);
See Also
getName()
this.getName = function ()
Returns the TransactionalQueue’s fully qualified name (e.g. “/some/queue”).
Returns
A string representing the TransactionalQueue’s fully qualified name.
Example Usage
var transactionalQueueName = myTransactionalQueue.getName();
See Also
getResourceType()
this.getResourceType = function ()
Returns the constant Nirvana.TRANSACTIONAL_QUEUE_RESOURCE, which identifies this resource as a TransactionalQueue.
Returns
A integer constant equal to Nirvana.TRANSACTIONAL_QUEUE_RESOURCE.
Example Usage
if (myQueue.getResourceType() === Nirvana.TRANSACTIONAL_QUEUE_RESOURCE) {
console.log("myQueue is a queue with a transactional reader");
}
on()
this.on = function ( observable, listener )
Registers a single event listener on the TransactionalQueue for observable events of the specified type (see Nirvana.Observe for applicable observables).
Parameters
observable | the type of observable event in which the listener is interested. |
listener | the listener function you have implemented, which should handle the parameters associated with the relevant observable event as defined in Nirvana.Observe. |
Returns
The TransactionalQueue object on which TransactionalQueue.on() was invoked (making this a chainable method).
Example Usage
function myHandler(evt) {
console.log("Received event from: " + evt.getResourceName());
}
myTransactionalQueue.on(Nirvana.Observe.DATA, myHandler);
Additional Information
For more information on assigning listeners for Nirvana.Observe.DATA or any other observable event, please see the Nirvana.Observe Example Usage section.
See Also
removeListener()
this.removeListener = function ( observable, listener )
Removes a specific listener for observable events of the specified type (see Nirvana.Observe for applicable observables).
Parameters
observable | the type of observable event in which the listener was interested. |
listener | the listener function originally assigned with on(), and which should now be removed. |
Returns
The TransactionalQueue object on which TransactionalQueue.removeListener() was invoked (making this a chainable method).
Example Usage
function myHandler(evt) {
// do something with the evt passed to us as a parameter
}
myTransactionalQueue.on(Nirvana.Observe.DATA, myHandler);
// when we want to, we can un-assign the listener:
myTransactionalQueue.removeListener(Nirvana.Observe.DATA, myHandler);
Additional Information
For more information on removing listeners for Nirvana.Observe.DATA or any other observable event, please see the Nirvana.Observe Example Usage section.
See Also
Event
An Event object is returned by any call to Nirvana.createEvent(). All client-created Event objects are created with this factory method; Event has no built-in public constructor method. In addition, all messages received via a subscription to a resource such as a Channel or Queue are of type Event; these Events are passed to any subscribed resource’s listeners of the Nirvana.Observe.DATA observable event.
Functions | |
getSession() | Returns the Session with which this Event is associated, or null if this is a new client-created Event. |
getResource() | Returns the resource object from which the Event was received, or null if this is a new client-created Event. |
getResourceName() | Returns the name of the resource with which the Event is associated, or null if this is a new client-created Event. |
getTTL() | Returns the Event’s TTL (Time-to-live) in milliseconds. |
setTTL() | Sets the Event’s TTL (Time-to-live) in milliseconds. |
getEID() | Returns the Event’s ID (the EID). |
getData() | Returns the Event’s raw data, or undefined if it has no data. |
setData() | Sets the Event’s raw data. |
getTag() | Returns the Event’s tag, or undefined if it has no data. |
setTag() | Sets the Event’s tag. |
getDictionary() | Returns the Event’s EventDictionary. |
getEventAttributes() | Returns the Event’s EventAttributes. |
hasData() | Returns true if the Event has data, or false otherwise. |
hasTag() | Returns true if the Event has a tag, or false otherwise. |
hasDictionary() | Returns true if the Event has an EventDictionary, or false otherwise. |
getSession()
Event.prototype.getSession = function getSession()
Returns the Session with which this Event is associated, or null if this is a new client-created Event.
If an Event is received via a subscription to a resource such as a Channel, Queue or TransactionalQueue then this method will return the Session object with which the resource, and thus the Event, is associated.
If an Event has been created locally with a call to Nirvana.createEvent(), then this method will return null.
Returns
A Session object or null.
Example Usage
var s = evt.getSession();
if (s != null) {
s.getChannel("/some/channel").publish(evt);
}
getResource()
Event.prototype.getResource = function getResource()
Returns the resource object from which the Event was received, or null if this is a new client-created Event.
If this Event was received via a client-initiated subscription, then this method will return the corresponding Channel, Queue or TransactionalQueue object.
If this Event was received as a result of DataGroup membership via a DataStream-enabled Session, this method will return a reference to the Session object.
If an Event has been created locally with a call to Nirvana.createEvent(), then this method will return null.
Returns
The resource from which the Event was received, or null if it is a new, locally-created Event.
Example Usage
var sourceChannel = evt.getResource(); // assuming evt came from a Channel subscription
getResourceName()
Event.prototype.getResourceName = function getResourceName()
Returns the name of the resource with which the Event is associated, or null if this is a new client-created Event.
If an Event is received via a client-initiated subscription to a resource such as a Channel, Queue or TransactionalQueue then this method will return the name of the resource with which the Event is associated (e.g. “/some/channel”).
If this Event was received as a result of DataGroup membership via a DataStream-enabled Session, this method will return the name of the source DataGroup.
If an Event has been created locally with a call to Nirvana.createEvent(), then this method will return null.
Returns
A string representing the resource’s fully qualified name, or null if it is a new, locally-created Event.
Example Usage
var channelName = evt.getResourceName(); // assuming evt came from a Channel subscription
setTTL()
Event.prototype.setTTL = function setTTL( newTTL )
Sets the Event’s TTL (Time-to-live) in milliseconds. This is useful if you wish to publish an Event that will expire after a certain time.
Parameters
newTTL | the TTL for this Event, in milliseconds. |
Returns
The Event object on which Event.setTTL() was invoked (making this a chainable method).
Example Usage
evt.setTTL(60000); // expire one minute after publishing
myChannel.publish(evt);
See Also
getEID()
Event.prototype.getEID = function getEID( longFormat )
Returns the Event’s ID (the EID).
Parameters
longFormat | optional <Nirvana.LongType> |
Returns
By default a Number representing the Event’s ID (EID). If longFormat is provided as a parameter will return the selected type if the Event’s origin is from the server
Example Usage
var eid = evt.getEID(); //returns the EID as the default, a Number
evt.getEID(Nirvana.LongType.LONG_AS_ARRAY); // returns an array of the EID split into two 32 bit parts
evt.getEID(Nirvana.LongType.LONG_AS_DECIMAL_STRING); // returns the EID as decimal formated string
evt.getEID(Nirvana.LongType.LONG_AS_HEXADECIMAL_STRING); // returns the EID as a hexadecimal string
getData()
Event.prototype.getData = function getData( dataFormat )
Returns the Event’s raw data, or undefined if it has no data.
Parameters
base64Encoded | optional boolean parameter; if true, the data will be returned in base64encoded form. |
Returns
The Event’s raw data, or undefined if it has no data.
Example Usage
evt.setData("Hello World");
evt.getData(); // returns "Hello World"
evt.getData(true); // returns "SGVsbG8gV29ybGQ="
See Also
setData()
Event.prototype.setData = function setData( data, dataFormat )
Sets the Event’s raw data.
Parameters
data | the data; this is either the raw data or a base64-encoded representation of it. |
isBase64Encoded | optional boolean parameter; set this to true if the data is already base64-encoded. |
Returns
The Event object on which Event.setData() was invoked (making this a chainable method).
Example Usage
evt.setData("Hello World");
evt.getData(); // returns "Hello World"
evt.setData(Utils.base64Encode("Another Example"), true);
evt.getData(); // returns "Another Example"
See Also
setTag()
Event.prototype.setTag = function setTag( newTag )
Sets the Event’s tag.
Parameters
newTag | a string representation of the tag for the Event. |
Returns
The Event object on which Event.setTTL() was invoked (making this a chainable method).
Example Usage
evt.setTag("sometag");
See Also
getDictionary()
Event.prototype.getDictionary = function getDictionary()
Returns the Event’s EventDictionary. If the Event did not explicitly have an EventDictionary, then a new, empty EventDictionary is initialized for the Event.
Note that the object returned is a reference to the Event’s actual EventDictionary, not a copy. There is therefore no corresponding setDictionary() method.
Returns
An EventDictionary object.
Example Usage
var dict = evt.getDictionary();
dict.putString("message", "Hello World");
myChannel.publish(evt);
See Also
getEventAttributes()
Event.prototype.getEventAttributes = function getEventAttributes()
Returns the Event’s EventAttributes. If the Event did not explicitly have any EventAttributes, then a new, empty EventAttributes object is initialized for the Event.
Note that the object returned is a reference to the Event’s actual EventAttributes, not a copy. There is therefore no corresponding setEventAttributes() method.
Returns
An EventAttributes object.
Example Usage
var attribs = evt.getEventAttributes();
attribs.setPublisherName("John Doe");
myChannel.publish(evt);
See Also
hasData()
Event.prototype.hasData = function hasData()
Returns true if the Event has data, or false otherwise.
Returns
A boolean value of true or false
Example Usage
if (evt.hasData()) {
console.log(evt.getData());
}
See Also
Event.getData(), Event.setData(), <Event.getEncodedData()>, <Event.setEncodedData()>
hasTag()
Event.prototype.hasTag = function hasTag()
Returns true if the Event has a tag, or false otherwise.
Returns
A boolean value of true or false
Example Usage
if (evt.hasTag()) {
console.log(evt.getTag());
}
See Also
hasDictionary()
Event.prototype.hasDictionary = function hasDictionary()
Returns true if the Event has an EventDictionary, or false otherwise.
Returns
A boolean value of true or false
Example Usage
if (evt.hasDictionary()) {
console.log(evt.getDictionary().getKeys());
}
See Also
EventDictionary
An EventDictionary object is returned by any call to Event.getDictionary() or Nirvana.createDictionary(). All EventAttributes objects are created with these two methods; EventAttributes has no built-in public constructor method.
Example Usage
It is very common to interact with the EventDictionary of an Event that may have been received through a subscription to a resource such as a Channel or a Queue:
var dict = evt.getDictionary();
console.log(dict.get("somekey"));
It is also very common to manipulate an Event’s EventDictionary before publishing the Event to such a resource:
var dict = evt.getDictionary();
dict.putString("message", "Hello World");
nestedDict = Nirvana.createDictionary();
nestedDict.putString("nestedmessage", "Hello again");
dict.putDictionary(nestedDict);
myChannel.publish(evt);
Cross-API Data Types
Since JavaScript only supports a very basic set of data types, EventDictionaries include extra data type information for each key/value pair. This permits communication with Universal Messaging clients built with APIs in other languages that include more sophisticated data type support. A number of constants to represent these types are defined within EventDictionary (see below).
Constants | |
STRING | EventDictionary.STRING is an integer constant representing the String data type. |
LONG | EventDictionary.LONG is an integer constant representing the Long data type. |
DOUBLE | EventDictionary.DOUBLE is an integer constant representing the Double data type. |
BOOLEAN | EventDictionary.BOOLEAN is an integer constant representing the Boolean data type. |
INTEGER | EventDictionary.INTEGER is an integer constant representing the Integer data type. |
FLOAT | EventDictionary.FLOAT is an integer constant representing the Float data type. |
CHARACTER | EventDictionary.CHARACTER is an integer constant representing the Character data type. |
BYTE | EventDictionary.BYTE is an integer constant representing the Byte data type. |
DICTIONARY | EventDictionary.DICTIONARY is an integer constant representing the EventDictionary data type (useful for nested EventDictionaries). |
ARRAY | EventDictionary.ARRAY is an integer constant representing the Array data type. |
Functions | |
getKeys() | Returns an array of the keys contained in the EventDictionary. |
get() | Returns the value to which the EventDictionary maps the specified key. |
getType() | Returns the type of the value to which the EventDictionary maps the specified key. |
getArrayType() | Returns the type of the entries in the array value to which the EventDictionary maps the specified key. |
putString() | Associates the specified String value with the specified key in this EventDictionary. |
putLong() | Associates the specified String value with the specified key in this EventDictionary. |
putDouble() | Associates the specified EventDictionary.DOUBLE value with the specified key in this EventDictionary. |
putBoolean() | Associates the specified EventDictionary.BOOLEAN value with the specified key in this EventDictionary. |
putInteger() | Associates the specified EventDictionary.INTEGER value with the specified key in this EventDictionary. |
putFloat() | Associates the specified EventDictionary.FLOAT value with the specified key in this EventDictionary. |
putChar() | Associates the specified EventDictionary.CHARACTER value with the specified key in this EventDictionary. |
putByte() | Associates the specified EventDictionary.BYTE value with the specified key in this EventDictionary. |
putDictionary() | Associates the specified EventDictionary value with the specified key in this EventDictionary. |
putArray() | Associates the specified EventDictionary.ARRAY value with the specified key in this EventDictionary. |
STRING
EventDictionary.STRING is an integer constant representing the String data type.
See Also
LONG
EventDictionary.LONG is an integer constant representing the Long data type.
See Also
DOUBLE
EventDictionary.DOUBLE is an integer constant representing the Double data type.
See Also
BOOLEAN
EventDictionary.BOOLEAN is an integer constant representing the Boolean data type.
See Also
INTEGER
EventDictionary.INTEGER is an integer constant representing the Integer data type.
See Also
FLOAT
EventDictionary.FLOAT is an integer constant representing the Float data type.
See Also
CHARACTER
EventDictionary.CHARACTER is an integer constant representing the Character data type.
See Also
BYTE
EventDictionary.BYTE is an integer constant representing the Byte data type.
See Also
DICTIONARY
EventDictionary.DICTIONARY is an integer constant representing the EventDictionary data type (useful for nested EventDictionaries).
See Also
ARRAY
EventDictionary.ARRAY is an integer constant representing the Array data type.
See Also
EventDictionary.putArray(), EventDictionary.getType(), EventDictionary.getArrayType()
getKeys()
EventDictionary.prototype.getKeys = function ()
Returns an array of the keys contained in the EventDictionary.
Returns
An array of key names.
Example Usage
var evt = Nirvana.createEvent();
evt.getDictionary().getKeys(); // returns []
evt.getDictionary().putString("message", "Hello World");
evt.getDictionary().getKeys(); // returns ["message"]
See Also
get()
EventDictionary.prototype.get = function ( key, longType )
Returns the value to which the EventDictionary maps the specified key.
Parameters
key | a string representing the name of the key. |
longType | a <Nirvana.LongType> used if the type being returned is a long and from the server when more than the accuracy of Javascript Number is required |
Returns
The value to which this EventDictionary maps the specified key.
Example Usage
var evt = Nirvana.createEvent();
evt.getDictionary().putString("message", "Hello World");
evt.getDictionary().get("message"); // returns "Hello World"
A common use case is to examine the values of EventDictionary entries after receiving an Event via a subscription to a resource:
function myHandler(evt) {
console.log(evt.getDictionary().get("currencypair"));
console.log(evt.getDictionary().get("price"));
}
myChannel.addHandler(Nirvana.Observe.DATA, myHandler);
myChannel.subscribe();
See Also
EventDictionary.getKeys(), EventDictionary.getType(), EventDictionary.getArrayType() along with the various type-specific put methods, EventDictionary.get(), EventDictionary.putString(), EventDictionary.putLong(), EventDictionary.putDouble(), EventDictionary.putBoolean(), EventDictionary.putInteger(), EventDictionary.putFloat(), EventDictionary.putChar(), EventDictionary.putByte(), EventDictionary.putDictionary(), EventDictionary.putArray()
getType()
EventDictionary.prototype.getType = function ( key )
Returns the type of the value to which the EventDictionary maps the specified key.
Parameters
key | a string representing the name of the key. |
Returns
An integer constant representing the type. See EventDictionary.Constants.
Example Usage
var evt = Nirvana.createEvent();
evt.getDictionary().putString("message", "Hello World");
evt.getDictionary().getKeys(); // returns ["message"]
See Also
EventDictionary.Constants, EventDictionary.get(), EventDictionary.getArrayType()
getArrayType()
EventDictionary.prototype.getArrayType = function ( key )
Returns the type of the entries in the array value to which the EventDictionary maps the specified key.
Parameters
name | a string representing the name of the array. |
Returns
An integer constant representing the type.
Example Usage
var evt = Nirvana.createEvent();
evt.getDictionary().putArray("myArray", ["Hello","World"], EventDictionary.STRING);
evt.getDictionary().get("myArray"); // returns ["Hello","World"]
evt.getDictionary().getType("myArray") === EventDictionary.ARRAY; // true
evt.getDictionary().getArrayType("myArray") === EventDictionary.STRING; // true
See Also
EventDictionary.ARRAY, EventDictionary.get(), EventDictionary.getType(), EventDictionary.putArray(), EventDictionary.putString(), EventDictionary.putLong(), EventDictionary.putDouble(), EventDictionary.putBoolean(), EventDictionary.putInteger(), EventDictionary.putFloat(), EventDictionary.putChar(), EventDictionary.putByte(), EventDictionary.putDictionary()
putString()
EventDictionary.prototype.putString = function ( key, value )
Associates the specified String value with the specified key in this EventDictionary.
Parameters
key | a string representing the name of the key. |
value | the String value to be added. |
Returns
The EventDictionary object on which EventDictionary.putString() was invoked (making this a chainable method).
Example Usage
var evt = Nirvana.createEvent();
evt.getDictionary().putString("message", "Hello World");
evt.getDictionary().get("message"); // returns "Hello World"
See Also
EventDictionary.get(), EventDictionary.getType(), EventDictionary.getArrayType(), EventDictionary.putString(), EventDictionary.putLong(), EventDictionary.putDouble(), EventDictionary.putBoolean(), EventDictionary.putInteger(), EventDictionary.putFloat(), EventDictionary.putChar(), EventDictionary.putByte(), EventDictionary.putDictionary(), EventDictionary.putArray()
putLong()
EventDictionary.prototype.putLong = function ( key, value )
Associates the specified String value with the specified key in this EventDictionary.
Parameters
key | a string representing the name of the key. |
value | the Long value to be added. |
Returns
The EventDictionary object on which EventDictionary.putLong() was invoked (making this a chainable method).
Example Usage
var evt = Nirvana.createEvent();
evt.getDictionary().putLong("myLong", 42424242);
evt.getDictionary().get("myLong"); // returns 42424242
evt.getDictionary().getType("myLong") === EventDictionary.LONG; // true
See Also
EventDictionary.LONG, EventDictionary.get(), EventDictionary.getType(), EventDictionary.getArrayType(), EventDictionary.putString(), EventDictionary.putDouble(), EventDictionary.putBoolean(), EventDictionary.putInteger(), EventDictionary.putFloat(), EventDictionary.putChar(), EventDictionary.putByte(), EventDictionary.putDictionary(), EventDictionary.putArray()
putDouble()
EventDictionary.prototype.putDouble = function ( key, value )
Associates the specified EventDictionary.DOUBLE value with the specified key in this EventDictionary.
Parameters
key | a string representing the name of the key. |
value | the Double value to be added. |
Returns
The EventDictionary object on which EventDictionary.putDouble() was invoked (making this a chainable method).
Example Usage
var evt = Nirvana.createEvent();
evt.getDictionary().putDouble("myDouble", 42.424242);
evt.getDictionary().get("myDouble"); // returns 42.424242
evt.getDictionary().getType("myDouble") === EventDictionary.DOUBLE; // true
See Also
EventDictionary.DOUBLE, EventDictionary.get(), EventDictionary.getType(), EventDictionary.getArrayType(), EventDictionary.putString(), EventDictionary.putLong(), EventDictionary.putBoolean(), EventDictionary.putInteger(), EventDictionary.putFloat(), EventDictionary.putChar(), EventDictionary.putByte(), EventDictionary.putDictionary(), EventDictionary.putArray()
putBoolean()
EventDictionary.prototype.putBoolean = function ( key, value )
Associates the specified EventDictionary.BOOLEAN value with the specified key in this EventDictionary.
Parameters
key | a string representing the name of the key. |
value | the Boolean value to be added. |
Returns
The EventDictionary object on which EventDictionary.putBoolean() was invoked (making this a chainable method).
Example Usage
var evt = Nirvana.createEvent();
evt.getDictionary().putBoolean("myBoolean", true);
evt.getDictionary().get("myBoolean"); // returns true
evt.getDictionary().getType("myBoolean") === EventDictionary.BOOLEAN; // true
See Also
EventDictionary.BOOLEAN, EventDictionary.get(), EventDictionary.getType(), EventDictionary.getArrayType(), EventDictionary.putLong(), EventDictionary.putDouble(), EventDictionary.putInteger(), EventDictionary.putFloat(), EventDictionary.putChar(), EventDictionary.putByte(), EventDictionary.putDictionary(), EventDictionary.putArray()
putInteger()
EventDictionary.prototype.putInteger = function ( key, value )
Associates the specified EventDictionary.INTEGER value with the specified key in this EventDictionary.
Parameters
key | a string representing the name of the key. |
value | the Integer value to be added. |
Returns
The EventDictionary object on which EventDictionary.putInteger() was invoked (making this a chainable method).
Example Usage
var evt = Nirvana.createEvent();
evt.getDictionary().putInteger("myInt", 42);
evt.getDictionary().get("myInt"); // returns 42
evt.getDictionary().getType("myInt") === EventDictionary.INTEGER; // true
See Also
EventDictionary.INTEGER, EventDictionary.get(), EventDictionary.getType(), EventDictionary.getArrayType(), EventDictionary.putString(), EventDictionary.putLong(), EventDictionary.putDouble(), EventDictionary.putBoolean(), EventDictionary.putFloat(), EventDictionary.putChar(), EventDictionary.putByte(), EventDictionary.putDictionary(), EventDictionary.putArray()
putFloat()
EventDictionary.prototype.putFloat = function ( key, value )
Associates the specified EventDictionary.FLOAT value with the specified key in this EventDictionary.
Parameters
key | a string representing the name of the key. |
value | the Float value to be added. |
Returns
The EventDictionary object on which EventDictionary.putFloat() was invoked (making this a chainable method).
Example Usage
var evt = Nirvana.createEvent();
evt.getDictionary().putFloat("myFloat", 1.234);
evt.getDictionary().get("myFloat"); // returns 1.234
evt.getDictionary().getType("myFloat") === EventDictionary.FLOAT; // true
See Also
EventDictionary.FLOAT, EventDictionary.get(), EventDictionary.getType(), EventDictionary.getArrayType(), EventDictionary.putString(), EventDictionary.putLong(), EventDictionary.putDouble(), EventDictionary.putBoolean(), EventDictionary.putInteger(), EventDictionary.putChar(), EventDictionary.putByte(), EventDictionary.putDictionary(), EventDictionary.putArray()
putChar()
EventDictionary.prototype.putChar = function ( key, value )
Associates the specified EventDictionary.CHARACTER value with the specified key in this EventDictionary.
Parameters
key | a string representing the name of the key. |
value | the Character value to be added. |
Returns
The EventDictionary object on which EventDictionary.putChar() was invoked (making this a chainable method).
Example Usage
var evt = Nirvana.createEvent();
evt.getDictionary().putChar("myCharVal", "x");
evt.getDictionary().get("myCharVal"); // returns "x"
evt.getDictionary().getType("myCharVal") === EventDictionary.CHARACTER; // true
See Also
EventDictionary.CHARACTER, EventDictionary.get(), EventDictionary.getType(), EventDictionary.getArrayType(), EventDictionary.putString(), EventDictionary.putLong(), EventDictionary.putDouble(), EventDictionary.putBoolean(), EventDictionary.putInteger(), EventDictionary.putFloat(), EventDictionary.putByte(), EventDictionary.putDictionary(), EventDictionary.putArray()
putByte()
EventDictionary.prototype.putByte = function ( key, value )
Associates the specified EventDictionary.BYTE value with the specified key in this EventDictionary.
Parameters
key | a string representing the name of the key. |
value | the Byte value to be added. |
Returns
The EventDictionary object on which EventDictionary.putByte() was invoked (making this a chainable method).
Example Usage
var evt = Nirvana.createEvent();
evt.getDictionary().putByte("myByteVal", myByteValue);
evt.getDictionary().getType("myByteVal") === EventDictionary.BYTE; // true
See Also
EventDictionary.BYTE, EventDictionary.get(), EventDictionary.getType(), EventDictionary.getArrayType(), EventDictionary.putString(), EventDictionary.putLong(), EventDictionary.putDouble(), EventDictionary.putBoolean(), EventDictionary.putInteger(), EventDictionary.putFloat(), EventDictionary.putChar(), EventDictionary.putDictionary(), EventDictionary.putArray()
putDictionary()
EventDictionary.prototype.putDictionary = function ( key, value )
Associates the specified EventDictionary value with the specified key in this EventDictionary.
Parameters
key | a string representing the name of the key. |
value | the EventDictionary value to be added. |
Returns
The EventDictionary object on which EventDictionary.putDictionary() was invoked (making this a chainable method).
Example Usage
var evt = Nirvana.createEvent();
var dict = evt.getDictionary();
nestedDict = Nirvana.createDictionary();
nestedDict.putString("message", "This is in a nested EventDictionary");
dict.putDictionary("myNestedDictionary", nestedDict);
myChannel.publish(evt);
evt.getDictionary().getType("myNestedDictionary") === EventDictionary.DICTIONARY; // true
See Also
EventDictionary.DICTIONARY, EventDictionary.get(), EventDictionary.getType(), EventDictionary.getArrayType(), EventDictionary.putString(), EventDictionary.putLong(), EventDictionary.putDouble(), EventDictionary.putBoolean(), EventDictionary.putInteger(), EventDictionary.putFloat(), EventDictionary.putChar(), EventDictionary.putByte(), EventDictionary.putArray()
putArray()
EventDictionary.prototype.putArray = function ( key, value, arrType )
Associates the specified EventDictionary.ARRAY value with the specified key in this EventDictionary.
Parameters
key | a string representing the name of the key. |
value | the array of values to be added. |
arrType | the type of the values in the array (see EventDictionary.Constants). |
Returns
The EventDictionary object on which EventDictionary.putArray() was invoked (making this a chainable method).
Example Usage
var evt = Nirvana.createEvent();
evt.getDictionary().putArray("myArray", ["Hello","World"], EventDictionary.STRING);
evt.getDictionary().get("myArray"); // returns ["Hello","World"]
evt.getDictionary().getType("myArray") === EventDictionary.ARRAY; // true
evt.getDictionary().getArrayType("myArray") === EventDictionary.STRING; // true
See Also
EventDictionary.ARRAY, EventDictionary.get(), EventDictionary.getType(), EventDictionary.getArrayType(), EventDictionary.putString(), EventDictionary.putLong(), EventDictionary.putDouble(), EventDictionary.putBoolean(), EventDictionary.putInteger(), EventDictionary.putFloat(), EventDictionary.putChar(), EventDictionary.putByte(), EventDictionary.putDictionary()
EventAttributes
An EventAttributes object is returned by any call to Event.getEventAttributes(). All EventAttributes objects are created with this factory method; EventAttributes no built-in public constructor method.
Example Usage
var publisher = evt.getAttributes().getPublisherName();
Developers will typically use specific getter/setter methods (such as EventAttributes.getPublisherName()) which exist for all default attributes. Alternatively, if they know the underlying attribute key name, they may use the generic EventAttributes.getAttribute() and EventAttributes.setAttribute() methods to accomplish the same thing:
var publisher = evt.getAttributes().getAttribute("pubName");
Methods
For brevity, the many methods of EventAttributes have no extended documentation; their meanings and usage, however, should be reasonably self-explanatory.
Getters/ | |
getSubscriberHost() | Returns a string representing the subscriber host. |
getSubscriberName() | Returns a string representing the subscriber name. |
getSubscriberID() | Returns a string representing the subscriber ID. |
getPublisherHost() | Returns a string representing the publisher host. |
getPublisherName() | Returns a string representing the publisher name. |
setSubscriberHost() | Sets the subscriber host. |
setSubscriberName() | Sets the subscriber name. |
setPublisherName() | Sets the publisher name. |
setPublisherHost() | Sets the publisher host. |
Low-Level Getters/ | |
getAttribute() | Returns the value to which the EventAttributes maps the specified name. |
getAttributeNames() | Returns an array of an attribute names in this EventAttributes object. |
setAttribute() | Associates the specified value with the specified attribute name in this EventAttributes object. |
Read-Only methods accessing Immutable Server-Side Values | |
getTimeStamp() | Returns the Event’s publication timestamp as an integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC (Unix Epoch). |
getAllowMerge() | Returns true if the Event can be merged, or false otherwise. |
isDelta() | Returns true if the Event is a delta. |
isRedelivered() | Returns true if the Event is redelivered. |
isRegistered() | Returns true if the Event is a “registered event”, or false otherwise. |
Join-Specific Functions | Methods for working with Events received via Joined Channels. |
getJoinChannel() | Returns a string representing the name of the Channel from which the Event originated. |
getJoinEID() | Returns an integer representing the EID of the original Event on the joined Channel. |
getJoinPath() | Returns the names of all the Channels in the join path for the Event. |
getJoinRealm() | Returns a string representing the details of the realm on which the joined Channel exists. |
Dead-Event Functions | |
getDeadEID() | Returns the EID of the Dead Event |
getDeadEventStore() | Returns a string representing the name of the Dead Event’s dead event store (assuming it was consumed from a dead event store). |
JMS Functions | |
getApplicationID() | Returns the application ID allocated to the Event. |
getCorrelationID() | Returns the correlation ID allocated to the Event. |
getDeliveryMode() | Returns the delivery mode used for the Event. |
getDestination() | Returns the destination allocated to the Event. |
getExpiration() | Returns the expiration value allocated to the Event. |
getMessageID() | Returns the message ID allocated to the Event. |
getMessageType() | Returns an integer representing the message type of the Event. |
getPriority() | Returns an integer representing the Event priority. |
getRedeliveredCount() | Returns an integer representing the number of times the Event has been redelivered. |
getReplyToName() | Returns the “reply to” name allocated to the Event. |
getReplyType() | Returns an integer representing the reply type of the Event. |
getType() | Returns the arbitrary type of the Event. |
getUserID() | Returns the user ID given to the Event. |
setAllowMerge() | |
setApplicationID() | |
setCorrelationID() | |
setDeliveryMode() | |
setDestination() | |
setExpiration() | |
setMessageID() | |
setMessageType() | |
setPriority() | |
setReplyToName() | |
setReplyType() | |
setType() | |
setUserID() | |
setSubscriberID() |
getSubscriberHost()
EventAttributes.prototype.getSubscriberHost = function ()
Returns a string representing the subscriber host.
See Also
EventAttributes.setSubscriberHost(), EventAttributes.getPublisherHost()
getSubscriberName()
EventAttributes.prototype.getSubscriberName = function ()
Returns a string representing the subscriber name.
See Also
EventAttributes.setSubscriberName(), EventAttributes.getPublisherName()
getPublisherHost()
EventAttributes.prototype.getPublisherHost = function ()
Returns a string representing the publisher host.
See Also
EventAttributes.setPublisherHost(), EventAttributes.getSubscriberHost()
getPublisherName()
EventAttributes.prototype.getPublisherName = function ()
Returns a string representing the publisher name.
See Also
EventAttributes.setPublisherName(), EventAttributes.getSubscriberName()
setSubscriberHost()
EventAttributes.prototype.setSubscriberHost = function ( subscriberHost )
Sets the subscriber host.
Returns
The EventAttributes object on which EventAttributes.setSubscriberHost() was invoked (making this a chainable method).
See Also
EventAttributes.getSubscriberHost(), EventAttributes.setPublisherHost()
setSubscriberName()
EventAttributes.prototype.setSubscriberName = function ( subscriberName )
Sets the subscriber name.
Returns
The EventAttributes object on which EventAttributes.setSubscriberName() was invoked (making this a chainable method).
See Also
EventAttributes.getSubscriberName(), EventAttributes.setPublisherName()
setPublisherName()
EventAttributes.prototype.setPublisherName = function ( publisherName )
Sets the publisher name.
Returns
The EventAttributes object on which EventAttributes.setPublisherName() was invoked (making this a chainable method).
See Also
EventAttributes.getPublisherName(), EventAttributes.setSubscriberName()
setPublisherHost()
EventAttributes.prototype.setPublisherHost = function ( publisherHost )
Sets the publisher host.
Returns
The EventAttributes object on which EventAttributes.setPublisherHost() was invoked (making this a chainable method).
See Also
EventAttributes.getPublisherHost(), EventAttributes.setSubscriberHost()
getAttribute()
EventAttributes.prototype.getAttribute = function ( name )
Returns the value to which the EventAttributes maps the specified name.
See Also
EventAttributes.setAttribute(), EventAttributes.getAttributeNames()
getAttributeNames()
EventAttributes.prototype.getAttributeNames = function ()
Returns an array of an attribute names in this EventAttributes object.
See Also
setAttribute()
EventAttributes.prototype.setAttribute = function ( attributeName, attributeValue )
Associates the specified value with the specified attribute name in this EventAttributes object.
Parameters
attributeName | the name of the attribute. |
attributeValue | the value to be set. |
See Also
EventAttributes.getAttribute(), EventAttributes.getAttributeNames()
getTimeStamp()
EventAttributes.prototype.getTimeStamp = function ( longType )
Returns the Event’s publication timestamp as an integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC (Unix Epoch).
Parameters
longFormat | optional <Nirvana.LongType> only applicable if event origin is the server |
getAllowMerge()
EventAttributes.prototype.getAllowMerge = function ()
Returns true if the Event can be merged, or false otherwise.
isRedelivered()
EventAttributes.prototype.isRedelivered = function ()
Returns true if the Event is redelivered. Returns false otherwise.
isRegistered()
EventAttributes.prototype.isRegistered = function ()
Returns true if the Event is a “registered event”, or false otherwise.
Join-Specific Functions
Methods for working with Events received via Joined Channels.
Learn more about Channel Joins at: https://documentation.softwareag.com
getJoinEID()
EventAttributes.prototype.getJoinEID = function ( longType )
Returns an integer representing the EID of the original Event on the joined Channel.
Parameters
longFormat | optional <Nirvana.LongType> only applicable if event origin is the server |
Returns
By default a Number representing the Event’s ID from the orignial Event on the joined Channel
Example Usage
var eid = evt.getJoinEID(); //returns the EID as the default, a Number
evt.getJoinEID(Nirvana.LongType.LONG_AS_ARRAY); // returns an array of the Join EID split into two 32 bit parts
evt.getJoinEID(Nirvana.LongType.LONG_AS_DECIMAL_STRING); // returns the Join EID as decimal formated string
evt.getJoinEID(Nirvana.LongType.LONG_AS_HEXADECIMAL_STRING); // returns the Join EID as a hexadecimal string
getJoinRealm()
EventAttributes.prototype.getJoinRealm = function ()
Returns a string representing the details of the realm on which the joined Channel exists.
getDeadEID()
EventAttributes.prototype.getDeadEID = function ( longType )
Returns the EID of the Dead Event
Parameters
longType | optional <Nirvana.LongType> only applicable if event origin is the server |
Returns Returns a Number representing the EID of the Dead Event (assuming it was consumed from a dead event store). If longType is provided as a paramater will return the appropriate type, only applicable if event origin is the server
Example Usage
var eid = evt.getDeadEID(); //returns the dead event EID as the default, a Number
evt.getDeadEID(Nirvana.LongType.LONG_AS_ARRAY); // returns an array of the dead event EID split into two 32 bit parts
evt.getDeadEID(Nirvana.LongType.LONG_AS_DECIMAL_STRING); // returns the dead event EID as decimal formated string
evt.getDeadEID(Nirvana.LongType.LONG_AS_HEXADECIMAL_STRING); // returns the EID as a hexadecimal string
getDeadEventStore()
EventAttributes.prototype.getDeadEventStore = function ()
Returns a string representing the name of the Dead Event’s dead event store (assuming it was consumed from a dead event store).
getApplicationID()
EventAttributes.prototype.getApplicationID = function ()
Returns the application ID allocated to the Event.
getCorrelationID()
EventAttributes.prototype.getCorrelationID = function ()
Returns the correlation ID allocated to the Event.
getDeliveryMode()
EventAttributes.prototype.getDeliveryMode = function ()
Returns the delivery mode used for the Event.
getDestination()
EventAttributes.prototype.getDestination = function ()
Returns the destination allocated to the Event.
getExpiration()
EventAttributes.prototype.getExpiration = function ( longType )
Returns the expiration value allocated to the Event.
Parameters
longFormat | optional <Nirvana.LongType> only applicable if event origin is the server |
getMessageID()
EventAttributes.prototype.getMessageID = function ()
Returns the message ID allocated to the Event.
getMessageType()
EventAttributes.prototype.getMessageType = function ()
Returns an integer representing the message type of the Event.
getPriority()
EventAttributes.prototype.getPriority = function ()
Returns an integer representing the Event priority.
getRedeliveredCount()
EventAttributes.prototype.getRedeliveredCount = function ()
Returns an integer representing the number of times the Event has been redelivered.
getReplyToName()
EventAttributes.prototype.getReplyToName = function ()
Returns the “reply to” name allocated to the Event.
getReplyType()
EventAttributes.prototype.getReplyType = function ()
Returns an integer representing the reply type of the Event.
getType()
EventAttributes.prototype.getType = function ()
Returns the arbitrary type of the Event.
getUserID()
EventAttributes.prototype.getUserID = function ()
Returns the user ID given to the Event.
Transaction
A Transaction object is returned by any call to Channel.createTransaction(). All Transaction objects are created with this factory method; Transaction has no built-in public constructor method.
Functions | |
publishAndCommit() | |
checkCommitStatus() | |
setEvent() | |
on() | Registers a single event listener on the Transaction for observable events of the specified type (see Nirvana.Observe for applicable observables). |
removeListener() | Removes a specific listener for observable events of the specified type (see Nirvana.Observe for applicable observables). |
on()
this.on = function ( observable, listener )
Registers a single event listener on the Transaction for observable events of the specified type (see Nirvana.Observe for applicable observables).
Parameters
observable | the type of observable event in which the listener is interested. |
listener | the listener function you have implemented, which should handle the parameters associated with the relevant observable event as defined in Nirvana.Observe. |
Returns
The Transaction object on which Transaction.on() was invoked (making this a chainable method).
Example Usage
function myCommitCB(transaction, successFlag) {
if (successFlag) {
console.log("Commit was successful");
}
}
myTransaction.on(Nirvana.Observe.COMMIT, myCommitCB);
Additional Information
For more information on assigning listeners for Nirvana.Observe.DATA or any other observable event, please see the Nirvana.Observe Example Usage section.
See Also
removeListener()
this.removeListener = function ( observable, listener )
Removes a specific listener for observable events of the specified type (see Nirvana.Observe for applicable observables).
Parameters
observable | the type of observable event in which the listener was interested. |
listener | the listener function originally assigned with on(), and which should now be removed. |
Returns
The Transaction object on which Transaction.removeListener() was invoked (making this a chainable method).
Example Usage
function myCommitCB(transaction, successFlag) {
if (successFlag) {
console.log("Commit was successful");
}
}
myTransaction.on(Nirvana.Observe.COMMIT, myCommitCB);
// when we want to, we can un-assign the listener:
myTransaction.removeListener(Nirvana.Observe.COMMIT, myCommitCB);
Additional Information
For more information on removing listeners for _Nirvana.Observe.COMMIT or any other observable event, please see the Nirvana.Observe Example Usage section.
See Also
Nirvana.Utils
Nirvana.Utils provides access to a number of utility methods.
Functions | |
isLoggingEnabled() | Returns true or false, depending on the value of a debugLevel key in the configuration object passed as an optional parameter to Nirvana.createSession(). |
Logger. | Assigns a user-defined function as the default log function which is invoked as appropriate, depending on the value of a debugLevel key in the configuration object passed as an optional parameter to Nirvana.createSession(). |
Logger. | Log a message to the debug log. |
Logger. | Log an exception to the debug log. |
base64Encode() | Takes a string and returns a base64 encoded representation of it. |
base64Decode() | Takes a base64-encoded string and returns the base64 decoded value. |
isLoggingEnabled()
Returns true or false, depending on the value of a debugLevel key in the configuration object passed as an optional parameter to Nirvana.createSession().
Returns
A boolean value of true or false.
See Also
Logger.setLogger()
Assigns a user-defined function as the default log function which is invoked as appropriate, depending on the value of a debugLevel key in the configuration object passed as an optional parameter to Nirvana.createSession().
Parameters
logFunction | the user-defined log function. It should accept a string as a parameter. |
Example Usage
function myLogFunction(debugMessage) {
console.log("Log: " + debugMessage);
}
Nirvana.Utils.Logger.setLogger(myLogFunction);
Logger.log()
Log a message to the debug log. By default, this will invoke the built-in debug function (the output of which can be seen by pressing Ctrl-Alt-d, depending on the value of a debugLevel key in the configuration object passed as an optional parameter to Nirvana.createSession()).
Parameters
logMessage | the string to be logged. |
Logger.logException()
Log an exception to the debug log. By default, this will invoke the built-in debug function (the output of which can be seen by pressing Ctrl-Alt-d, depending on the value of a debugLevel key in the configuration object passed as an optional parameter to Nirvana.createSession()).
Parameters
log_exception | the exception to be logged. |
Nirvana.EventDictionary
Nirvana.EventDictionary provides the options for dictionary types
Creates and initializes (but does not start) a session object for communication with a Universal Messaging Realm Server.
function createSession( config )
Factory method to create a new, empty Universal Messaging Event (typically for subsequent publishing to a resource such as a Channel or Queue).
function createEvent()
Factory method to create a new, empty EventDictionary (typically for subsequent addition to an existing EventDictionary using EventDictionary.putDictionary()).
function createDictionary()
Associates the specified EventDictionary value with the specified key in this EventDictionary.
EventDictionary.prototype.putDictionary = function ( key, value )
Registers a single event listener on the Nirvana object for observable events of the specified type (see Nirvana.Observe for a list of applicable observables).
function on( observable, listener )
Removes a specific listener for observable events of the specified type (see Nirvana.Observe for a list of applicable observables).
function removeListener( observable, listener )
Starts the Session.
this.start = function ()
Stops the Session.
this.stop = function ( forceClose )
Batch-subscribes to multiple Channel, Queue and/or TransactionalQueue resources with a single call to the server.
this.subscribe = function ( resourceArray )
Returns the Channel object for the supplied channel name.
this.getChannel = function ( channelName )
Returns the Queue or TransactionalQueue object for the supplied queue name.
this.getQueue = function ( queueName, isTransactionalReader )
Registers a single event listener on the Session for observable events of the specified type (see Nirvana.Observe for a list of applicable observables).
this.on = function ( observable, listener )
Removes a specific listener for observable events of the specified type (see Nirvana.Observe for a list of applicable observables).
this.removeListener = function ( observable, listener )
Returns the username used in this Session.
this.getUsername = function ()
Returns the name of the Session’s current transport driver.
this.getCurrentDriver = function ()
Returns the RNAME (in protocol://host:port format) of the realm server to which the Session is currently connected.
this.getCurrentRealm = function ()
Returns the Session’s current session ID.
this.getSessionID = function ()
Returns the Session’s current DataStream ID.
this.getDataStreamID = function ()
Returns the configuration object for the Session.
this.getConfig = function ()
Returns the Session’s current status, which describes whether it is, for example, not yet started, connected, disconnected, or stopped.
this.getStatus = function ()
Returns true or false, depending on whether the Session was configured to be DataStream-enabled (via setting of the dataStreamEnabled key in the configuration object passed as an optional parameter to Nirvana.createSession().
this.isDataStreamEnabled = function ()
Subscribes to the Channel, and begins receiving events.
this.subscribe = function ()
Unsubscribes from the Channel, and stops receiving events.
this.unsubscribe = function ()
Returns true or false, depending on whether a subscription exists for the Channel.
this.isSubscribed = function ()
Publishes a Universal Messaging Event to the Channel.
this.publish = function ( event )
Factory method to create a new Transaction for use on the Channel.
this.createTransaction = function ()
Returns the Event ID (the “EID”) from which an existing subscription to the Channel started, or from which a subsequent subscription to the Channel will start.
this.getStartEID = function ()
Sets the Event ID (the “EID”) from which a subsequent subscription to the Channel shall start.
this.setStartEID = function ( eid )
Returns the Event ID (the “EID”) which an existing subscription to the Channel is at.
this.getCurrentEID = function ()
Returns the SQL-style filter applied to an existing or subsequent subscription to the Channel.
this.getFilter = function ()
Sets the SQL-style filter to be applied to a subsequent subscription to the Channel.
this.setFilter = function ( newFilter )
Returns the Channel’s fully qualified name (e.g.
this.getName = function ()
Returns the constant Nirvana.CHANNEL_RESOURCE, which identifies this resource as a Channel.
this.getResourceType = function ()
Registers a single event listener on the Channel for observable events of the specified type (see Nirvana.Observe for applicable observables).
this.on = function ( observable, listener )
Removes a specific listener for observable events of the specified type (see Nirvana.Observe for applicable observables).
this.removeListener = function ( observable, listener )
Subscribes to the Queue, and begins receiving events.
this.subscribe = function ()
Unsubscribes from the Queue, and stops receiving events.
this.unsubscribe = function ()
Returns true or false, depending on whether a subscription exists for the Queue.
this.isSubscribed = function ()
Publishes a Universal Messaging Event to the Queue.
this.publish = function ( event )
Factory method to create a new Transaction for use on the Queue.
this.createTransaction = function ()
Returns the SQL-style filter applied to an existing or subsequent subscription to the Queue.
this.getFilter = function ()
Sets the SQL-style filter to be applied to a subsequent subscription to the Queue.
this.setFilter = function ( newFilter )
Returns the Queue’s fully qualified name (e.g.
this.getName = function ()
Returns the constant Nirvana.QUEUE_RESOURCE, which identifies this resource as a Queue.
this.getResourceType = function ()
Registers a single event listener on the Queue for observable events of the specified type (see Nirvana.Observe for applicable observables).
this.on = function ( observable, listener )
Removes a specific listener for observable events of the specified type (see Nirvana.Observe for applicable observables).
this.removeListener = function ( observable, listener )
Subscribes to the TransactionalQueue, and begins receiving events.
this.subscribe = function ()
Unsubscribes from the TransactionalQueue, and stops receiving events.
this.unsubscribe = function ()
Returns true or false, depending on whether a subscription exists for the TransactionalQueue.
this.isSubscribed = function ()
Publishes a Universal Messaging Event to the TransactionalQueue.
this.publish = function ( event )
Factory method to create a new Transaction for use on the TransactionalQueue.
this.createTransaction = function ()
Commits the read of the supplied Event on the TransactionalQueue.
this.commit = function ( event )
Commits the read of all received Events on the TransactionalQueue.
this.commitAll = function ()
Performs a Roll back of the TransactionalQueue to the supplied Event.
this.rollback = function ( event )
Returns the SQL-style filter applied to an existing or subsequent subscription to the TransactionalQueue.
this.getFilter = function ()
Sets the SQL-style filter to be applied to a subsequent subscription to the TransactionalQueue.
this.setFilter = function ( newFilter )
Returns the window size for transactional reading on the TransactionalQueue.
this.getWindowSize = function ()
Sets the window size for transactional reading on the TransactionalQueue.
this.setWindowSize = function ( newWindowSize )
Returns the TransactionalQueue’s fully qualified name (e.g.
this.getName = function ()
Returns the constant Nirvana.TRANSACTIONAL_QUEUE_RESOURCE, which identifies this resource as a TransactionalQueue.
this.getResourceType = function ()
Registers a single event listener on the TransactionalQueue for observable events of the specified type (see Nirvana.Observe for applicable observables).
this.on = function ( observable, listener )
Removes a specific listener for observable events of the specified type (see Nirvana.Observe for applicable observables).
this.removeListener = function ( observable, listener )
Returns the Session with which this Event is associated, or null if this is a new client-created Event.
Event.prototype.getSession = function getSession()
Returns the resource object from which the Event was received, or null if this is a new client-created Event.
Event.prototype.getResource = function getResource()
Returns the name of the resource with which the Event is associated, or null if this is a new client-created Event.
Event.prototype.getResourceName = function getResourceName()
Returns the Event’s TTL (Time-to-live) in milliseconds.
Event.prototype.getTTL = function getTTL()
Sets the Event’s TTL (Time-to-live) in milliseconds.
Event.prototype.setTTL = function setTTL( newTTL )
Returns the Event’s ID (the EID).
Event.prototype.getEID = function getEID( longFormat )
Returns the Event’s raw data, or undefined if it has no data.
Event.prototype.getData = function getData( dataFormat )
Sets the Event’s raw data.
Event.prototype.setData = function setData( data, dataFormat )
Returns the Event’s tag, or undefined if it has no data.
Event.prototype.getTag = function getTag()
Sets the Event’s tag.
Event.prototype.setTag = function setTag( newTag )
Returns the Event’s EventDictionary.
Event.prototype.getDictionary = function getDictionary()
Returns the Event’s EventAttributes.
Event.prototype.getEventAttributes = function getEventAttributes()
Returns true if the Event has data, or false otherwise.
Event.prototype.hasData = function hasData()
Returns true if the Event has a tag, or false otherwise.
Event.prototype.hasTag = function hasTag()
Returns true if the Event has an EventDictionary, or false otherwise.
Event.prototype.hasDictionary = function hasDictionary()
Returns an array of the keys contained in the EventDictionary.
EventDictionary.prototype.getKeys = function ()
Returns the value to which the EventDictionary maps the specified key.
EventDictionary.prototype.get = function ( key, longType )
Returns the type of the value to which the EventDictionary maps the specified key.
EventDictionary.prototype.getType = function ( key )
Returns the type of the entries in the array value to which the EventDictionary maps the specified key.
EventDictionary.prototype.getArrayType = function ( key )
Associates the specified String value with the specified key in this EventDictionary.
EventDictionary.prototype.putString = function ( key, value )
Associates the specified String value with the specified key in this EventDictionary.
EventDictionary.prototype.putLong = function ( key, value )
Associates the specified EventDictionary.DOUBLE value with the specified key in this EventDictionary.
EventDictionary.prototype.putDouble = function ( key, value )
Associates the specified EventDictionary.BOOLEAN value with the specified key in this EventDictionary.
EventDictionary.prototype.putBoolean = function ( key, value )
Associates the specified EventDictionary.INTEGER value with the specified key in this EventDictionary.
EventDictionary.prototype.putInteger = function ( key, value )
Associates the specified EventDictionary.FLOAT value with the specified key in this EventDictionary.
EventDictionary.prototype.putFloat = function ( key, value )
Associates the specified EventDictionary.CHARACTER value with the specified key in this EventDictionary.
EventDictionary.prototype.putChar = function ( key, value )
Associates the specified EventDictionary.BYTE value with the specified key in this EventDictionary.
EventDictionary.prototype.putByte = function ( key, value )
Associates the specified EventDictionary.ARRAY value with the specified key in this EventDictionary.
EventDictionary.prototype.putArray = function ( key, value, arrType )
Returns a string representing the subscriber host.
EventAttributes.prototype.getSubscriberHost = function ()
Returns a string representing the subscriber name.
EventAttributes.prototype.getSubscriberName = function ()
Returns a string representing the subscriber ID.
EventAttributes.prototype.getSubscriberID = function ()
Returns a string representing the publisher host.
EventAttributes.prototype.getPublisherHost = function ()
Returns a string representing the publisher name.
EventAttributes.prototype.getPublisherName = function ()
Sets the subscriber host.
EventAttributes.prototype.setSubscriberHost = function ( subscriberHost )
Sets the subscriber name.
EventAttributes.prototype.setSubscriberName = function ( subscriberName )
Sets the publisher name.
EventAttributes.prototype.setPublisherName = function ( publisherName )
Sets the publisher host.
EventAttributes.prototype.setPublisherHost = function ( publisherHost )
Returns the value to which the EventAttributes maps the specified name.
EventAttributes.prototype.getAttribute = function ( name )
Returns an array of an attribute names in this EventAttributes object.
EventAttributes.prototype.getAttributeNames = function ()
Associates the specified value with the specified attribute name in this EventAttributes object.
EventAttributes.prototype.setAttribute = function ( attributeName, attributeValue )
Returns the Event’s publication timestamp as an integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC (Unix Epoch).
EventAttributes.prototype.getTimeStamp = function ( longType )
Returns true if the Event can be merged, or false otherwise.
EventAttributes.prototype.getAllowMerge = function ()
Returns true if the Event is a delta.
EventAttributes.prototype.isDelta = function ()
Returns true if the Event is redelivered.
EventAttributes.prototype.isRedelivered = function ()
Returns true if the Event is a “registered event”, or false otherwise.
EventAttributes.prototype.isRegistered = function ()
Returns a string representing the name of the Channel from which the Event originated.
EventAttributes.prototype.getJoinChannel = function ()
Returns an integer representing the EID of the original Event on the joined Channel.
EventAttributes.prototype.getJoinEID = function ( longType )
Returns the names of all the Channels in the join path for the Event.
EventAttributes.prototype.getJoinPath = function ()
Returns a string representing the details of the realm on which the joined Channel exists.
EventAttributes.prototype.getJoinRealm = function ()
Returns the EID of the Dead Event
EventAttributes.prototype.getDeadEID = function ( longType )
Returns a string representing the name of the Dead Event’s dead event store (assuming it was consumed from a dead event store).
EventAttributes.prototype.getDeadEventStore = function ()
Returns the application ID allocated to the Event.
EventAttributes.prototype.getApplicationID = function ()
Returns the correlation ID allocated to the Event.
EventAttributes.prototype.getCorrelationID = function ()
Returns the delivery mode used for the Event.
EventAttributes.prototype.getDeliveryMode = function ()
Returns the destination allocated to the Event.
EventAttributes.prototype.getDestination = function ()
Returns the expiration value allocated to the Event.
EventAttributes.prototype.getExpiration = function ( longType )
Returns the message ID allocated to the Event.
EventAttributes.prototype.getMessageID = function ()
Returns an integer representing the message type of the Event.
EventAttributes.prototype.getMessageType = function ()
Returns an integer representing the Event priority.
EventAttributes.prototype.getPriority = function ()
Returns an integer representing the number of times the Event has been redelivered.
EventAttributes.prototype.getRedeliveredCount = function ()
Returns the “reply to” name allocated to the Event.
EventAttributes.prototype.getReplyToName = function ()
Returns an integer representing the reply type of the Event.
EventAttributes.prototype.getReplyType = function ()
Returns the arbitrary type of the Event.
EventAttributes.prototype.getType = function ()
Returns the user ID given to the Event.
EventAttributes.prototype.getUserID = function ()
EventAttributes.prototype.setAllowMerge = function ( mergeValue )
EventAttributes.prototype.setApplicationID = function ( applicationID )
EventAttributes.prototype.setCorrelationID = function ( correlationID )
EventAttributes.prototype.setDeliveryMode = function ( deliveryMode )
EventAttributes.prototype.setDestination = function ( destination )
EventAttributes.prototype.setExpiration = function ( expiration )
EventAttributes.prototype.setMessageID = function ( messageID )
EventAttributes.prototype.setMessageType = function ( messageType )
EventAttributes.prototype.setPriority = function ( priority )
EventAttributes.prototype.setReplyToName = function ( replyToName )
EventAttributes.prototype.setReplyType = function ( replyType )
EventAttributes.prototype.setType = function ( type )
EventAttributes.prototype.setUserID = function ( userID )
EventAttributes.prototype.setSubscriberID = function ( subscriberID )
this.publishAndCommit = function ()
this.checkCommitStatus = function ( queryServer )
this.setEvent = function ( newEvent )
Registers a single event listener on the Transaction for observable events of the specified type (see Nirvana.Observe for applicable observables).
this.on = function ( observable, listener )
Removes a specific listener for observable events of the specified type (see Nirvana.Observe for applicable observables).
this.removeListener = function ( observable, listener )