System Host Object

1.0 Introduction

A 'system' hosted global object provides a set of system specific utility functions. No explicit instantiation is necessary.

1.1 Example

system.include("concatscript.js");
function add(first, last) {
print(system.localhostname);
//waits for 1 second
system.wait(1000);
// concat is a function in the included concatscript.js javascript
return concat(first,last);
}

2.0 System Object

2.1 System Object Interface

{
    function void include(string[] scriptPath);
    function void wait([optional int time]);
    readonly property string localhostname;
    function uuid setInterval(String javascriptCode/Function javascriptFunctionName, timeInterval, [optional] Array parameters, [optional] Date startTime, [optional] Date endtime);
    function void clearInterval(String uuid);

}

2.2 API Documentation 

Member Description Supported in version
void include(string scriptPath*); Imports the external scripts given as the arguments. Paths of the scripts to be imported can be given using a comma separated list as arguments. Imported script files need to be placed in the service.resources directory of the mashup service. If the path represents a file it should be given relative to the service.resources directory. If a file is not found at this location, the path is treated as an URL. The URL can be given relative to the services context root (eg: http://127.0.0.1:7762/services) or it can also be an absolute URL to a JavaScript file.
    system.include("include.js"); 
    system.include("version?stub&lang=e4x", "lib2.js");
    system.include("http://tempuri.org/js/temp.js");
0.1
void wait([optional int time]) Waits for the execution of the script for the given time in milliseconds or waits for 10 milliseconds when the time is not given.
    system.wait();
    system.wait(1000);
0.1
readonly property string localhostname; Gets the string defining the hostname of the system.  
    var hostname = system.localhostname;
0.1
uuid setInterval
(
String javascriptCode/Function javascriptFunctionName,
timeInterval,
[optional] Array parameters,
[optional] Date startTime,
[optional] Date endtime
);
This function allows the scheduling of a JavaScript function or a String of Javascript code periodically. There are 2 mandatory parameters.
  1. A javascript function (or a javascript expression) and
  2. the time interval between two consecutive executions.

Optionally one can specify a start time, indicating when to begin the function execution (after given number of milliseconds in the frequency parameter by default). It is also possible to give a start time and an end time.

The function returns a String UUID, which can be used to refer to this function scheduling instance.
     var id = system.setInterval('myJavaScriptFunction("I am a parameter value");', 2000);

For a demonstration of this feature, please refer the TomatoTube sample in your WSO2 Mashup Server distribution.
0.2
function void clearInterval(uuid); Removes a JavaScript function scheduled for periodic execution using the job uuid.
     system.clearInterval(uuid);
0.2

3.0 References

© WSO2 Inc.