Skip to content
Nuno Aguiar edited this page May 22, 2018 · 4 revisions

$ch

$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

$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

$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

$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

$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

$doWait(aPromise, aWaitTimeout) : oPromise

Blocks until aPromise is fullfilled or rejected. Optionally you can specify aWaitTimeout between checks. Returns aPromise.


$from

$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

$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

AF.encryptText()

Interactevly asks to enter a text and then uses af.encrypt to print to stdout the result.


AF.fromYAML

AF.fromYAML(aYaml) : Object

Tries to parse aYaml into a javascript map.


AF.toYAML

AF.toYAML(aJson) : String

Tries to dump aJson into a YAML string.


IO.readFileYAML

IO.readFileYAML(aYAMLFile) : Object

Tries to read aYAMLFile into a javascript object.


IO.writeFileYAML

IO.writeFileYAML(aYAMLFile, aObj)

Tries to write a javascript aObj into a aYAMLFile.


addOnOpenAFShutdown

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

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

ansiStart(force)

Prepares to output ansi codes if the current terminal is capable off (unless force = true). Use with ansiColor() and ansiStop().


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

beautifier(anObject) : String

Shortcut for the af.js2s function providing a human readable representation of the javascript object provided.


beep

beep()

Tries to produce a beep sound.


bprint

bprint(aStr)

"Beautifies" and prints the aStr to the stdout (with a new line on the end) (example: bprint("hello world!"))


bprintErr

bprintErr(aStr)

"Beautifies" and prints the aStr to the stderr (with a new line on the end) (example: bprintErr("Hupps!! A problem!"))


bprintErrnl

bprintErrnl(aStr)

"Beautifies" and prints the aStr to the stderr (without adding a new line on the end) (example: bprintErrnl("Hupps!! A problem!"))


bprintnl

bprintnl(aStr)

"Beautifies" and prints the aStr to the stdout (without adding a new line on the end) (example: bprintnl("hello world!"))


checkLatestVersion

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

clone(anObject) : aClonedObject

Creates a new copy of a JavaScript object.


cls

cls()

Tries to clear the screen. The commands to try to clean the screen are given in ANSI.


colorify

colorify(aObject) : String

Tries to ANSI colorify a json aObject for use with cprint, cprintErr, cprintErrnl and cprintnl


compare

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

compress(anObject) : ArrayOfBytes

Compresses a JSON object into an array of bytes suitable to be uncompressed using the uncompress function.


cprint

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

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

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

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

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

deleteFromArray(anArray, anIndex) : Array

Deletes the array element at anIndex from the provided anArray. Returns the new array with the element removed.


dumpLog

dumpLog() : Array

Returns an array with collected log messages. Each entry has: d - timestamp; t - type; m - message.


exit

exit(anExitCode)

Immediately exits execution with the provided exit code


extend

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

findRandomOpenPort() : number

Tries to find a random open port on all network interfaces. Useful to start network servers on an available port.


flatten

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

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

getChLog() : Channel

Returns the current log dump channel.


getDistribution

getDistribution() : String

Returns the current distribution channel for this version of OpenAF.


getFromZip

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

getNumberOfCores() : Number

Try to identify the current number of cores on the system where the script is being executed.


getOPackLocalDB

getOPackLocalDB() : Array

Returns an Array of maps. Each map element is an opack package description of the currently  locally installed opack packages.


getOPackPath

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

getOPackPaths() : Array

Returns an array of strings with the paths for each of the installed opacks.


getOPackRemoteDB

getOPackRemoteDB() : Array

Returns an Array of maps. Each map element is an opack package description registered in the OpenAF central repository.


getOpenAFJar

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

getOpenAFPath() : String

Returns the filesystem path to the openaf.jar currently being used for the script execution.


getPid

getPid() : String

Tries to retrieve the current script execution operating system PID and returns it.


getUUID

getUUID() : String

Generates and returns an UUID using a javascript algorithm (if needed you can refer to the  AF operation AF.KeyGenerator.GenerateUUID).


getVersion

getVersion() : String

Shortcut for the af.getVersion (see more af.getVersion) function. Will return the current version of OpenAF being used.


inherit

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

ioStreamCopy(aOutputStream, aInputStream)

Copies the contents of a Java aInputStream to a Java aOutputStream. The two streams will  be closed in the end.


ioStreamRead

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

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

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

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

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

isArray(aObj) : boolean

Returns true if aObj is an array, false otherwise.


isDate

isDate(aObj) : boolean

Returns true if aObj is a date, false otherwise


isDef

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

isDefined(aObject) : boolean

Returns true if the provided aObject is defined as a javascript variable. It will return false otherwise. (see also isUndefined)


isFunction

isFunction(aObj) : boolean

Returns true if aObj is a function, false otherwise;


isJavaObject

isJavaObject(aObj) : boolean

Returns true if aObj is a Java object, false otherwise


isMap

isMap(aObj) : boolean

Returns true if aObj is a map, false otherwise.


isNumber

isNumber(aObj) : boolean

Returns true if aObj is a number, false otherwise


isObject

isObject(aObj) : boolean

Returns true if aObj is an object, false otherwise;


isString

isString(aObj) : boolean

Returns true if aObj is a string, false otherwise


isUnDef

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

isUndefined(aObject) : boolean

Returns true if the provided aObject is undefined as a javascript variable. It will return false otherwise. (see also isDefined)


javaRegExp

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

jsonParse(aString) : Map

Shorcut for the native JSON.parse that returns an empty map if aString is not defined, empty or unparsable.


listFilesRecursive

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

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

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

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

