Class Index | File Index

Classes


Class baja.comm.Batch


Extends BaseBajaObj.
Batch Network Call Capturing.

A Batch object can be used to batch up a number of network calls into one network call. It's used for network efficient remote programming in BajaScript.

When specified, a batch object is typically an optional argument in a method that could make a network call.

  var b = new baja.comm.Batch();
  
  // Invoke a number of Component Actions in one network call...
  myComp.foo({batch: b});
  myComp2.foo2({batch: b});

  // Make a single network call that will invoke both Actions in one go...
  b.commit();

Defined in: comm.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Method Summary
Method Attributes Method Name and Description
<private>  
addCallback(ok, fail)
Add a Callback.
<private>  
addReq(channel, key, body, callback)
Add a BOX request message to the Batch Buffer.
 
Makes a Batch asynchronous network call.
 
Adds all messages to a frame and makes a synchronous network call.
<private> <inner>  
doCommit(async)
Performs the actual commit work for the commit and commitSync functions.
<private>  
fail(err)
Fail is called if one of the batched calls fails.
<private>  
Return a copy of the Batch's messages array.
<private>  
Return true if this Batch was committed asynchronously.
<private>  
Return true if this Batch has already been committed.
<private>  
Return true if this Batch object has no messages to send.
<private>  
ok(resp)
Ok callback made one network call has successfully completed.
Methods borrowed from class BaseBajaObj:
equals, valueOf
Class Detail
baja.comm.Batch()
Method Detail
<private> addCallback(ok, fail)
Add a Callback.

This adds a callback into the batch queue without a message to be sent. This is useful if a callback needs to be made halfway through batch processing.

Please note, this is a private method that's only recommended for use by Tridium developers!

Parameters:
{Function} ok Optional
the ok callback.
{Function} fail Optional
the fail callback.

<private> addReq(channel, key, body, callback)
Add a BOX request message to the Batch Buffer.

This method is used internally by BajaScript.

Parameters:
{String} channel
the BOX Channel name.
{String} key
the BOX key in the Channel.
{Object} body
the object that will be encoded to JSON set over the network.
{baja.comm.Callback} callback
the callback. 'ok' or 'fail' is called on this object once network operations have completed.

commit()
Makes a Batch asynchronous network call. This should always be used in preference to baja.comm.Batch#commitSync.

commitSync()
Adds all messages to a frame and makes a synchronous network call.

It's always preferable to make an asynchronous network call. Otherwise any page will appear to block. However, there are some occassions where synchronous network calls are necessary. This method can be used to make these network calls.

See:
baja.comm.Batch#commit

<private> <inner> doCommit(async)
Performs the actual commit work for the commit and commitSync functions. Checks to see if this batch's queue contains any actual BOX messages that need to be sent to the station. If not, it simply calls all the ok callbacks the queue contains. If there are messages to send, it assembles them into a baja.comm.BoxFrame and sends them up.
Parameters:
{Boolean} async
determines whether to send the frame to the station asynchronously (only applicable if there are actual messages to send).

<private> fail(err)
Fail is called if one of the batched calls fails.
Parameters:
err
the cause of the error.

<private> getMessages()
Return a copy of the Batch's messages array.
Returns:
a copy of the Batch's Messages array.

<private> {Boolean} isAsync()
Return true if this Batch was committed asynchronously.

If the batch is not committed yet, this will return true.

Returns:
{Boolean}

<private> {Boolean} isCommitted()
Return true if this Batch has already been committed.
Returns:
{Boolean}

<private> {Boolean} isEmpty()
Return true if this Batch object has no messages to send.
Returns:
{Boolean}

<private> ok(resp)
Ok callback made one network call has successfully completed.

This gets invoked when the network call has completed successfully and a response has been received.

Parameters:
{String} resp
the response text.
Throws:
Error if a failure occurs.

Documentation generated by JsDoc Toolkit 2.3.2