jade.core.behaviours
Class ThreadedBehaviourFactory
java.lang.Object
|
+--jade.core.behaviours.ThreadedBehaviourFactory
- public class ThreadedBehaviourFactory
- extends java.lang.Object
This class provides support for executing JADE Behaviours
in dedicated Java Threads. In order to do that it is sufficient
to add to an agent a normal JADE Behaviour "wrapped" into
a "threaded behaviour" as returned by the wrap()
method
of this class (see the example below).
ThreadedBehaviourFactory tbf = new ThreadedBehaviourFactory();
Behaviour b = // create a JADE behaviour
addBehaviour(tbf.wrap(b));
This class also provides methods to control the termination of
the threads dedicated to the execution of wrapped behaviours
NOT available in MIDP
- Author:
- Giovanni Caire - TILAB
Method Summary |
java.lang.Thread |
getThread(Behaviour b)
|
Behaviour[] |
getWrappers()
|
void |
interrupt()
Interrupt all threads dedicated to the execution of
wrapped behaviours. |
int |
size()
|
boolean |
waitUntilEmpty(long timeout)
Blocks until all threads dedicated to the execution of threaded
behaviours complete. |
Behaviour |
wrap(Behaviour b)
Wraps a normal JADE Behaviour into a "threaded behaviour" so that
b will be executed by a dedicated Therad. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ThreadedBehaviourFactory
public ThreadedBehaviourFactory()
wrap
public Behaviour wrap(Behaviour b)
- Wraps a normal JADE Behaviour into a "threaded behaviour" so that
b
will be executed by a dedicated Therad.
size
public int size()
- Returns:
- The number of active threads dedicated to the execution of
wrapped behaviours.
interrupt
public void interrupt()
- Interrupt all threads dedicated to the execution of
wrapped behaviours.
waitUntilEmpty
public boolean waitUntilEmpty(long timeout)
- Blocks until all threads dedicated to the execution of threaded
behaviours complete.
- Parameters:
timeout
- The maximum timeout to wait for threaded behaviour
termination.
- Returns:
true
if all threaded behaviour have actually
completed, false
otherwise.
getThread
public java.lang.Thread getThread(Behaviour b)
- Returns:
- the Thread dedicated to the execution of the Behaviour
b
getWrappers
public Behaviour[] getWrappers()
- Returns:
- All the wrapper behaviours currently used by theis ThreadedBehaviourFactory
JADE