loadDiff()

Loads the JsDiff javascript library into scope (check https://github.com/kpdecker/jsdiff).


loadFuse

loadFuse()

Loads the FuseJS javascript library into scope.

See more in: http://fusejs.io/


loadHandlebars

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

loadHelp()

Loads into scope the ODoc objects for documentation support.


loadJSYAML

loadJSYAML()

Loads the JS-YAML library.


loadLib

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

loadLodash()

Loads the loadash javascript library.

See more in https://lodash.com/docs


loadUnderscore

loadUnderscore()

Loads the Underscore javascript library into scope (using the loadash alternative).

See more in: http://underscorejs.org and https://lodash.com/docs


log

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

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

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

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

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

merge(anObjectA, anObjectB) : aMergedObject

Merges a JavaScript object A with a JavaScript object B a returns the result as a new object.


newJavaArray

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

now() : Number

Will return the current system time in milliseconds.


nowNano

nowNano() : Number

Will return the current system time in nanoseconds.


nowUTC

nowUTC() : Number

Will return the current system time in milliseconds.


oJobRun

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

oJobRunFile(aFile, args, aId)

Runs a oJob aFile with the provided args (arguments). Optionally you can provide aId to segment these specific jobs.


oJobRunJob

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

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

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

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

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

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

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

opackExec(aPackageName)

Tries to execute the provided opack aPackageName.


ow.loadAI

ow.loadAI()

Loads OpenWrap AI functionality.


ow.loadCh

ow.loadCh()

Loads OpenWrap channels functionality.


ow.loadDev

ow.loadDev()

Loads OpenWrap dev functionality. Basically functions being tested.


ow.loadFormat

ow.loadFormat()

Loads OpenWrap format functionality. Basically functions to help with the formatting of strings, numbers, dates, etc...


ow.loadOJob

ow.loadOJob()

Loads OpenWrap oJob functionality.


ow.loadObj

ow.loadObj()

Loads OpenWrap object functionality.


ow.loadServer

ow.loadServer()

Loads OpenWrap Server functionality. Basically functions to wrap access to server functionality.


ow.loadTemplate

ow.loadTemplate()

Loads OpenWrap template functionality. Basically functions to wrap access to Handlebars functionality.


ow.loadTest

ow.loadTest()

Loads OpenWrap test functionality. Basically functions to unit test other functionality.


parallel

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

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

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

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

pidCheck(aPid) : Boolean

Verifies if aPid is running (returning true) or not (returning false).


pidCheckIn

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

pidCheckOut(aFilename) : boolean

Removes the pid information from aFilename and deletes the file if possible.  If successful returns true, if not returns false.


pidKill

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

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

pods.declare(aId, exports)

Declares a new module, aId, as the provided exports literal.


pods.define

pods.define(aId, aDepsArray, aFactoryFunction)

Defines a new module given aId, aDepsArray with depend id modules and a factory function.


pods.require

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

print(aStr)

Prints the aStr to the stdout (with a new line on the end) (example: print("hello world!"))


printErr

printErr(aStr)

Prints the aStr to the stderr (with a new line on the end) (example: printErr("Hupps!! A problem!"))


printErrnl

printErrnl(aStr)

Prints the aStr to the stderr (without adding a new line on the end) (example: printErrnl("Hupps!! A problem!"))


printTable

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

printnl(aStr)

Prints the aStr to the stdout (without adding a new line on the end) (example: printnl("hello world!"))


processExpr

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

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

repeat(nTimes, aStr) : String

Will build a string composed of aStr repeated nTimes.


require

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

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

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

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

searchArray(anArray, aPartialMap, useRegEx, ignoreCase, useParallel) : Array

Shortcut to ow.obj.searchArray.


searchHelp

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

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

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

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

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

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

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

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

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

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

sleep(millis)

Shortcut for af.sleep function. Will pause execution for a given period of time expressed in milliseconds.


splitArray

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

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

sprint(aStr)

"Stringifies" and prints the aStr to the stdout (with a new line on the end) (example: sprint("hello world!"))


sprintErr

sprintErr(aStr)

"Stringifies" and prints the aStr to the stderr (with a new line on the end) (example: sprintErr("Hupps!! A problem!"))


sprintErrnl

sprintErrnl(aStr)

"Stringifies" and prints the aStr to the stderr (without adding a new line on the end) (example: sprintErrnl("Hupps!! A problem!"))


sprintnl

sprintnl(aStr)

"Stringifies" and prints the aStr to the stdout (without adding a new line on the end) (example: sprintnl("hello world!"))


startLog

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

stopLog()

Will stop collecting log messages and will reset everything. User dumpLog() before stopping if you intend to keep the recorded log messages.


stringify

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

sync(aFunction, anObject)

Will ensure that aFunction is synchronized, in multi-threaded scripts. Optionally you can provide anObject to synchronized upon.


templify

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

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

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

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

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

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

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

toCSV(anArray) : CSV

Converts a given javascript anArray into a CSV object instance.


toEncoding

toEncoding(aString, anEncoding) : String

Converts the provided aString to a different anEncoding (by default UTF-8).


tprint

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

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

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

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

traverse(aObject, aFunction) : Map

Traverses aObject executing aFunction for every single element. The aFunction will receive the arguments: aKey, aValue, aPath, aObject.


uncompress

uncompress(aResultOfTheCompressFunction) : Object

Uncompresses a JSON object, compressed by using the compress function, into a JSON object.


utf8

utf8(aString) : String

Converts the provided aString into UTF-8 encoding.


watch

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

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.

Clone this wiki locally