|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ThreadAgent
MobiliTools $Name: $, $Id: ThreadAgent.java,v 1.1.1.1 2003/03/28 14:47:58 dillense Exp $
This example class shows a straightforward implementation of a thread-based agent activity.
The agent activity consists in continuously moving from agency to agency in its region.
The agent takes an optional single integer argument, interpreted as a delay in ms (no argument means no delay).
The easiest way to use this example is to use GUI-enabled agencies.
NB : THIS EXAMPLE REQUIRES THE MAFFINDER TO BE RUNNING BEFORE LAUNCHING AGENCIES AND AGENTS.
At creation, the agent gets the latest list of agencies. While this list contains only one agency (it cannot be empty!), the agent loops on updating the list and waiting for the specified delay. As soon as the list contains at least two agencies, the agent begins to move, waiting for the specified delay between two consecutive moves.
Field Summary | |
protected boolean |
dead
true if the agent is dead |
protected Location[] |
itinerary
latest list of agencies in current region |
protected Agency |
my_agency
current host agency |
protected Name |
my_name
agent's name |
protected int |
pause
delay in ms between consecutive moves or agency list updates |
protected int |
step
index in list of agencies for next move |
protected boolean |
suspended
true if the agent is suspended |
Constructor Summary | |
ThreadAgent()
|
Method Summary | |
void |
afterBirth(AgentSystem agency,
AgentInfo entry,
java.lang.Object arg)
Initialize the agent and create a thread to run the agent's autonomous activity |
void |
afterMove(AgentSystem agency,
Location dummy1,
java.lang.String dummy2)
Create a thread after move to go on agent's autonomous activity in new host agency. |
void |
afterMoveFailed(Location dummy1,
java.lang.String dummy2,
int dummy3,
java.lang.String dummy4)
Nothing special to do if the agent transport/setup phase failed during a move. |
void |
beforeDeath()
Make the agent's thread stop as soon as possible. |
void |
beforeMove(Location dummy1,
java.lang.String dummy2)
Nothing special to do before moving. |
void |
beforeResume()
Update the itinerary in current agency's region, and create a thread to run the agent's autonomous activity. |
void |
beforeShutdown()
Nothing special to do before agency shutdown (just face upcoming death...) |
void |
beforeSuspend()
Make the agent's thread stop as soon as possible. |
protected void |
resetItinerary()
Update the list of agencies and set the itinerary index to zero. |
void |
run()
Agent activity: wait for a while, then move to next agency in itinerary or update itinerary if it contains a single agency. |
protected void |
runActivity()
Agent's thread creation. |
Methods inherited from class java.lang.Object |
|
Field Detail |
protected Name my_name
protected transient Agency my_agency
protected volatile Location[] itinerary
protected int pause
protected int step
protected boolean dead
protected boolean suspended
Constructor Detail |
public ThreadAgent()
Method Detail |
protected void resetItinerary()
protected void runActivity()
public void run()
run
in interface java.lang.Runnable
public void afterBirth(AgentSystem agency, AgentInfo entry, java.lang.Object arg) throws BadOperation
afterBirth
in interface MobileObject
arg
- if a non-empty String[], should hold a delay in ms as a single value;
this delay is applied between two consecutive moves or itinerary updates.
Otherwise, this delay is zero.public void beforeSuspend()
beforeSuspend
in interface MobileObject
public void beforeResume() throws BadOperation
beforeResume
in interface MobileObject
public void beforeMove(Location dummy1, java.lang.String dummy2)
beforeMove
in interface MobileObject
public void afterMove(AgentSystem agency, Location dummy1, java.lang.String dummy2)
afterMove
in interface MobileObject
public void afterMoveFailed(Location dummy1, java.lang.String dummy2, int dummy3, java.lang.String dummy4)
afterMoveFailed
in interface MobileObject
public void beforeDeath()
beforeDeath
in interface MobileObject
public void beforeShutdown()
beforeShutdown
in interface MobileObject
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |