Chapter 8. JAM: The JavaScript Agent Machine
270
cesses sequentially. If an activity execution reaches the hard time-slice limit, a
SCHEDULE exception is raised, which can be handled by an optional agent
exception handler (but without extending the time-slice). This agent exception
handling has only an informational purpose for the agent, but offers the agent
to modify its behaviour. All consumed activity and transition execution times
are accumulated, and if the agent process reaches a soft run-time limit, an EOL
exception is raised. This can be handled by an optional agent exception han-
dler, which can try to negotiate a higher CPU limit based on privilege level and
available capabilities (only level-2 agents). Any ready scheduling block of an
agent and signal handlers are scheduled before activity execution.
After an activity was executed, the next activity is computed by calling the
transition function in the transition section.
In contrast to the AAPL model that supports multiple blocking statements
(e.g., IO/tuple-space access) inside activities, JS is incapable of handling any
kind of process blocking (there is no process and blocking concept). For this
reason, scheduling blocks can be used in AgentJS activity functions handled by
the AIOS scheduler. Blocking AgentJS functions returning a value use common
callback functions to handle function results, e.g., inp(pat, function(tup)
{..}).
A scheduling block consists of an array of functions (micro activities), i.e.,
B(block) = B([function(){..}, function(){..},...])., executed one-by-
one by the AIOS scheduler. Each function may contain a blocking statement at
the end of the body. The this object inside each function always reference
the agent object. To simplify iteration, there is a scheduling loop constructor
L(init,cond,next,block,finalize) and an object iterator constructor
I(obj,next,block,finalize), used, e.g., for array iteration.
Agent execution is encapsulated in a process container handled by the
AIOS. An agent process container can be blocked waiting for an internal sys-
tem-related IO event or suspended waiting for an agent-related AIOS event
(caused by the agent, e.g., the availability of a tuple). Both cases stop the
agent process execution until an event occurred.
The basic agent scheduling algorithm is shown in Algorithm 8.1 and consists
of an ordered scheduling processing type selection, i.e., partitioning agent
processing in agent activities, transitions, signals, and scheduling blocks. In
one scheduler pass, only one kind of processing is selected to guarantee
scheduling fairness between different agents. There is only one scheduler
used for all virtual (logical) nodes of a world (a JAM instance). A process priority
is used to alternate activity and signal handling of one agent, preventing long
activity and transition processing delays due to chained signal processing if
there are a large number of signals pending.
S. Bosse, Unified Distributed Sensor and Environmental Information Processing with Multi-Agent Systems
epubli, ISBN 9783746752228 (2018)