bdi4jade
Changes
bdi-jade/src/bdi4jade/core/Intention.java 13(+10 -3)
Details
bdi-jade/src/bdi4jade/core/Intention.java 13(+10 -3)
diff --git a/bdi-jade/src/bdi4jade/core/Intention.java b/bdi-jade/src/bdi4jade/core/Intention.java
index 917a282..130e485 100644
--- a/bdi-jade/src/bdi4jade/core/Intention.java
+++ b/bdi-jade/src/bdi4jade/core/Intention.java
@@ -226,8 +226,7 @@ public class Intention {
break;
case TRYING_TO_ACHIEVE:
this.waiting = true;
- this.currentPlan.stop();
- this.currentPlan = null;
+ this.currentPlan.block();
break;
case PLAN_FAILED:
this.waiting = true;
@@ -325,6 +324,10 @@ public class Intention {
switch (status) {
case WAITING:
this.noLongerDesired = true;
+ if (currentPlan != null) {
+ this.currentPlan.stop();
+ this.currentPlan = null;
+ }
break;
case TRYING_TO_ACHIEVE:
this.noLongerDesired = true;
@@ -367,7 +370,11 @@ public class Intention {
break;
case WAITING:
this.waiting = false;
- dispatchPlan();
+ if (currentPlan != null) {
+ this.currentPlan.restart();
+ } else {
+ dispatchPlan();
+ }
break;
case PLAN_FAILED:
this.executedPlans.add(this.currentPlan.getPlan());
diff --git a/bdi-jade/src/bdi4jade/plan/planbody/PlanBody.java b/bdi-jade/src/bdi4jade/plan/planbody/PlanBody.java
index dff3fb8..22f8836 100644
--- a/bdi-jade/src/bdi4jade/plan/planbody/PlanBody.java
+++ b/bdi-jade/src/bdi4jade/plan/planbody/PlanBody.java
@@ -48,6 +48,21 @@ import bdi4jade.plan.Plan.EndState;
public interface PlanBody extends GoalListener {
/**
+ * Blocks this behaviour. It should be noticed that this method is NOT a
+ * blocking call: when it is invoked, the internal behaviour state is set to
+ * Blocked so that, as soon as the action() method returns, the behaviour is
+ * put into a blocked behaviours queue so that it will not be scheduled
+ * anymore. The behaviour is moved back in the pool of active behaviours
+ * when either a message is received or the behaviour is explicitly
+ * restarted by means of its restart() method. If this behaviour is a child
+ * of a CompositeBehaviour a suitable event is fired to notify its parent
+ * behaviour up to the behaviour composition hierarchy root.
+ *
+ * @see Behaviour#block()
+ */
+ public void block();
+
+ /**
* Dispatches a goal to be achieved. It is added as a top level agent goal,
* that is, the dispatched goal is independent of the goal that this plan
* body is trying to achieve.
@@ -169,8 +184,6 @@ public interface PlanBody extends GoalListener {
* body. Note that onEnd is called after the plan body has already stopped
* its execution.
*
- * @see Behaviour#onEnd()
- *
* @return an integer code representing the termination value of the
* behaviour.
*
@@ -197,6 +210,17 @@ public interface PlanBody extends GoalListener {
public void reset();
/**
+ * Restarts a blocked behaviour. This method fires a suitable event to
+ * notify this behaviour's parent. When the agent scheduler inserts a
+ * blocked event back into the agent ready queue, it restarts it
+ * automatically. When this method is called, any timer associated with this
+ * behaviour object is cleared.
+ *
+ * @see Behaviour#restart()
+ */
+ public void restart();
+
+ /**
* Starts the execution of a plan body, a {@link Behaviour}, associated with
* this plan.
*/