When a new Agent is created (see Figure
![[*]](/usr/share/latex2html/icons/crossref.png)
), the
AgentLoader
loads the needed classes using the
AgentClassLoader which
is a subclass of the standard
ClassLoader. The
AgentClassLoader
supports only the loading from the CLASSPATH but can easily be extended to load
them from other AgentSystems and from web / ftp servers. The Agent runs in its
own thread group which has some security advantages. The priority of each Agent
and its own thread can be controlled through the thread group of the Agent and
it also shows if the Agent is still executing. Since the Agent is untrusted
code all the calls to methods of the Agent have to be done by a thread for itself
to do not block the execution of the
AgentLoader and the System.
The first thread for the Agent is created for instantiating the Agent. When
the Agent is instantiated its constructor is called, possible containing evil
code. This thread is member of the thread group of the Agent and has the same
priority, which is lower then the of the rest of the System. The
AgentLoader
waits now at a maximum of one second for the thread to make the Agent object
available. The Agent can spend more time in the constructor but the
AgentLoader
continuous work after waiting the one second. The timeout for the Agent methods
is still a static variable of the
AgentLoader class, but could
be put into the configuration file in future. If the Agent has not finished
with its constructor after the timeout, the AgentLoader throws an Exception
and exits from its constructor (where all this stuff is done). This lets only
Agents execute in the machine which are compliant to the timeout rules of the
System. This can be done strictly because the Agent should not have code in
its constructor. Therefor an Agent is provided with the
initUser()
method, which is described in the Agent class section. After instantiating the
AgentLoader scans the Agent class to store the list of available methods for
receiving messages. These message have to start with the string ``handle''
to be recognized. The
AgentLoader uses for this purpose the
getMethods() of the
Class object of the Agent class.
This is done by the following line of code:
Method [] agentMethods = this.agent.getClass().getMethods();
When an Agent was received by the System and has to be started again here, it
receives also an AgentLoader. The boolean parameter create
tells the AgentLoader if it has to create a new Agent or just
restart an old one. When an Agent is traveling its own thread is stopped and
thus it cannot be restarted again. Once a thread has finished executing its
run() method, it is no longer possible to start it again (like with
calling the start() method of the thread again). Therefor the AgentLoader
has to create a new Thread with the old Agent as parameter
(as well as the Agent thread group). Then the AgentLoader
scans the methods like mentioned before to find all message receivers and stores
them.
The following list will describe the other methods to be used to control an
Agent.