new PollingManager(optsopt, adapter)
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
opts |
Object |
<optional> |
General settings for PollingManager |
adapter |
Adapter | Adapter for which this is a plugin |
Members
(static) constants
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
constants |
Object |
adapter :Adapter
- Source:
The adapter instance
Type:
pollSlot :Number
- Source:
The specific poll slot id/index for this
Type:
- Number
pollSlots :Number
- Source:
The number of total poll slots available
Type:
- Number
pollWindow :Number
- Source:
The duration of the total poll window
Type:
- Number
Methods
calculatePollSlot(min, max, addressMAC) → {Number}
- Source:
Determines the pollSlot for this controller using a computation involving its MAC address
Parameters:
| Name | Type | Description |
|---|---|---|
min |
Number | The lowest pollSlot that can be assigned to this controller. Inclusive |
max |
Number | The largest pollSlot that can be assigned to this controller. Inclusive. |
addressMAC |
String | The MAC address for this controller |
Returns:
The pollSlot: an integer betwen [0, n]
- Type
- Number
checkDeviceNodeState(device) → {String|null}
- Source:
Determines the device's node state, if available
Parameters:
| Name | Type | Description |
|---|---|---|
device |
Device |
Returns:
- Type
- String | null
checkPollSlot(currentTimeMsec, slotDurationMsec, pollWindowMsec) → {Number}
- Source:
Determines the designated slotId for this pollSlot
Parameters:
| Name | Type | Description |
|---|---|---|
currentTimeMsec |
Number | The time current as of the beginning of this pollSlot |
slotDurationMsec |
Number | Duration of a pollSlot (msec) |
pollWindowMsec |
Number | Duration of the pollWindow (msec) |
Returns:
Returns a slotId in the range [0, pollSlots) (upper exclusive). In total, there are (pollSlots + 1) possible slots to account for the ad-hoc slot.
- Type
- Number
checkTrackerForPollItem(device, pollItem, pollTrackeropt) → {Number}
- Source:
Determines how many pollWindows are remaining until this pollItem should be polled/command issued for
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
device |
Device | The device to poll |
|
pollItem |
Object | The command and information associated with the item to be polled |
|
pollTracker |
Map |
<optional> |
The poll tracker for this device |
Returns:
Returns the number of polls remaining
- Type
- Number
clearPollTrackerForDevice(devicePath)
- Source:
Nulls out poll tracker map for a particular device
Parameters:
| Name | Type | Description |
|---|---|---|
devicePath |
String | The path to the node of the device to poll |
createTimer(onSlotHandler, pollWindowMsec, numSlots) → {Tuple.<Object, Number>}
- Source:
Sets up the main polling timer
Parameters:
| Name | Type | Description |
|---|---|---|
onSlotHandler |
function | Handler to be called once per tick |
pollWindowMsec |
Number | Duration for all controllers' poll operations (msec) |
numSlots |
Number | Total number of slots in the pollWindow |
Returns:
Returns reference to an array containing (i) the object which stores the tick tracker/metronome and (ii) the time when polling started
- Type
- Tuple.<Object, Number>
decrementNumPollsRemaining(pollIntervalMsec, pollWindowMsec, currentNumPollsRemaining) → {Number}
- Source:
Correctly decrements polls remaining count while accounting for "hourglass"/count refill
Parameters:
| Name | Type | Description |
|---|---|---|
pollIntervalMsec |
Number | |
pollWindowMsec |
Number | |
currentNumPollsRemaining |
Number |
Returns:
Number of pollWindows remaining after decrementing
- Type
- Number
getValidatedPollSlotDuration(pollWindowMsec, numSlots) → {Number}
- Source:
Returns the correct duration for each allotted pollSlot within the pollWindow or fails.
Parameters:
| Name | Type | Description |
|---|---|---|
pollWindowMsec |
Number | Duration for all controllers' poll operations (msec) |
numSlots |
Number | Total number of slots in the pollWindow |
Throws:
Returns:
The allotted duration for a controller pollSlot (msec)
- Type
- Number
init() → {Promise}
- Source:
This method should be named as 'init' because Adapter instance calls the 'init' methods (if they exist) for all Adapter plugins
Returns:
- Type
- Promise
(async) issuePollCommand(device, pollItem) → {Promise}
- Source:
Actually send a single command for a poll item
Parameters:
| Name | Type | Description |
|---|---|---|
device |
Device | The device to poll |
pollItem |
Object | The poll item content |
Returns:
Resolves when command is passed to bridge for transport
- Type
- Promise
obtainPollingManagerPropOverrideForVal(argName, device, pollItem) → {any}
- Source:
Determine, if available, the K4Model property override value for a poll item
Parameters:
| Name | Type | Description |
|---|---|---|
argName |
String | Name of the argument belonging to a node monitoring parameter |
device |
Device | The device whose nodeState is monitored |
pollItem |
Object | The settings for monitoring |
Returns:
The appropriate value the argument should be set to
- Type
- any
obtainPollIntervalForItem(pollItem, device) → {Number}
- Source:
Get the appropriate poll interval for an item, factoring in K4 Model property overrides
Parameters:
| Name | Type | Description |
|---|---|---|
pollItem |
Object | Information and settings for polled item |
device |
Device | The device to poll |
Returns:
The appropriate poll interval (msec)
- Type
- Number
obtainPollMappingFieldValue(fieldName, defaultFieldValue, device, pollItem) → {String|Boolean|Number|null}
- Source:
Determine the value to set for a specific command argument, giving primacy to K4Model property overrides
Parameters:
| Name | Type | Description |
|---|---|---|
fieldName |
String | Name of the field |
defaultFieldValue |
any | The hard-coded fallback value for the field |
device |
Device | The device to poll |
pollItem |
Object | The poll item itself |
Returns:
The appropriate value to set for this argument
- Type
- String | Boolean | Number | null
onPollSlot(slotDurationMsec, pollWindowMsec)
- Source:
Orchestrates everything that happens within a pollSlot
Parameters:
| Name | Type | Description |
|---|---|---|
slotDurationMsec |
Number | Duration of a pollSlot (msec) |
pollWindowMsec |
Number | Duration of the pollWindow (msec) |
(async) poll(scheduledPollTime) → {Promise.<Tuple.<Number, Boolean, Array.<Object>, Number>>}
- Source:
Carries out the actual polling procedure. Still allows poll bleed into other controllers' poll slots (by design).
Parameters:
| Name | Type | Description |
|---|---|---|
scheduledPollTime |
Number | The RTC time for beginning of this poll (msec) |
Returns:
Resolves with the poll starting time, Boolean if poll was called or not, a list of items that were polled on this run, and the poll ending time
- Type
- Promise.<Tuple.<Number, Boolean, Array.<Object>, Number>>
(async) processAdHocTasks(scheduledStartTime, slotDurationMsec, taskQueue) → {Promise.<Object>}
- Source:
Manages the tasks designated for execution in the ad hoc slot
Parameters:
| Name | Type | Description |
|---|---|---|
scheduledStartTime |
Number | The scheduled beginning time of the ad hoc slot |
slotDurationMsec |
Number | Duration of a pollSlot (msec) |
taskQueue |
PromiseQueue | The running queue of tasks to be executed in the ad hoc slot |
Returns:
Resolves with the ending time of the ad hoc processing routine
- Type
- Promise.<Object>
prunePollTrackerForDevice(device)
- Source:
If the device has removed poll items from its mapping, make sure to not actually track, nor by extension, poll for them
Parameters:
| Name | Type | Description |
|---|---|---|
device |
Device |
registerAdHocTask(task, context, argsArray) → {Promise}
- Source:
Enqueues a consumer to register a task for later execution during the designated ad hoc pollSlot
Parameters:
| Name | Type | Description |
|---|---|---|
task |
function | A synchronous or asynchronous task to run |
context |
Object | The context |
argsArray |
Array | Arguments to call the specified task with |
Returns:
Resolves once the registered task has been completed
- Type
- Promise
setupPollTrackerForDevice(device, pollWindowMsec)
- Source:
Initializes poll interval "hourglass" trackers for each polled item on a device
Parameters:
| Name | Type | Description |
|---|---|---|
device |
Device | The device to poll |
pollWindowMsec |
Number | The duration of the pollWindow (msec)s |
updateTrackerForPollItem(device, pollWindowMsec, pollItem) → {Number}
- Source:
Should decrement the number of polls until each item should be re-polled in an hourglass fashion. Will roll over and reset to interval once the counter reaches zero. If the pollItem does not exist, then simply add it to the tracker map.
Parameters:
| Name | Type | Description |
|---|---|---|
device |
Device | The device to poll |
pollWindowMsec |
Number | The pollWindow (msec) |
pollItem |
Object | The command and information associated with the item to be polled |
Returns:
Returns the number of polls remaining prior to decrement
- Type
- Number