public interface AQSystem
An instance of this interface is available to aquascripts via aqua.system alias.
Modifier and Type | Method and Description |
---|---|
void |
forceGC()
Force garbage collection.
|
long |
getCurrentTime()
Returns current time in milliseconds as reported by
System.currentTimeMillis() . |
java.lang.String |
getenv(java.lang.String name)
Gets the value of the specified environment variable.
|
long |
getMaxMemory()
Returns the maximum amount of memory (in bytes) which may be requested by the virtual machine from the OS.
|
java.lang.String |
getProperty(java.lang.String key)
Gets the system property indicated by the specified key.
|
java.lang.String |
getProperty(java.lang.String key,
java.lang.String def)
Gets the system property indicated by the specified key.
|
long |
getTotalMemory()
Returns the amount of memory (in bytes) currently allocated by the virtual machine.
|
long |
getUsedMemory()
Returns the amount of memory (in bytes) currently in use by the virtual machine.
|
boolean |
isLowMemory()
Returns true if the memory is almost full.
|
byte[] |
newByteArray(int length)
Creates an empty byte array.
|
java.lang.Process |
runCommand(java.lang.String commandLine)
Executes an external process.
|
java.lang.Process |
runCommand(java.lang.String[] cmdArray)
Executes an external process.
|
java.lang.Process |
runCommand(java.lang.String[] cmdArray,
java.lang.String folder)
Executes an external process in the specified folder.
|
java.lang.Process |
runCommand(java.lang.String commandLine,
java.lang.String folder)
Executes an external process in the specified folder.
|
java.lang.Object |
runScript(java.lang.String path)
Execute another script.
|
java.lang.Object |
runScript(java.lang.String path,
java.lang.Object args)
Execute another script with additional parameter.
|
java.lang.Object |
runScript(java.lang.String path,
java.lang.Object argument,
boolean shareContext)
Executes another script with an additional parameter and enables a shared global context.
|
java.lang.Process runCommand(java.lang.String commandLine) throws java.lang.Exception
This method is analogous to Runtime.exec(String)
call. A script may call Process.waitFor()
method on the returned value to wait for the process to finish.
commandLine
- Command line.java.lang.Exception
- on errorjava.lang.Process runCommand(java.lang.String commandLine, java.lang.String folder) throws java.lang.Exception
This method is analogous to Runtime.exec(String, String[], java.io.File)
call.
A script may call Process.waitFor()
method on the returned value to wait for the process to finish.
commandLine
- Command line.folder
- Directory to start the process in.java.lang.Exception
- on errorjava.lang.Process runCommand(java.lang.String[] cmdArray) throws java.lang.Exception
This method is analogous to Runtime.exec(String[])
call. A script may call Process.waitFor()
method on the returned value to wait for the process to finish.
cmdArray
- array containing the command to call and its arguments.java.lang.Exception
- on errorjava.lang.Process runCommand(java.lang.String[] cmdArray, java.lang.String folder) throws java.lang.Exception
This method is analogous to Runtime.exec(String[], String[], java.io.File)
call.
A script may call Process.waitFor()
method on the returned value to wait for the process to finish.
cmdArray
- array containing the command to call and its arguments.folder
- Directory to start the process in.java.lang.Exception
- on errorjava.lang.Object runScript(java.lang.String path) throws java.lang.Exception
The new script inherits the instance of aqua object but runs in a separate global scope.
path
- Local path to the script in the project's AquaScripts folder.java.lang.Exception
- on errorjava.lang.Object runScript(java.lang.String path, java.lang.Object args) throws java.lang.Exception
Note: In case of child script uses the argument variable, the child script can only be executed from the parent script unless you handle the undefined errors.
Example:
// Parent Script: //creates an AquaScript object with an attribute title and a function greet var greeting = { title : "Hello", greet : function (name) { return this.title + " " + name; } }; // executes script with argument greeting object aqua.system.runScript("script.xjs", greeting); // Script Being Called (script.xjs): // A variable with the name 'argument' contains an object passed from the parent script var name = "aqua data user"; // invoking greet method defined in greeting object of the parent script. print(argument.greet(name));The new script shares the instance of aqua object but gets its own global context. This means, among other things, that variables and functions will not be shared.
path
- Local path to the script in the project's AquaScripts folder.args
- Script arguments.java.lang.Exception
- on errorjava.lang.Object runScript(java.lang.String path, java.lang.Object argument, boolean shareContext) throws java.lang.Exception
runScript(String, Object)
, this method allows for global context sharing among parent and child scripts.
Once the global shared context is set to true, the parent and child scripts can use each others variables and functions.
Note: In case of child script using parent script's function or variables, the child script can be only be executed from the parent script unless you handle the undefined errors.
Example:
// Parent Script: //defines a simple function toUpperCase to convert any string to upper case. function toUpperCase(str) { return (str) ? str.toUpperCase() : ""; } // executes script with sharedContext set to true aqua.system.runScript("script.xjs", null, true); // invoking greet method defined in script.xjs. print(greet("Hello", "aqua data user")); // Script Being Called (script.xjs): function greet(greeting, name) { // invoking toUpperCase method defined in parent script. return greeting + " " + toUpperCase(name); }
path
- Local path to the script in the project's AquaScripts folder.argument
- Script arguments.shareContext
- Determines whether to share the parent global context or create a separate one.java.lang.Exception
- on errorboolean isLowMemory()
void forceGC()
System.gc()
, this method actually tries to collect in
the calling thread.long getCurrentTime()
System.currentTimeMillis()
.long getUsedMemory()
long getTotalMemory()
long getMaxMemory()
java.lang.String getProperty(java.lang.String key)
System.getProperty(String)
.key
- the name of the system property.null
if there is no property with that key.java.lang.String getProperty(java.lang.String key, java.lang.String def)
System.getProperty(String, String)
.key
- the name of the system property.def
- a default value.java.lang.String getenv(java.lang.String name)
System.getenv(String)
.name
- the name of the environment variablenull
if the variable is not defined in the system environmentbyte[] newByteArray(int length)
length
- Array length.
Copyright © 2019 AquaFold, Inc. All Rights Reserved. Use is subject to license terms.