System Host Object

1.0 Introduction

The 'system' host object provides a set of system specific utility functions. The system object is global and thus does not need to be instantiated explicitly.

1.1 Example

                system.include("concatscript.js");
                function add(first, last) {
                    system.log(system.localHostName);
                    //waits for 1 second
                    system.wait(1000);
                    // concat is a function in the included concatscript.js javascript
                    var answer = concat(first,last);
                    // Send a notification to the Desk tray specifying the answer
                    system.notifyMonitor("Result of concaternating" + first + " and " + last + ", " + answer);
                    return answer;
                }

                // Here is the contents of the "concatscript.js" file which was included above. It should have been placed in the ".resources" folder of this mashup.
                concat.visible=false; // Note that I have set the "visible" annotation to false. If it was not set the concat function would appear in the service as well.
                function concat(first,last){
                    return 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 String setInterval(String javascriptCode/Function javascriptFunctionName, timeInterval, [optional]Array parameters, [optional] Date startTime, [optional] Date endtime, [optional] String taskName);
                    function void clearInterval(String uuid);
                    function String setTimeout (String javascriptCode/Function javascriptFunctionName, Number startInMilliSeconds, [optional]String taskName);
                    function void clearTimeout(String uuid);
                    function boolean isTaskActive(String taskName);
                    function void notifyMonitor( string message, [optional] string title, [optional] int severity);
                    function XML getXML(String url);
                    function void log(String logmessage, [Optional]String logLevel);
                    readonly property string wwwURL;
                }
            

2.2 API Documentation

Member Description Supported in version
function 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:9763/services) or it can also be an absolute URL to a JavaScript file.

system.include("include.js");

system.include("system/version?stub&lang=e4x", "lib2.js");

system.include("http://tempuri.org/js/temp.js");

0.1
function 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
function String setInterval (

String javascriptCode/Function javascriptFunctionName,

timeInterval,

[optional] Array parameters,

[optional] Date startTime,

[optional] Date endtime,

[optional] String taskName

);
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("parameterValue")', 2000);



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

system.clearInterval(uuid);
0.2
function String setTimeout (

String javascriptCode/Function javascriptFunctionName,

Number startInMilliSeconds,

[optional] String taskName

);
setTimeout() allows you to specify that a piece of JavaScript code (called an expression) will be run a specified number of milliseconds from when the setTimeout() method was called. setTimeout() also returns a numeric timeout ID that can be used to track the timeout. This is most commonly used with the clearTimeout() method.

var id = system.setTimeout('myJavaScriptFunction("parameterValue")', 2000);
1.5
function void clearTimeout(String uuid); Sometimes it's useful to be able to cancel a timer before it goes off. The clearTimeout() method lets us do exactly that.

system. clearTimeout ( id );

where timeoutId is the ID of the timeout as returned from the setTimeout() method call.
1.5
function boolean isTaskActive(String taskName); Sometimes it's useful to be able to get the task status as it might have been deleted from the UI. User can check whether the task is active and re-schedule it with the help of this.

system.isTaskActive ( taskName );

where taskName is name of the task to be get the status.
2.0
function void notifyMonitor(

string message,

[optional] string title

[optional] int severity)

Sends the user a message via the desk tray icon of the monitor. The message string is the only mandatory parameter, with the title defaulting to 'Message' and the message severity defaulting to 'none'. The options for message severity are 0 - Informational, 1 - Error, 2 - Warning and 3 - None.

system.notifyMonitor("My Error Message", "Title", 2);
1.5

function XML getXML(String url, [[username, [password]]); Utility function to get an XML file over the network. You can optionally pass username and password for HTTP basic authentication.

system.getXML('http://wso2.org/repos/wso2/trunk/mashup/java/modules/ samples/upgradeChecker/upgradeChecker.resources/history.xml');
1.5
function object getJSON(String url, [[username, [password]]); Utility function to get a JSON file over the network. You can optionally pass username and password for HTTP basic authentication.

system.getJSON('http://wso2.org/repos/wso2/trunk/mashup/java/modules/ samples/upgradeChecker/upgradeChecker.resources/history.json');
2.2
function void log(String logmessage, [Optional] String logLevel); Allows printing to the system log from a Mashup. Where logmessage contains a string to be written to the system log and (optional) loglevel indicates the logging level as * 'info', 'warn', 'debug', 'error' or 'fatal'. The logging level defaults to 'info' when one is not provided.

system.log("Message", "error");
1.5
readonly property string wwwURL; Returns the base address of the calling mashup. Could be usefull when a user wants to return a URL to a feed that it has created. Using this function will make sure that the feed URL would not break when a mashup is shared to another Mashup Server.

Assuming the user bob has created a feed called bobsFeed.xml in a mashup called feedExample.

var bobsFeed = system.wwwURL + "/bobsFeed.xml";
1.5

3.0 References