Nirvana JavaScript : Creating a Session

To interact with a Nirvana Server, the first thing to do is create a Nirvana Session (nSession) object, which is effectively your logical and physical connection to a Nirvana Realm.

Creating a Nirvana Session Object

The JavaScript nSession constructor function takes five parameters:

  • RNAME : the URL for your Nirvana Realm Server
  • sessionName : An arbitrary string which should ideally be unique to this session. This is to help you monitor sessions using the Enterprise Manager GUI.
  • username : The current user's username. This allows you to link sessions to already authenticated users, irrespective of what authentication technology you are using.
  • cbPrefix : a prefix for two function names which are automatically called if the session is disconnected or reconnected. A value of "connectionCB" means you should implement two functions: connectionCBDisconnected() and connectionDBReconnected(); these will automatically be invoked by the API if appropriate.
  • appName : An arbitrary string which should ideally be unique to this application. Again, this is to help you monitor sessions using the Enterprise Manager GUI.

The JavaScript code snippet below demonstrates the creation of an nSession object:

var RNAME = "https://nirvanahost:443/";
var sessionName = "Some Arbitrary Session Name";
var username = "myUserName";
var cbPrefix = "connectionCB";
var appName = "My Application Name";
var mySession = new nSession(RNAME, sessionName, username, cbPrefix, applicationName);

Initializing a Nirvana Session

Once the nSession object has been created, it must be initialized to create a connection to the server:

var sessionInitCB = "sessionInitCallbackFunc";
var sessionRejectCB = "sessionRejectCB";
mySession.init(sessionInitCB, sessionResetCB);

Note that the nSession.init() call is asynchronous; it returns immediately, allowing single-threaded JavaScript clients to continue processing.

To enable the developer to know when an nSession.init() call has completed, the init function takes two parameters:

  • sessionInitCB : the name of a developer-defined JavaScript function that will be called when the session with the server has successfully initialized
  • sessionResetCB : the name of a developer-defined JavaScript function that will be called if the server resets the session at any point
Share this page with others:
Tell Your Tweets Facebook It! Add to Delicious Reddit! Digg It! Stumble Upon Add to Your Faves Mixx it
Follow Us:
Keep up with my-Channels on Twitter Become a fan on Facebook LinkedIn Profile Recent Highlights RSS Feed