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.
| Constructor Attributes | Constructor Name and Description |
|---|---|
| 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.
|
|
commit()
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> |
isAsync()
Return true if this Batch was committed asynchronously.
|
| <private> |
Return true if this Batch has already been committed.
|
| <private> |
isEmpty()
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
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!
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.
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.
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).
- Parameters:
- err
- the cause of the error.
- Returns:
- a copy of the Batch's Messages array.
If the batch is not committed yet, this will return true.
- Returns:
- {Boolean}
- Returns:
- {Boolean}
- Returns:
- {Boolean}
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.