$server

Global object that stores information about the server environment.

Summary
$serverGlobal object that stores information about the server environment.
Properties
commandPathOS path to the commandline invoker
dataSourcesA structure of DS information
isThreadtrue if this is an independent thread with no access to session or servlet
isCommandlinetrue if this code is running from the commandline
threadFunctionSourcethe source of the function that the current subthread is executing, or null if this is not a subthread
instanceIdan identifier for this server instance
purposeA short name that describes the purpose of this instance.
responseA reference to servlet response object
requestA reference the servlet request object.
requestScriptNameThe name of the originally requested script.
serverUrlThe the server name and protocol of the request
remoteAddrThe IP address of the requestor
requestServerUrlDEPRECATED see $server.serverUrl
requestDirMynaPath representing the directory of the originally requested script.
requestUrlURL Path representing the directory of the originally requested script.
resolveUrltakes a url path relative to the request directory and returns an absolute URL, including the server part.
rootDirMynaPath representing the Myna root directory.
rootUrlURL Path representing the Myna root directory.
currentDirMynaPath representing the directory of the currently executing script.
currentUrlURL Path representing the directory of the currently executing script
globalScopeA reference to the Top Level Javascript scope in the current script
servletReference to the servlet object.
versionString representing the running version of Myna.
scriptNameThe name of the currently running script.
tempDirMynaPath of the JVM temp directory
hostNamethe hostname of the server running myna
ipAdressesAn array of the non-loopback ipv4 IP addresses on this machine
osNameString representing the host operating system type.
osArchString representing the host cpu architecture.
osVersionString representing the host operating system version.
propertiesThe general properties set in the general Settings section of the Administrator
memCurrentThe current heap size in bytes.
memMaxThe maximum heap size
memFreeThe current number of free bytes on the heap.
memAvailableThe number of free bytes on the heap + unallocaed heap space.
memUsedThe number of used bytes on the heap
mynaCmdPath to the Myna commandline shell script
Functions
getretrieves a server variable
setSets a variable that is available across all requests.
reParentChanges parent scope of all the functions in obj
restartIf this instance is running has watchdog, the exit the JVM
memToScaleconverts a value in bytes to another scale

Properties

commandPath

OS path to the commandline invoker

dataSources

A structure of DS information

isThread

true if this is an independent thread with no access to session or servlet

isCommandline

true if this code is running from the commandline

threadFunctionSource

the source of the function that the current subthread is executing, or null if this is not a subthread

instanceId

an identifier for this server instance

purpose

A short name that describes the purpose of this instance.  Set in General Settings of Myna Administrator

response

A reference to servlet response object

request

A reference the servlet request object.

requestScriptName

The name of the originally requested script.

Example

index.sjs

serverUrl

The the server name and protocol of the request

Example

http://localhost:8080

Note

If Myna is behind a proxy you will want to make sure that the X-Forwarded-Host and optionally X-Forwarded-Proto request headers are set by the proxy so that a valid result is generated

See

remoteAddr

The IP address of the requestor

Example

123.345.678.910

Detail

This is normally the IP address of the request.  If the X-Forwarded-For header is set, then that IP address is returned instead

requestServerUrl

DEPRECATED see $server.serverUrl

requestDir

MynaPath representing the directory of the originally requested script.

Example

file:/usr/share/tomcat/webapps/myna/myna/administrator/

requestUrl

URL Path representing the directory of the originally requested script.

Example

/myna/myna/administrator/

resolveUrl

takes a url path relative to the request directory and returns an absolute URL, including the server part.

Parameters

patha url path relative to the request directory

Example

//return full URL to this page
var linkUrl = $server.resolveUrl($server.requestScriptName);

rootDir

MynaPath representing the Myna root directory.

Example

file:/usr/share/tomcat/webapps/myna/

rootUrl

URL Path representing the Myna root directory.

Example

/myna/

currentDir

MynaPath representing the directory of the currently executing script.

Example

file:/usr/share/tomcat/webapps/myna/myna/administrator/views/

currentUrl

URL Path representing the directory of the currently executing script

Example

/<context root>/myna/administrator/views/

globalScope

A reference to the Top Level Javascript scope in the current script

Detail

A reference to the Top Level Javascript scope in the current script.  This analogous to “window” in a browser environment.

servlet

Reference to the servlet object.

version

String representing the running version of Myna.

Example

1.0_alpha_9

scriptName

The name of the currently running script.

Example

index.sjs

tempDir

MynaPath of the JVM temp directory

Example

file:/usr/share/tomcat/temp

hostName

the hostname of the server running myna

ipAdresses

An array of the non-loopback ipv4 IP addresses on this machine

osName

String representing the host operating system type.

Example

Linux

osArch

String representing the host cpu architecture.

Example

i386

osVersion

String representing the host operating system version.

Example

2.6.20-16-386

properties

The general properties set in the general Settings section of the Administrator

Example

var purpose = $server.properties.instance_purpose

See Also

memCurrent

memMax

memFree

The current number of free bytes on the heap.

For the total memory available for new objects, see memAvailable

See

$server.memMax, $server.memCurrent, $server.memAvailable, $server.memUsed, Myna.freeMemory()

memAvailable

The number of free bytes on the heap + unallocaed heap space.

See

$server.memMax, $server.memCurrent, $server.memFree, $server.memUsed, Myna.freeMemory()

memUsed

mynaCmd

Path to the Myna commandline shell script

Example

//execute some code in a separate JVM:
Myna.executeShell($server.mynaCmd+" -m 40",<ejs>
Myna.printConsole("I'm running as a completely separate process!");
Myna.include("/some/gnarly/code.sjs");
</ejs>)

See:

Functions

get

get:function(key,
value)

retrieves a server variable

Parameters

keya variable name

See

$server.set,

set

set:function(key,
value)

Sets a variable that is available across all requests.  Server varaiables are not preserved across Myna restarts

Parameters

keya variable name
valueThe value to set

Returns

value

See

$server.get,

reParent

reParent:function reParent(obj,
index)

Changes parent scope of all the functions in obj

Normally the parent scope of a function is a closure of the scope chain at the time the function was created.  If this function is executed in a different scope, then any references to parent scope variables like $server or $application will fail

This function changes all references to topLevelScope properties in obj, its prototype, and object properties to proxies that will find those properties in the global scope of the current thread.  This function is called automatically by $server.set, $application.set, and Myna.Cache

Parameters

objFunction or Object to reparent

Returns

  • obj

restart

restart:function()

If this instance is running has watchdog, the exit the JVM

Detail

If this instance of Myna has a watchdog process (-Dmyna.hasWatchdog passed to the JVM), the this will call System.exit(0) and allow the watchdog to restart the process.  Starting Myna via the embedded Tomcat instance will automatically enable a watchdog process

memToScale

memToScale:function(value,
scale)

converts a value in bytes to another scale

Paramters

valuevalue in bytes to convert
scaleOptional default ‘b’ scale of returned value, precise to 2 decimal places.  See Scales below

Scales

bbytes
kkilobytes
mmegabytes
ggigabytes
tterabytes
The the server name and protocol of the request
A MynaPath is a file URI String with certain automatic translations.
get:function(key,
value)
retrieves a server variable
set:function(key,
value)
Sets a variable that is available across all requests.
reParent:function reParent(obj,
index)
Changes parent scope of all the functions in obj
restart:function()
If this instance is running has watchdog, the exit the JVM
memToScale:function(value,
scale)
converts a value in bytes to another scale
URL Path representing the Myna root directory.
URL Path representing the directory of the currently executing script
The name of the currently running script.
The name of the originally requested script.
Myna.getGeneralProperties=function Myna_getGeneralProperties()
Returns the Java Properties object loaded from /WEB-INF/classes/general.properties
The maximum heap size
The number of free bytes on the heap + unallocaed heap space.
The current number of free bytes on the heap.
The number of used bytes on the heap
Myna.freeMemory=function Myna_freeMemory(size,
timeout)
attempts to free the specified amount of memory within the timeout, returning true if successful.
The current heap size in bytes.
The Myna commandline invoker consists of an executable BASH script file for UNIX (“myna”) or a command file for Windows (“myna.cmd”).