10.2 Survival 359
agency as soon as its run method has terminated. Otherwise, the agent
remains alive, but in state Waiting until the user, the agency, or any
other plugin restarts it. In this example it can only be activated by an
external event. Later, when we use asynchronous messaging, the agent
may be awakened by a message from another agent or from its owner. To
restart an agent, type in the runagent command, followed by the agent’s
full name. However, the agent still does not do anything sensible except
print Hello World messages to its owner. Every time you start the agent, a
new message will be printed. To eventually delete the agent manually, you
have to use the stopagent command, followed by the agent’s name. An
agent can also release the connection to the Survival service if it wants
In the following sections, we will introduce all the basic services that are
shipped with the Tracy agency, beginning with the Survival plugin.
The most important job of the Survival plugin is to prevent an agent from
being disposed after its run method has terminated. It can also be used to
schedule future agent execution. For example, an agent can deﬁne that it
wants to be started once at a speciﬁc time or time interval. An agent can
also deﬁne that it wants to be started periodically.
The complete API of the Survival service consists of the following
public void schedule( Date date )
Starts the agent once at the given date.
public void schedule( Date firstDate, long period )
Starts the agent at the given ﬁrstDate and then every period milliseconds.
public void schedule( long delay )
Starts the agent once after the given delay in milliseconds.
public void schedule( long delay, long period )
Starts the agent after the given delay in milliseconds and then every period milliseconds.
public void cancel()
Deregisters from this service. Stops every previously deﬁned timer.