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
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
b
into a "threaded behaviour". Adding the
wrapper behaviour to an agent results in executing b
in a dedicated Java Therad.
size
public int size()
- Returns:
- The number of active threads dedicated to the execution of
wrapped behaviours.
interrupt
public void interrupt()
- Interrupt all threaded behaviours managed by this ThreadedBehaviourFactory
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.
interrupt
public java.lang.Thread interrupt(Behaviour b)
throws NotFoundException
- Interrupt a threaded behaviour. This method should be used to abort a threaded behaviour
instead of getThread().interrupt() because i) the latter may have no effect if called just after
the threaded behaviour suspended itself and ii) the threaded behaviour may be suspended
and in this case its Thread is null.
- Returns:
- the Thread that was interrupted if any.
NotFoundException
suspend
public void suspend(Behaviour b)
- Suspend a threaded behaviour. This method has only effect if called by the threaded behaviour
itself and has the effect of releasing its dedicated Java Thread. This can later be restored
by means of the
resume()
method.
resume
public void resume(Behaviour b)
- Resume a threaded behaviour. Assign a new Java Thread to a threaded behaviour that is
currently suspended.
getThread
public java.lang.Thread getThread(Behaviour b)
- Returns:
- the Thread dedicated to the execution of the Behaviour
b
JADE