Module library

Index:

Functions:

module-delete

module-delete

Synopsis
Deletes a snapshot of the current module.
Usage
(module-delete snapshot_pattern)
Returns
result
Where
  • snapshot_pattern is string: a pattern to specify the snapshots to delete. That pattern may contain the symbol * as a wildcard.
  • result is string: a text indicating that the current module has been initialized.
Description
Deletes the snapshots of the current module whose name matches the specified pattern.
Examples
(module-delete "backup*")
"Snapshots deleted."
module-init

module-init

Synopsis
Initializes the current module.
Usage
(module-init)
Returns
result
Where
  • result is string
Description
Stops the current module and removes all data contained in global scope.
Examples
(module-init)
"Module sample initialized."
module-load

module-load

Synopsis
Loads a snapshot of the current module.
Usage
(module-load snapshot_name)
Returns
result
Where
  • snapshot_name is string[0..1]: the name of the snapshot to load. When omitted, the default snapshot ('head') is loaded.
  • result is string: a text indicating that the specified snapshot has been loaded.
Description
Loads the specified snapshot from persistent store into the memory of the current module. This operation do not stops the running executors and may cause unpredictible results. Stopping executors before loading a snapshot is always recommended.
Examples
(module-load)
"Module sample loaded."
(module-load "backup3")
"Module sample loaded."
Related functions
module-monitor

module-monitor

Synopsis
Monitors a exterior function.
Usage
(module-monitor
  server_url
  module_name
  function_name
  listener
  "polling-interval" => polling_interval
  "access-key" => access_key
)
Returns
result
Where
  • server_url is string: The server url.
  • module_name is string: The module name.
  • function_name is string: The name of the exterior function to monitor.
  • listener is function: The listener function that will be called when the value returned by the exterior function changes. This listerer takes 3 parameters: (function_name value server_time).
  • polling_interval is number[0..1]: The polling interval in milliseconds.
  • access_key is string[0..1]: The access key that will be sent to the server.
  • result is string: "registered" when the listener is added, "unregistered" when it is removed, or null otherwise.
Description
When a listener is specified, this function monitors the specified exterior function from the given server and module. Whenever that exterior function returns a new value, the listener is called passing as arguments the name of the exterior function, the value it returned and the server time in milliseconds when this value was sent. Each listener runs in a different executor.
If the provided listener is null, the previous registered listener is removed.
See the REST API documentation for more information about monitoring exterior functions.
Examples
(module-monitor
  "http://localhost:9999"
  "test"
  "@temperature"
  (function (fn temp server_time)
    (set temperature temp)
  )
)
"registered"
(module-monitor
  "http://localhost:9999"
  "test"
  "@temperature"
  null
)
"unregistered"
Related functions
module-name

module-name

Synopsis
Gets the name of the current module.
Usage
(module-name)
Returns
name
Where
  • name is string: the name of the current module.
Description
This function returns the name of the current module.
Examples
(module-name)
"energy_manager"
module-notify

module-notify

Synopsis
Notifies that the value returned by a exterior function has changed.
Usage
(module-notify function_name ... function_name)
Returns
listeners
Where
  • function_name is string[1..N]: the name of the exterior function that has changed.
  • listeners is number: the number of listeners that were monitoring the specified exterior functions.
Description
This function notifies all the listeners that were monitoring the value returned by the given exterior functions. These listeners are called in no special order.
A listener is registered with the module-monitor function.
Examples
(module-notify "@door_state")
3
(module-notify "@display" "@temperature")
0
Related functions
module-save

module-save

Synopsis
Saves a snapshot of the current module.
Usage
(module-save snapshot_name backup)
Returns
result
Where
  • snapshot_name is string[0..1]: the name of the snapshot that is going to be saved. When omitted, the default snapshot name ('head') is used.
  • backup is boolean[0..1]: when true, a copy of the specified snapshot is made before it is overwritten. The name of that copy is snapshot_name followed by the current date and time. By default, backup is false.
  • result is string: a text indicating that the module has been saved.
Description
Saves all data of the current module into persistent storage with the name snapshot_name. This function do not stops running executors and may produce an inconsistent snapshot image. Stopping executors before saving a module is always recommended.
Examples
(module-save)
"Module sample saved."
(module-save "backup3")
"Module sample saved."
Related functions
module-snapshots

module-snapshots

Synopsis
List all snapshots of the current module.
Usage
(module-snapshots snapshot_pattern)
Returns
(snapshot ... snapshot)
Where
  • snapshot_pattern is string[0..1]: a pattern to filter the snapshots by name. That pattern may contain the symbol * as a wildcard.
  • snapshot is (
      "name" => name
      "last-modified" => last_modified
      "length" => length
    )
    [0..N]: a module snapshot representation.
  • name is string: the name of the snapshot.
  • last_modified is number: the snapshot modification date/time expressed as the number of milliseconds elapsed since january 1st 1970 00:00h.
  • length is number: the size of the snapshot in bytes.
Description
Returns a list of the snapshots of the current module whose name matches the specified snapshot_pattern.
Examples
(module-snapshots "b*")
(
  (
    "name" => "backup1"
    "last-modified" => 1504118861000
    "length" => 4235
  )
  (
    "name" => "backup2"
    "last-modified" => 1504118876000
    "length" => 4604
  )
)
module-start

module-start

Synopsis
Starts the current module.
Usage
(module-start)
Returns
result
Where
  • result is string: a text indicating that the current module has been started.
Description
Starts the current module. When starting a module, the code contained in the start variable is executed. That code can initialize variables, listeners or hardware resources and also may spawn executors to perform repetivite tasks.
Examples
(module-start)
"Module facility started."
module-stop

module-stop

Synopsis
Stops the current module.
Usage
(module-stop)
Returns
result
Where
  • result is string: a text indicating that the current module has been stopped.
Description
Stops the current module. When stopping a module, the code contained in the stop variable is executed. That code may release resources and force the termination of the running executors. After the execution of stop, all remaining executors are killed.
Examples
(module-stop)
"Module facility stopped."
Top