# A Social Multi-Agent Cooperation System Based on Planning and Distributed Task Allocation
## 5 Distributed Task Allocation
### Agent Behavior in JADE  
A behavior represents a task that a participant agent can carry out. A behavior is a kind of control thread for the agent where the method action() is similar to Thread.run(). New behaviors can be added at any time during the agent's life (Figure 4).  
* **Behaviour class:** it is implemented as an object of a class that extends jade.core.behaviours.Behaviour. The Behaviour class is an abstract class having several abstract methods. The _action_ method defines the operation to be performed when the behavior is in execution. The _done_ method returns a boolean value to indicate whether or not a behavior has completed. The Behaviour class also provides two methods, named _onStart_ and _onEnd_. These methods can be overridden by user defined subclasses when some actions are to be executed before and after running behavior execution.
* **SimpleBehaviour class:** it is an abstract class representing simple atomic behaviors (which means it is composed of only one behavior). It can be overridden by user defined subclasses which are OneShotBehaviour and CyclicBehaviour classes.  
* **OneShotBehaviour class:*
* it represents atomic behaviors that must be executed only once and cannot be blocked. Two subclasses inherit from the OneShotBehaviour class, which are the WakerBehaviour and the TickerBehaviour classes.
* The **WakerBehaviour*
* class implements a one-shot task that must be executed only once just after a given timeout has elapsed, which is specified in the _handleElapsedTimeout_ method.
* The **ReceiverBehaviour*
* class, which triggers when a given type of message is received or a timeout expires.
* **CyclicBehaviour class:*
* it models atomic behaviors that must be executed forever. Thus, its _done_ method always returns false. The CyclicBehaviour class represents \"Cyclic\" behaviors that never complete and whose _action_ method executes the same operations each time it is called.
* The **TickerBehaviour*
* class implements a cyclic task that must be executed recurrently. The periodic actions are determined in the _onTick_ method.
* **CompositeBehaviour class:*
* This abstract class models behaviors that are made up of a number of other behaviors (children). Thus, the actual operations performed by executing this behavior are not defined in the behavior itself but inside its children, while the composite behavior only takes care of child scheduling according to a given policy (sequentially for the SequentialBehaviour class, concurrently for the ParallelBehaviour class and as a finite state machine for the FSMBehaviour class).
* class: this behavior controls a set of sub-behaviors that execute in parallel. The most important thing is the termination condition; it is possible to specify the termination of ParallelBehaviour when **all*
* of its sub-behaviors terminate or **any*
* sub-behavior is ended.
* class: this behavior is composed of a set of sub-behaviors where each one is executed after the other. The SequentialBehaviour terminates when all its sub-behaviors have terminated.
* **ReceiverBehaviour class:** a behavior with a timeout that waits until the reception of a message or the elapsing of a given timeout.  
Figure 4. Behavior class hierarchy in JADE.