|
||||||||||
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 lifecycle, messaging, graphical interface, group and roles management, agent information, ... The agent behavior intentionnaly is *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. after the activate() method has been called 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()
Due to the "Thread problem" (see http://java.sun.com/j2se/1.4/docs/api/index.html for more details) when an agent is killed, by another agent or interface (unvolontary end: whithout exiting of the live method)
the Kernel will try a Thread.stop on it. |
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 for threaded agents. |
void |
pause(int t)
Suspend the agent for a while. |
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, hashCode, notify, notifyAll, toString, 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 millisecondspublic void receiveMessage(Message m)
receiveMessage
in class AbstractAgent
public 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 by 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 developper responsability to be sure that an agent cleanly exit its thread when dying.
The exitImmediatlyOnKill
method is made to easy this procedure.
When a dead agent, that has been killed, calls this method, its thread immediatly exits if it is still running, avoiding to become a "zombie agent"
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(); //SURE CODE
i++;
}
}
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |