-
Notifications
You must be signed in to change notification settings - Fork 6
scope
- $ch
- $channels
- $do
- $doAll
- $doFirst
- $doWait
- $from
- $stream
- AF.encryptText
- AF.fromYAML
- AF.toYAML
- IO.readFileYAML
- IO.writeFileYAML
- addOnOpenAFShutdown
- ansiColor
- ansiStart
- ansiStop
- beautifier
- beep
- bprint
- bprintErr
- bprintErrnl
- bprintnl
- checkLatestVersion
- clone
- cls
- colorify
- compare
- compress
- cprint
- cprintErr
- cprintErrnl
- cprintnl
- createDBInMem
- deleteFromArray
- dumpLog
- exit
- extend
- findRandomOpenPort
- flatten
- getCPULoad
- getChLog
- getDistribution
- getFromZip
- getNumberOfCores
- getOPackLocalDB
- getOPackPath
- getOPackPaths
- getOPackRemoteDB
- getOpenAFJar
- getOpenAFPath
- getPid
- getUUID
- getVersion
- inherit
- ioStreamCopy
- ioStreamRead
- ioStreamReadBytes
- ioStreamReadLines
- ioStreamWrite
- ioStreamWriteBytes
- isArray
- isDate
- isDef
- isDefined
- isFunction
- isJavaObject
- isMap
- isNumber
- isObject
- isString
- isUnDef
- isUndefined
- javaRegExp
- jsonParse
- listFilesRecursive
- load
- loadCompiledLib
- loadDBInMem
- loadDiff
- loadFuse
- loadHandlebars
- loadHelp
- loadJSYAML
- loadLib
- loadLodash
- loadUnderscore
- log
- logErr
- logWarn
- lognl
- md5
- merge
- newJavaArray
- now
- nowNano
- nowUTC
- oJobRun
- oJobRunFile
- oJobRunJob
- oPack
- oPromise
- oPromise.all
- oPromise.catch
- oPromise.race
- oPromise.then
- opackExec
- ow.loadAI
- ow.loadCh
- ow.loadDev
- ow.loadFormat
- ow.loadOJob
- ow.loadObj
- ow.loadServer
- ow.loadTemplate
- ow.loadTest
- parallel
- parallel4Array
- parallelArray
- persistDBInMem
- pidCheck
- pidCheckIn
- pidCheckOut
- pidKill
- plugin
- pods.declare
- pods.define
- pods.require
- printErr
- printErrnl
- printTable
- printnl
- processExpr
- quickSort
- repeat
- require
- restartOpenAF
- saveHelp
- saveHelpWeb
- searchArray
- searchHelp
- searchKeys
- searchValues
- setLog
- setOfflineHelp
- sh
- sha1
- sha256
- sha512
- showDebugger
- sleep
- splitArray
- splitBySeparator
- sprint
- sprintErr
- sprintErrnl
- sprintnl
- startLog
- stopLog
- stringify
- sync
- templify
- threadBox
- threadBoxCtrlC
- tlog
- tlogErr
- tlogWarn
- tlognl
- toCSV
- toEncoding
- tprint
- tprintErr
- tprintErrnl
- tprintln
- traverse
- uncompress
- utf8
- watch
- wedoDate
$ch(aChannel)
Please check more details with the help from ow.ch. The available methods are:
Channel basics:
- create(shouldCompress, aType, options)
- list()
- destroy()
- size()
- subscribe(aFunction, onlyFromNow, anId)
- unsubscribe(aId)
- forEach(aFunction)
- getAll()
- getKeys(fullInfo)
- getSortedKeys(fullInfo)
- set(aKey, aValue, aForcedTimestamp)
- setAll(keysArray, valuesArray, aForcedTimestamp)
- get(aKey)
- getSet(aMatch, aKey, aValue, aForcedTimestamp)
- unset(aKey, aForcedTimestamp)
- push(aKey, aValue)
- pop(aKey)
- shift(aKey)
- stopJobs()
- waitForJobs(aTimeout)
Channel basic persistence:
- storeAdd(aFilename, anArrayOfKeys, shouldCompress)
- storeRestore(aFilename, anArrayOfKeys)
Inter-channel HTTP REST:
- expose(aLocalPortOrServer, aPath, aAuthFunc, aUnAuthFunc)
- peer(aLocalPortOrServer, aPath, aRemoteURL, aAuthFunc, aUnAuthFunc)
- createRemote(aURL, aTimeout)
$channels(aChannel)
Please check more details with the help from ow.ch. The available methods are:
Channel basics:
- create(shouldCompress, aType, options)
- list()
- destroy()
- size()
- subscribe(aFunction, onlyFromNow, anId)
- unsubscribe(aId)
- forEach(aFunction)
- getAll(fullInfo)
- getKeys(fullInfo)
- getSortedKeys(fullInfo)
- set(aKey, aValue, aForcedTimestamp)
- setAll(keysArray, valuesArray, aForcedTimestamp)
- get(aKey)
- getSet(aMatch, aKey, aValue, aForcedTimestamp)
- unset(aKey, aForcedTimestamp)
- push(aKey, aValue)
- pop(aKey)
- shift(aKey)
- stopJobs()
- waitForJobs(aTimeout)
Channel basic persistence:
- storeAdd(aFilename, anArrayOfKeys, shouldCompress)
- storeRestore(aFilename, anArrayOfKeys)
Inter-channel HTTP REST:
- expose(aLocalPortOrServer, aPath, aAuthFunc, aUnAuthFunc)
- peer(aLocalPortOrServer, aPath, aRemoteURL, aAuthFunc, aUnAuthFunc)
- createRemote(aURL, aTimeout)
$do(aFunction, aRejFunction) : oPromise
Instantiates and returns a oPromise. If you provide aFunction, this aFunction will be executed async in a thread and oPromise object will be immediatelly returned. Optionally this aFunction can receive a resolve and reject functions for to you use inside aFunction to provide a result with resolve(aResult) or an exception with reject(aReason). If you don't call theses functions the returned value will be used for resolve or any exception thrown will be use for reject. You can use the "then" method to add more aFunction that will execute once the previous as executed successfully (in a stack fashion). The return/resolve value from the previous function will be passed as the value for the second. You can use the "catch" method to add aFunction that will receive a string or exception for any exception thrown with the reject functions. You can also provide aRejFunction to work as a "catch" method as previously described before.
$doAll(anArray) : oPromise
Returns an oPromise that will be resolved when all oPromise part of the anArray are fullfiled. If any of the oPromises fails/rejects the returned oPromise will also be rejected/fail.
$doFirst(anArray) : oPromise
Returns an oPromise that will be resolved when any oPromise part of the anArray is fullfiled. If any of the oPromises fails/rejects the returned oPromise will also be rejected/fail.
$doWait(aPromise, aWaitTimeout) : oPromise
Blocks until aPromise is fullfilled or rejected. Optionally you can specify aWaitTimeout between checks. Returns aPromise.
$from : Array
Shortcut for the JLinq library for easy query and access to arrays/objects. To see all the available options please refer to http://hugoware.net/Projects/jlinq and the list of available functions by executing, in the openaf-console: "desc $from([])".
$stream
Shortcut for the streamjs library for easy query and access to streams of data. To see all the available options please refer to https://github.com/winterbe/streamjs/blob/master/APIDOC.md.
AF.encryptText()
Interactevly asks to enter a text and then uses af.encrypt to print to stdout the result.
AF.fromYAML(aYaml) : Object
Tries to parse aYaml into a javascript map.
AF.toYAML(aJson) : String
Tries to dump aJson into a YAML string.
IO.readFileYAML(aYAMLFile) : Object
Tries to read aYAMLFile into a javascript object.
IO.writeFileYAML(aYAMLFile, aObj)
Tries to write a javascript aObj into a aYAMLFile.
addOnOpenAFShutdown(aFunction) : Boolean
Adds aFunction to try to execute whenever OpenAF is going to shutdown. The latest hook added will be the first to be executed until the first hook added (actually a shortcut for Threads.addOpenAFShutdownHook).
ansiColor(aAnsi, aString, force) : String
Returns the ANSI codes together with aString, if determined that the current terminal can handle ANSI codes (overridden by force = true), with the attributes defined in aAnsi. Please use with ansiStart() and ansiStop(). The attributes separated by commas can be:
BLACK; RED; GREEN; YELLOW; BLUE; MAGENTA; CYAN; WHITE;
FG_BLACK; FG_RED; FG_GREEN; FG_YELLOW; FG_BLUE; FG_MAGENTA; FG_CYAN; FG_WHITE;
BG_BLACK; BG_RED; BG_GREEN; BG_YELLOW; BG_BLUE; BG_MAGENTA; BG_CYAN; BG_WHITE;
BOLD; FAINT; INTENSITY_BOLD; INTENSITY_FAINT; ITALIC; UNDERLINE; BLINK_SLOW; BLINK_FAST; BLINK_OFF; NEGATIVE_ON; NEGATIVE_OFF; CONCEAL_ON; CONCEAL_OFF; UNDERLINE_DOUBLE; UNDERLINE_OFF;
ansiStart(force)
Prepares to output ansi codes if the current terminal is capable off (unless force = true). Use with ansiColor() and ansiStop().
ansiStop(force)
Disables the output of ansi codes if the current terminal is capable off (unless force = true). Use with ansiColor() and ansiStart().
beautifier(anObject) : String
Shortcut for the af.js2s function providing a human readable representation of the javascript object provided.
beep()
Tries to produce a beep sound.
bprint(aStr)
"Beautifies" and prints the aStr to the stdout (with a new line on the end) (example: bprint("hello world!"))
bprintErr(aStr)
"Beautifies" and prints the aStr to the stderr (with a new line on the end) (example: bprintErr("Hupps!! A problem!"))
bprintErrnl(aStr)
"Beautifies" and prints the aStr to the stderr (without adding a new line on the end) (example: bprintErrnl("Hupps!! A problem!"))
bprintnl(aStr)
"Beautifies" and prints the aStr to the stdout (without adding a new line on the end) (example: bprintnl("hello world!"))
checkLatestVersion() : String
Tries to determine what is the latest available version for OpenAF. Compare it with getVersion() to determine if you need an update.
clone(anObject) : aClonedObject
Creates a new copy of a JavaScript object.
cls()
Tries to clear the screen. The commands to try to clean the screen are given in ANSI.
colorify(aObject) : String
Tries to ANSI colorify a json aObject for use with cprint, cprintErr, cprintErrnl and cprintnl
compare(X, Y) : Boolean
Compares a X object to a Y object at the content level. If they are equal the function will return true otherwise it will return false.
compress(anObject) : ArrayOfBytes
Compresses a JSON object into an array of bytes suitable to be uncompressed using the uncompress function.
cprint(aStr)
"Stringifies" in ANSI color and prints the aStr to the stdout (with a new line on the end) (example: cprint("hello world!"))
cprintErr(aStr)
"Stringifies" in ANSI color and prints the aStr to the stderr (with a new line on the end) (example: cprintErr("Hupps!! A problem!"))
cprintErrnl(aStr)
"Stringifies" in ANSI color and prints the aStr to the stderr (with a new line on the end) (example: cprintErrnl("Hupps!! A problem!"))
cprintnl(aStr)
"Stringifies" in ANSI color and prints the aStr to the stdout (with a new line on the end) (example: cprintnl("hello world!"))
createDBInMem(aName, dontClose, aLogin, aPass, inMemFileSystem, inMemCompressed, useNIO) : DB
Creates a DB object instantiated with an in-memory database for the given name. Optionally you can specify that you don't want it to close on db.close (but all data will be lost on exiting OpenAF). Optionally you can also specify aLogin and aPass. This is a H2 database so do check more documentation on http://www.h2database.com/. Also optionally you can specify if you want the in-memory database to be file based (inMemFileSystem) which is slower than normal; to be compressed (inMemCompressed) which is slower than normal and inMemFileSystem; to store data outside the VM's heap (useNIO). Do note that if inMemFileSystem and inMemCompressed are selected only inMemCompressed will be used. And useNIO will only affect inMemFileSystem or inMemCompressed options.
deleteFromArray(anArray, anIndex) : Array
Deletes the array element at anIndex from the provided anArray. Returns the new array with the element removed.
dumpLog() : Array
Returns an array with collected log messages. Each entry has: d - timestamp; t - type; m - message.
exit(anExitCode)
Immediately exits execution with the provided exit code
extend([deep], target [, object1][, objectN]) : Object
Merges the contents of two or more objects together into the first object (target). If deep is specified the copy will be recursive. This function is equivalent to JQuery's extend function. See more in https://api.jquery.com/jquery.extend/
findRandomOpenPort() : number
Tries to find a random open port on all network interfaces. Useful to start network servers on an available port.
flatten(aObject, noKeyValSeparation) : Array
Given aObject it will traverse it and create an array where each element will have a key and a val(ue). The key will begin with a "." whenever it's a children key on aObject. This function is useful when trying to find specific keys or values across a Map. Optionally you can specify that you don't want each array element with the key and the value as separate elements but rather a directly as key and value.
getCPULoad(useAlternative) : Number
Tries to obtain the current system load average (equivalent to top). If not available a negative value will be returned. Optionally you can specify to use the current system load if useAlternative = true. If the current system doesn't provide a load average it will fallback to the current system load.
getChLog() : Channel
Returns the current log dump channel.
getDistribution() : String
Returns the current distribution channel for this version of OpenAF.
getFromZip(aZipFile, aResource, inBytes, anEncoding) : anArrayOfBytes
Retrieves aResource, as anArrayOfBytes, from aZipFile. This resource can be inBytes = true or not and anEncoding can be provided.
getNumberOfCores() : Number
Try to identify the current number of cores on the system where the script is being executed.
getOPackLocalDB() : Array
Returns an Array of maps. Each map element is an opack package description of the currently locally installed opack packages.
getOPackPath(aPackage) : String
Given aPackage name (a opack name) will search the opack and if installed will return the filesystem path where the opack is installed.
getOPackPaths() : Array
Returns an array of strings with the paths for each of the installed opacks.
getOPackRemoteDB() : Array
Returns an Array of maps. Each map element is an opack package description registered in the OpenAF central repository.
getOpenAFJar() : String
Returns the complete filepath and name for the OpenAF jar file. (Shortcut for af.getOpenAFJar()). If __forcedOpenAFJar is defined the corresponding value will be used (useful when detection of the OpenAF jar doesn't work as expected or when OpenAF is embedded.
getOpenAFPath() : String
Returns the filesystem path to the openaf.jar currently being used for the script execution.
getPid() : String
Tries to retrieve the current script execution operating system PID and returns it.
getUUID() : String
Generates and returns an UUID using a javascript algorithm (if needed you can refer to the AF operation AF.KeyGenerator.GenerateUUID).
getVersion() : String
Shortcut for the af.getVersion (see more af.getVersion) function. Will return the current version of OpenAF being used.
inherit(Child, Parent)
Associates a Child object to a Parent simulating a inheritance relationship. This is done by copying the Parent prototype to the Child prototype. This is similar to "Parent.call(this, arg1, arg2)"
ioStreamCopy(aOutputStream, aInputStream)
Copies the contents of a Java aInputStream to a Java aOutputStream. The two streams will be closed in the end.
ioStreamRead(aStream, aFunction, aBufferSize, useNIO)
Given a Java input or output stream helps to read strings by using aFunction with a string argument for each buffer size (default 1024 characters). Optionally you can provide a different aBufferSize (default: 1024) and/or also specify that Java NIO functionality should be used. If aFunction returns true the read operation stops.
ioStreamReadBytes(aStream, aFunction, aBufferSize, useNIO)
Given a Java input or output stream helps to read an array of bytes by using aFunction with anArrayOfBytes argument for each buffer size (default 1024 characters). Optionally you can provide a different aBufferSize (default: 1024) and/or also specify that Java NIO functionality should be used. If aFunction returns true the read operation stops.
ioStreamReadLines(aStream, aFunctionPerLine, aSeparator, useNIO)
Given aStream will read the entire buffer and call aFunctionPerLine(withALine) per each \n found. Aditionally you can specify a different aSeparator for each line other than "\n". If aFunctionPerLine returns true the read operation stops.
ioStreamWrite(aStream, aString, aBufferSize, useNIO)
Given a Java input or output stream helps to write aString into the same. Optionally you can provide a different aBufferSize (default: 1024) and/or also specify that Java NIO functionality should be used.
ioStreamWriteBytes(aStream, aArrayBytes, aBufferSize, useNIO)
Given a Java input or output stream helps to write aArrayBytes into the same. Optionally you can provide a different aBufferSize (default: 1024) and/or also specify that Java NIO functionality should be used.
isArray(aObj) : boolean
Returns true if aObj is an array, false otherwise.
isDate(aObj) : boolean
Returns true if aObj is a date, false otherwise
isDef(aObject) : boolean
Returns true if the provided aObject is defined as a javascript variable. It will return false otherwise. (see also isUnDef). Shortcut for the isDefined function.
isDefined(aObject) : boolean
Returns true if the provided aObject is defined as a javascript variable. It will return false otherwise. (see also isUndefined)
isFunction(aObj) : boolean
Returns true if aObj is a function, false otherwise;
isJavaObject(aObj) : boolean
Returns true if aObj is a Java object, false otherwise
isMap(aObj) : boolean
Returns true if aObj is a map, false otherwise.
isNumber(aObj) : boolean
Returns true if aObj is a number, false otherwise
isObject(aObj) : boolean
Returns true if aObj is an object, false otherwise;
isString(aObj) : boolean
Returns true if aObj is a string, false otherwise
isUnDef(aObject) : boolean
Returns true if the provided aObject is undefined as a javascript variable. It will return false otherwise. (see also isDef). Shortcut for the isUndefined function.
isUndefined(aObject) : boolean
Returns true if the provided aObject is undefined as a javascript variable. It will return false otherwise. (see also isDefined)
javaRegExp(text).test(regExp, mods) : boolean
Mimics, using Java, the javascript RegExp test function. Supported mods are "g", "m" and "i" or the java integer composed mods. Returns the corresponding boolean value.
jsonParse(aString) : Map
Shorcut for the native JSON.parse that returns an empty map if aString is not defined, empty or unparsable.
listFilesRecursive(aPath) : Map
Performs the io.listFiles function recursively given aPath. The returned map will be equivalent to the io.listFiles function (see more in io.listFiles).
load(aScript)
Provides a shortcut for the af.load function (see more af.load). If the provided aScript is not found this function will try to search the script on the openaf.jar::js folder and on the installed opacks. If it doesn't find the provided aScript it will throw an exception "Couldn't find aScript".
loadCompiledLib(aLibClass, forceReload, aFunction) : boolean
Loads the corresponding compiled javascript library class and keeps track if it was already loaded or not (in __loadedLibs). Optionally you can force reload and provide aFunction to execute after the successful loading. Returns true if successfull, false otherwise.
loadDBInMem(aDB, aFilename)
Tries to load to a in-memory database, aDB object, previously created by the function createDBInMem from a SQL aFilename probably created by the function persistDBInMem.
loadDiff()
Loads the JsDiff javascript library into scope (check https://github.com/kpdecker/jsdiff).
loadFuse()
Loads the FuseJS javascript library into scope.
See more in: http://fusejs.io/
loadHandlebars()
Loads the Handlebars javascript library into scope. Example:
loadHandlebards();
var source = "{{#each lines}}\t<s name="{{key}}">{{value}}\n{{/each}}\n";
var data = { "lines": [ { "name": "n1", "value": "v1" }, { "name": "n2", "value": "v2" } ] };
var template = Handlebars.compile(source);
print(template(data));
data.lines.push({"name": "n3", "value": "v3"});
print(template(data));
See more documentation in: http://handlebarsjs.com/
loadHelp()
Loads into scope the ODoc objects for documentation support.
loadJSYAML()
Loads the JS-YAML library.
loadLib(aLib, forceReload, aFunction) : boolean
Loads the corresponding javascript library and keeps track if it was already loaded or not (in __loadedLibs). Optionally you can force reload and provide aFunction to execute after the successful loading. Returns true if successfull, false otherwise.
loadLodash()
Loads the loadash javascript library.
See more in https://lodash.com/docs
loadUnderscore()
Loads the Underscore javascript library into scope (using the loadash alternative).
See more in: http://underscorejs.org and https://lodash.com/docs
log(msg)
Outputs to the current stdout a line composed of the current date, indication of INFO and the provided msg. Note: you can use startLog, stopLog and dumpLog to keep an internal record of theses messages.
logErr(msg)
Outputs to the current stderr a line composed of the current date, indication of ERROR and the provided msg. Note: you can use startLog, stopLog and dumpLog to keep an internal record of theses messages.
logWarn(msg)
Outputs to the current warning in a line composed of the current date, indication of WARN and the provided msg. Note: you can use startLog, stopLog and dumpLog to keep an internal record of theses messages.
lognl(msg)
Outputs to the current stdout, without a new line, a sentence composed of the current date, indication of INFO and the provided msg. Note: you can use startLog, stopLog and dumpLog to keep an internal record of theses messages.
md5(anObject) : String
Will return of the MD5 in hexadecimal format for a given anObject.
For files you can provide a file stream: var s = io.readFileStream(getOpenAFJar()); md5(s); s.close()
merge(anObjectA, anObjectB) : aMergedObject
Merges a JavaScript object A with a JavaScript object B a returns the result as a new object.
newJavaArray(aJavaClass, aSize) : JavaArrayClass
Creates a new Java Array object for the aJavaClass type for a provided aSize.
Examples:
newJavaArray(java.lang.String, 5);
newJavaArray(java.lang.Integer.TYPE, 2);
now() : Number
Will return the current system time in milliseconds.
nowNano() : Number
Will return the current system time in nanoseconds.
nowUTC() : Number
Will return the current system time in milliseconds.
oJobRun(aJson, args, aId)
Runs a oJob from aJson definition with the provided args (arguments). Optionally you can provide aId to segment these specific jobs.
oJobRunFile(aFile, args, aId)
Runs a oJob aFile with the provided args (arguments). Optionally you can provide aId to segment these specific jobs.
oJobRunJob(aJob, args, aId)
Shortcut for ow.oJob.runJob. Please see help for ow.oJob.runJob. Optionally you can provide aId to segment this specific job.
oPack(aParameters)
Tries to execute oPack with aParameters string. These string is equivalent to the opack command-line commands. aParameters = "help" will, for example, print all the help information.
oPromise(aFunction, aRejFunction) : oPromise
Custom Promise-like implementation. If you provide aFunction, this aFunction will be executed async in a thread and oPromise object will be immediatelly returned. Optionally this aFunction can receive a resolve and reject functions for to you use inside aFunction to provide a result with resolve(aResult) or an exception with reject(aReason). If you don't call theses functions the returned value will be used for resolve or any exception thrown will be use for reject. You can use the "then" method to add more aFunction that will execute once the previous as executed successfully (in a stack fashion). The return/resolve value from the previous function will be passed as the value for the second. You can use the "catch" method to add aFunction that will receive a string or exception for any exception thrown with the reject functions. You can also provide a aRejFunction that works like a "catch" method as previously described.
oPromise.all(anArray) : oPromise
Returns an oPromise that will be resolved when all oPromise part of the anArray are fullfiled. If any of the oPromises fails/rejects the returned oPromise will also be rejected/fail.
oPromise.catch(onReject) : oPromise
Adds onRejected to the current oPromise stack to execute if the previous function was rejected and receives the reason as parameter.
oPromise.race(anArray) : oPromise
Returns an oPromise that will be resolved when any oPromise part of the anArray is fullfiled. If any of the oPromises fails/rejects the returned oPromise will also be rejected/fail.
oPromise.then(onFulfilled, onRejected) : oPromise
Adds onFulfilled to the current oPromise stack to execute if the previous function was resolved successfully and receives the resolve/return value as parameter. Also adds onRejected to the current oPromise stack to execute if the previous function was rejected and receives the reason as parameter.
opackExec(aPackageName)
Tries to execute the provided opack aPackageName.
ow.loadAI()
Loads OpenWrap AI functionality.
ow.loadCh()
Loads OpenWrap channels functionality.
ow.loadDev()
Loads OpenWrap dev functionality. Basically functions being tested.
ow.loadFormat()
Loads OpenWrap format functionality. Basically functions to help with the formatting of strings, numbers, dates, etc...
ow.loadOJob()
Loads OpenWrap oJob functionality.
ow.loadObj()
Loads OpenWrap object functionality.
ow.loadServer()
Loads OpenWrap Server functionality. Basically functions to wrap access to server functionality.
ow.loadTemplate()
Loads OpenWrap template functionality. Basically functions to wrap access to Handlebars functionality.
ow.loadTest()
Loads OpenWrap test functionality. Basically functions to unit test other functionality.
parallel(aFunction, numThreads, aAggFunction, aControlMap) : Object
Executes a function in a specific number of threads (each function will receive a corresponding uuid). The returned result of each function execution is kept in an array. If no aAggFunction is provided this array will be returned, otherwise the array will be passed to the aAggFunction for processing and the corresponding result of aAggFunction will be returned. If no numThreads is provided, the number of threads will be automatically determined. Optionally you can provide a empty map as aControlMap that it will be filled with aControlMap.__threads with the threads object, the aControlMap.__numThreads for the number of threads in use and a thread __uuid list.
parallel4Array(anArray, aFunction, numThreads, aControlMap) : Object
Given anArray, divides it in subsets for processing in a specific number of threads. In each thread aFunction(aValue) will be executed for each value in sequence. An array with all the aFunction results will be returned. If no numThreads is provided, the number of threads will be automatically determined. Optionally you can provide a empty map as aControlMap that it will be filled with aControlMap.__threads with the threads object, the aControlMap.__numThreads for the number of threads in use and a thread __uuid list. Example:
var count = 0;
var ctrl = {};
var res = parallel4Array(thingsToProcess,
function(aValue) {
ctrl.__threads.sync(function() { count++; }) // Sync access to a shared variable
return processValue(aValue);
},
undefined,
ctrl
);
parallelArray(anArray, aReduceFunction, initValue, aAggFunction, numThreads, aControlMap) : Object
Given anArray, divides it in subsets for processing in a specific number of threads. In each thread aReduceFunction(pr, cv, i, arr), where pr = previous result, cv = current value, i = index and arr = array subset, will be executed for each value in sequence. The pr value for the first execution on each thread will have the value initValue if provided. The returned result, in each thread, will be placed into an array. If aAggFunction is defined, the resulting array will be passed to the aAggFunction for processing and the corresponding result of aAggFunction will be returned. If no numThreads is provided, the number of threads will be automatically determined. Optionally you can provide a empty map as aControlMap that it will be filled with aControlMap.__threads with the threads object, the aControlMap.__numThreads for the number of threads in use and a thread __uuid list.
persistDBInMem(aDB, aFilename) : Array
Tries to persist a in-memory database, aDB object, previously created by the function createDBInMem into a SQL aFilename. This can later be used to load again using the loadDBInMem function.
pidCheck(aPid) : Boolean
Verifies if aPid is running (returning true) or not (returning false).
pidCheckIn(aFilename) : boolean
Uses the contents of aFilename to determine if there is an existing process running with the pid recorded on the file. If it's running it will return false, if not it will return true and record the current pid on the aFilename. The function pidCheckOut will be added as a hook to run on the end of the current process.
pidCheckOut(aFilename) : boolean
Removes the pid information from aFilename and deletes the file if possible. If successful returns true, if not returns false.
pidKill(aPidNumber, isForce) : boolean
Tries to terminate a process with aPidNumber. If successful it will return true otherwise it will return false. If necessary, a boolean true value on isForce, will force the termination of the process.
plugin(aPlugin)
Provides a shortcut for the af.plugin function. It also provides a shortcut for plugins with the java package "openaf.plugins" (e.g. af.plugin("openaf.plugins.HTTP") is the same as plugin("HTTP")).
pods.declare(aId, exports)
Declares a new module, aId, as the provided exports literal.
pods.define(aId, aDepsArray, aFactoryFunction)
Defines a new module given aId, aDepsArray with depend id modules and a factory function.
pods.require(aIds, aCallbackFunction)
Requires a module or a list of modules and all of its dependencies. Optionally you can provide aCallbackFunction to inject the required modules into.
print(aStr)
Prints the aStr to the stdout (with a new line on the end) (example: print("hello world!"))
printErr(aStr)
Prints the aStr to the stderr (with a new line on the end) (example: printErr("Hupps!! A problem!"))
printErrnl(aStr)
Prints the aStr to the stderr (without adding a new line on the end) (example: printErrnl("Hupps!! A problem!"))
printTable(anArrayOfEntries, aWidthLimit, displayCount, useAnsi, colorMap) : String
Returns a ASCII table representation of anArrayOfEntries where each entry is a Map with the same keys. Optionally you can specify aWidthLimit and useAnsi. If you want to include a count of rows just use displayCount = true. If useAnsy = true you can provide a colorMap with colors for lines (default bold) and values (default CYAN).
printnl(aStr)
Prints the aStr to the stdout (without adding a new line on the end) (example: printnl("hello world!"))
processExpr(aSeparator, ignoreCase) : Map
Will access the current contents of the OpenAF -e argument looking for pairs of key values in the form "a=5;b=1;c=xpto\;" and will produce a Map with { "a": 5, "b": 1, "c": "xpto;" }. If no aSeparator is provided ';' will be assumed. __pmIn values will be also included. If ignoreCase = true all keys will be lower cased.
quickSort(items, aCompareFunction) : Array
Performs a quick sort algorithm on the items array provided. Optionally aCompareFunction can be provided. The sorted array will be returned.
repeat(nTimes, aStr) : String
Will build a string composed of aStr repeated nTimes.
require(aScript) : Object
Will try to load aScript from the directories specified in the loadRequire function (by default all opack directories plus the current working directory). Returns the exports object manipulated in aScript (note: results are cached)
restartOpenAF(aCommandLineArray, preCommandLineArray)
Terminates the current OpenAF execution and tries to start a new with the same command line, if aCommandLineArray is not provided. If aCommandLineArray is provided each array element will be use sequentially to build the command line to start a new OpenAF instance. preCommandLineArray can be used to provide java arguments if defined.
saveHelp(aPath, aMapOfFiles)
Given aMapOfFiles, or basically an array of JavaScript or Java source filenames, each file will be processed for ODoc XML tags and the corresponding ODoc database will be generated on the provided aPath suitable for offline use.
saveHelpWeb(aPath, aMapOfFiles)
Given aMapOfFiles, or basically an array of JavaScript or Java source filenames, each file will be processed for ODoc XML tags and the corresponding ODoc database will be generated on the provided aPath suitable for online use.
searchArray(anArray, aPartialMap, useRegEx, ignoreCase, useParallel) : Array
Shortcut to ow.obj.searchArray.
searchHelp(aTerm, aPath, anArrayOfIds) : Map
Searches the OpenAF ODoc help system for a specific term. Optionally you can provide a path of where to search for ODoc help files. If an exact match is found the function will return an array with a single a map with the corresponding ODoc id, key, fullkey and text. If no exact match is found the function will return an array of alternative matches or an empty array if no alternatives are found. Optionally you can also restrict by anArrayOfIds.
searchKeys(aObject, aSearchKey, useCase) : Map
Traverses aObject looking for key matches, ignoring case if useCase is true, of the regular expression aSearchKey. Each element founf is added to the returned Map. The element key will represent the path from aObject to it.
searchValues(aObject, aSearchValue, useCase) : Map
Traverse aObject looking for value matches, ignoring case if useCase is true, of the regular expression aSearchKey. Each value found is added to the returned Map linked to the path representation of where it was found.
setLog(aMap)
Sets the current log output settings:
- off (boolean) Turns off output to stdout/stderr
- offInfo (boolean) Turns off output of INFO
- offError (boolean) Turns off output of ERROR
- offWarn (boolean) Turns off output of WARN
- dateFormat (string) ow.format.fromDate format for date
- dateTZ (string) Time zone to use with ow.format.fromDate
- separator (string) String to use as separator
- async (boolean) Run in async mode
- profile (boolean) Gathers memory and system load stats
setOfflineHelp(aBoolean)
Forces help (odoc) to be retrieved locally (if aBoolean is true) or reestablishes the normal behaviour of retriving from online first (if aBoolean is false)
sh(commandArguments, aStdIn, aTimeout, shouldInheritIO, aDirectory, returnMap) : String
Tries to execute commandArguments (either a String or an array of strings) in the operating system as a shortcut for AF.sh except that it will run them through the OS shell. Optionally aStdIn can be provided, aTimeout can be defined for the execution and if shouldInheritIO is true the stdout, stderr and stdin will be inherit from OpenAF. If shouldInheritIO is not defined or false it will return the stdout of the command execution. It's possible also to provide a different working aDirectory. The variables __exitcode and __stderr can be checked for the command exit code and the stderr output correspondingly. In alternative if returnMap = true a map will be returned with stdout, stderr and exitcode.
sha1(anObject) : String
Will return of the SHA-1 in hexadecimal format for a given anObject.
For files you can provide a file stream: var s = io.readFileStream(getOpenAFJar()); sha1(s); s.close()
sha256(anObject) : String
Will return of the SHA-256 in hexadecimal format for a given anObject.
For files you can provide a file stream: var s = io.readFileStream(getOpenAFJar()); sha256(s); s.close()
sha512(anObject) : String
Will return of the SHA-512 in hexadecimal format for a given anObject.
For files you can provide a file stream: var s = io.readFileStream(getOpenAFJar()); sha512(s); s.close()
showDebugger(shouldRedirect)
Starts the a graphical Rhino debugger instance, typically from the openaf-console. The stdin, stdout and stderr can be redirected to the debugger by having shouldRedirect = true. The Rhino context will be shared between the debugger and the original script that invoked it (for example: openaf-console).
sleep(millis)
Shortcut for af.sleep function. Will pause execution for a given period of time expressed in milliseconds.
splitArray(anArray, numberOfParts) : Array
Returns the result of the split of anArray into equals numberOfParts (when possible). If numberOfParts is not provided the current result of getNumberOfCores() will be used.
splitBySeparator(aString, aSeparator) : Array
Will split aString using the provided aSeparator. If the aSeparator is escaped (for example if ';' is the aSeparator and aString 'abc\;def;123" only the second ';' will be considered.
sprint(aStr)
"Stringifies" and prints the aStr to the stdout (with a new line on the end) (example: sprint("hello world!"))
sprintErr(aStr)
"Stringifies" and prints the aStr to the stderr (with a new line on the end) (example: sprintErr("Hupps!! A problem!"))
sprintErrnl(aStr)
"Stringifies" and prints the aStr to the stderr (without adding a new line on the end) (example: sprintErrnl("Hupps!! A problem!"))
sprintnl(aStr)
"Stringifies" and prints the aStr to the stdout (without adding a new line on the end) (example: sprintnl("hello world!"))
startLog(externalLogging)
Starts collecting log messages logged with log* functions. See stopLog() and dumpLog(). You can also specify externalLogging, a custom channel subscribe function.
stopLog()
Will stop collecting log messages and will reset everything. User dumpLog() before stopping if you intend to keep the recorded log messages.
stringify(anObject, replacer, space) : String
Converts anObject into a string representation of the same. This is equivalent to the JSON.stringify function. If space isn't defined a " " (2 spaces) is assumed as the default value. Reverts to the beautifier function if it isn't possible to apply stringify to the current object. To see more info on the remaining parameters please check https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
sync(aFunction, anObject)
Will ensure that aFunction is synchronized, in multi-threaded scripts. Optionally you can provide anObject to synchronized upon.
templify(aTemplateString, someData) : String
Using Handlebars and the functionality provided in ow.template, will use the aTemplateString as a Handlebars template and return the parsed output. Optionally you can provide someData as data for the Handlebars template otherwise the current scope will be used.
Example:
var someText = "Hello World!";
var retText = templify("Hi, {{someText}}"); // Hi, Hello World!
threadBox(aExecFunction, aTimeout, aStopFunction)
Tries to execute aExecFunction inside a thread. If aTimeout is defined the thread will be terminated if it's still executing after aTimeout. If aStopFunction is defined it will receive, as argument, a boolean indicating if the thread has stopped (true). If this function returns true the thread execution will be terminated, if false will continue.
Note: see threadBoxCtrlC as aStopFunction to stop executing on Ctrl-C
threadBoxCtrlC() : Boolean
Meant to be use as a stopFunction for threadBox will return true if Ctrl-C is detected and false otherwise. If the current terminal can't support ANSI if will default to false.
tlog(msg, someData)
Outputs to the current stdout a line composed of the current date, indication of INFO and the provided msg using the templify function. Optionally you can provide also someData. Note: you can use startLog, stopLog and dumpLog to keep an internal record of theses messages.
tlogErr(msg, someData)
Outputs to the current stderr a line composed of the current date, indication of ERROR and the provided msg using the templify function. Optinionally you can provide also someData.
tlogWarn(msg, someData)
Outputs to the current warning in a line composed of the current date, indication of WARN and the provided msg using the templify function. Optinionally you can provide also someData.
tlognl(msg, someData)
Outputs to the current stdout, without a new line, a sentence composed of the current date, indication of INFO and the provided msg using the templify function. Optinionally you can provide also someData.
toCSV(anArray) : CSV
Converts a given javascript anArray into a CSV object instance.
toEncoding(aString, anEncoding) : String
Converts the provided aString to a different anEncoding (by default UTF-8).
tprint(aTemplateString, someData)
Using Handlebars and the functionality provided in ow.template, will use the aTemplateString as a Handlebars template and print the parsed output. Optionally you can provide someData as data for the Handlebars template otherwise the current scope will be used.
Example:
var someText = "Hello World!";
tprint("Hi, {{someText}}"); // Hi, Hello World!
tprintErr(aTemplateString, someData)
Using Handlebars and the functionality provided in ow.template, will use the aTemplateString as a Handlebars template and print, to the stderr, the parsed output. Optionally you can provide someData as data for the Handlebars template otherwise the current scope will be used.
Example:
var someText = "Hello World!";
tprintErr("Hi, {{someText}}"); // Hi, Hello World!
tprintErrnl(aTemplateString, someData)
Using Handlebars and the functionality provided in ow.template, will use the aTemplateString as a Handlebars template and print, to the stderr without new line, the parsed output. Optionally you can provide someData as data for the Handlebars template otherwise the current scope will be used.
Example:
var someText = "Hello World!";
tprintErrnl("Hi, {{someText}}"); // Hi, Hello World!
tprintln(aTemplateString, someData)
Using Handlebars and the functionality provided in ow.template, will use the aTemplateString as a Handlebars template and print, withouth a new line, the parsed output. Optionally you can provide someData as data for the Handlebars template otherwise the current scope will be used.
Example:
var someText = "Hello World!";
tprintln("Hi, {{someText}}"); // Hi, Hello World!
traverse(aObject, aFunction) : Map
Traverses aObject executing aFunction for every single element. The aFunction will receive the arguments: aKey, aValue, aPath, aObject.
uncompress(aResultOfTheCompressFunction) : Object
Uncompresses a JSON object, compressed by using the compress function, into a JSON object.
utf8(aString) : String
Converts the provided aString into UTF-8 encoding.
watch(waitFor, aCommand, beautifyFlag)
Executes javascript aCommand provided every waitFor periods of time (expressed in ms). The screen will be cleared and the execution will repeat indefinitely until the 'q' key is pressed. Optionally a beautifyFlag can be provided to execute the beautifier function on the aCommand result.
wedoDate(year, month, day, hour, minute, second, ms) : Map
Builds and returns a wedoDate JSON object given either a year, a month, a day, a hour, a minute, a second and ms or a Date object.