Skip to content

Lite API: Runtime

Hayun Lee edited this page Dec 21, 2020 · 8 revisions

Parent Document: ANT APIs

Runtime API comprises of the app-lifecycle functions and miscellaneous utility functions.

You need to load runtime API module before you use its API as following.

var runtimeAPI = require('ant').runtime;

App Lifecycle

setCurrentApp()

String setCurrentApp(Function on_initialize, Function on_start, Function on_stop);

setCurrentApp() registers functions in charge of application lifecycle in App Runtime.

And it returns whether it succeeded in registering the app runtime.

  • on_initialize: Called when installing an application.
  • on_start: Called at application startup.
  • on_stop: Called when the application program is stopped.

It returns a result(String) of “Success” if it succeeds in registering in App Runtime and “Failed” if it fails.

Example

var onInitialize = function () {
  console.log("onInitialize");
);
var onStart = function () {
  console.log('onStart');
);
var onStop = function () {
  console.log('onStop');
};

runtimeAPI.setCurrentApp(onInitialize, onStart, onStop);

getCurrentApp()

Object getCurrentApp();

getCurrentApp() returns the app currently registered in the App Runtime.

If there is no registered app, undefined is returned.

Example

var app = runtimeAPI.getCurrentApp();
if (app != undefined) {
  app.start();
  app.stop();

Misc. Utility

getPssInKB()

Number getPssInKB();

getPssInKB() returns the PSS of the currently running app.

Example

var pss = runtimeAPI.getPssInKB();

getEnv()

String getEnv(String envKey);

getEnv() returns the value of the environment variable according to envKey.

  • envKey: Key value of environment variable

Example

var antRootDir = runtimeAPI.getEnv('ANT_ROOT);

downloadFileViaHTTP()

Boolean downloadFileViaHTTP(String url, String downloadPath);

downloadFileViaHTTP() downloads a file.

  • url: URL to download
  • downloadPath: Directory to save downloaded files

It returns whether the download was successful.

Example

var resultDownload = runtimeAPI.downloadFileViaHTTP(modelUrl, modelArchivePath);

unarchive()

Boolean unarchive(String archiveFilePath, String targetDirPath);

unarchive() decompresses the file.

  • archiveFilePath: Path to compressed file
  • targetDirPath: Directory path to decompress

It returns whether the decompression was successful.

Example

var resultArchive = runtimeAPI.unarchive(modelArchivePath, modelDirectoryPath);