next up previous contents
Next: Resource Access Up: Creating an Agent Previous: terminateUser()   Contents

Command Queue

As mentioned before all the methods to process the real work of the Agent (its desired tasks) have to be put into own methods. These methods may not need parameters, one should use global variables instead. This has to be done because only the global variables are serialized when moving the Agent. The name of the method to call after being started has to be put into the command queue using the method setNextCommand(String cmd). This should be done in the initUser method, because the startUser method is called every time when an Agent is restarted and it would lead to call this method every time again (this could be wished, but normally is not). The command queue can hold more the one command, making it possible to define at the begin of the Agent life what tasks have to be accomplished and in what order. The commands in the command queue are processed while the Agent is started and not stopped anymore.

The following code from the example Agent tells the basic Agent to execute the method moveMe() when started:

setNextCommand(``moveMe'');
When calling a command method, first the command is retrieved of the queue and removed from it. Then the method is called. When an Agent is traveling, the next command is executed when arriving at the new System. There should of course be a next command in the command queue available before traveling.


next up previous contents
Next: Resource Access Up: Creating an Agent Previous: terminateUser()   Contents
Thomas Letsch 2001-02-21