|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmadkit.kernel.AbstractAgent
madkit.kernel.Agent
public abstract class Agent
The main MadKit AbstractAgent class. Provides support for non threaded agent life cycle, messaging, graphical interface, group and roles management, agent information, ...
The agent behavior is intentionally *not* defined. It is up to the agent developer to choose an agent model or to develop his specific agent library on top of the facilities provided by MadKit. However, all agent share the same organizational view, and the basic messaging code, so integration of agent coming from different developer and having heterogeneous models is quite easy.
Agent-related methods (almost everything here) can invoked only after registration in the kernel (i.e. starting from the activate() method call on this agent). That means that you should not use any of the agent methods in constructor
Constructor Summary | |
---|---|
Agent()
|
Method Summary | |
---|---|
boolean |
connectAgencyToAgency(java.lang.String host,
int port)
|
void |
createPlace(java.lang.String place)
|
void |
createPlace(java.lang.String place,
java.lang.String informations)
|
void |
enableMobility(java.lang.String name)
|
void |
enableMobility(java.lang.String name,
int port)
|
protected void |
exitImmediatlyOnKill()
Ensures that an agent will be cleanly killed. |
KernelAddress |
getAgencyNamed(java.lang.String name)
|
int |
joinPlace(java.lang.String place)
|
int |
joinPlace(java.lang.String place,
java.lang.String pwd)
|
int |
joinPlace(java.lang.String Community,
java.lang.String place,
java.lang.String pwd)
|
void |
live()
This method defines the main behavior of threaded agents. |
void |
pause(int t)
Suspend the agent for a while. |
protected void |
receiveMessage(Message m)
this method is dramatically private. |
void |
run()
Only useful to the agent micro-kernel |
Message |
waitNextMessage()
This method is the blocking version of nextMessage(). |
Message |
waitNextMessage(long timeout)
This method is the blocking version of nextMessage(), with time-out. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Agent()
Method Detail |
---|
public final void pause(int t)
t
- pause duration in millisecondspublic final Message waitNextMessage()
public final Message waitNextMessage(long timeout)
timeout
- the maximum time to wait, in milliseconds
protected void receiveMessage(Message m)
receiveMessage
in class AbstractAgent
m
- the messagepublic void live()
public final void run()
run
in interface java.lang.Runnable
public void createPlace(java.lang.String place, java.lang.String informations)
public void createPlace(java.lang.String place)
public void enableMobility(java.lang.String name)
public void enableMobility(java.lang.String name, int port)
public boolean connectAgencyToAgency(java.lang.String host, int port)
public int joinPlace(java.lang.String place)
public int joinPlace(java.lang.String Community, java.lang.String place, java.lang.String pwd)
public int joinPlace(java.lang.String place, java.lang.String pwd)
public KernelAddress getAgencyNamed(java.lang.String name)
protected final void exitImmediatlyOnKill()
live
method)
the Kernel will try a Thread.stop on it. And the Thread problem is that this method is currently unsafe and does not work
every time.
The result is that the agent has been killed, that is to say removed from organizations and invisible to others (no more messages), but its thread is still alive with unpredictable behaviors, wasting cpu time.
The sun API says : Most uses of stop should be replaced by code that simply modifies some variable to indicate that the target thread should stop running. The target thread should check this variable regularly, and return from its run method in an orderly fashion if the variable indicates that it is to stop running. (This is the approach that JavaSoft's Tutorial has always recommended.)
In MadKit, agents are autonomous :)
So it is the developer responsibility to be sure that an agent cleanly exits its thread when killed.
The exitImmediatlyOnKill
method is made to ease this procedure.
When a dead agent, which has been killed, calls this method, its thread immediately exits if it is still running, avoiding unpredictable behavior
For example this kind of agent may not be able to be cleanly killed by another due to its simplicity (no wait, no pause).
public void live() { int i=0; while(true) //UNSAFE i++; }
public void live() { int i=0; while(true) { exitImmediatlyOnKill(); //SAFE i++; } }
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |