Details
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/domain/CO.java b/bdi-jade-test/src/bdi4jade/examples/undo/domain/CO.java
new file mode 100644
index 0000000..b964ca0
--- /dev/null
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/domain/CO.java
@@ -0,0 +1,38 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2011 Ingrid Nunes
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+
+package bdi4jade.examples.undo.domain;
+
+import java.io.Serializable;
+
+import jade.content.Concept;
+import jade.content.ContentElement;
+
+/**
+ * @author jgfaccin
+ *
+ */
+public class CO implements Serializable, Concept, ContentElement {
+
+ private static final long serialVersionUID = 2426152760359289784L;
+
+}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/Abnormal.java b/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/Abnormal.java
index a9576a5..6088370 100644
--- a/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/Abnormal.java
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/Abnormal.java
@@ -1,16 +1,17 @@
package bdi4jade.examples.undo.domain.predicate;
+import bdi4jade.examples.undo.domain.CO;
import bdi4jade.extension.remediation.logics.UnaryPredicate;
/**
* @author jgfaccin
*
*/
-public class Abnormal extends UnaryPredicate<String> {
+public class Abnormal extends UnaryPredicate<CO> {
private static final long serialVersionUID = 3585281441119434642L;
- public Abnormal(String concept) {
- super(concept);
+ public Abnormal(CO co) {
+ super(co);
}
}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/Leak.java b/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/Leak.java
index 6cf65a5..b42de95 100644
--- a/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/Leak.java
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/Leak.java
@@ -1,17 +1,18 @@
package bdi4jade.examples.undo.domain.predicate;
+import bdi4jade.examples.undo.domain.WaterHeater;
import bdi4jade.extension.remediation.logics.UnaryPredicate;
/**
* @author jgfaccin
*
*/
-public class Leak extends UnaryPredicate<String> {
+public class Leak extends UnaryPredicate<WaterHeater> {
private static final long serialVersionUID = 5258088447456078315L;
- public Leak(String concept) {
- super(concept);
+ public Leak(WaterHeater waterHeater) {
+ super(waterHeater);
}
}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/Locked.java b/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/Locked.java
index 33cb5d4..d89ca96 100644
--- a/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/Locked.java
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/Locked.java
@@ -1,17 +1,18 @@
package bdi4jade.examples.undo.domain.predicate;
+import bdi4jade.examples.undo.domain.Door;
import bdi4jade.extension.remediation.logics.UnaryPredicate;
/**
* @author jgfaccin
*
*/
-public class Locked extends UnaryPredicate<String> {
+public class Locked extends UnaryPredicate<Door> {
private static final long serialVersionUID = -761337311336588990L;
- public Locked(String concept) {
- super(concept);
+ public Locked(Door door) {
+ super(door);
}
}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/On.java b/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/On.java
index 99e99b1..b79a9bb 100644
--- a/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/On.java
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/On.java
@@ -1,16 +1,17 @@
package bdi4jade.examples.undo.domain.predicate;
+import bdi4jade.examples.undo.domain.Device;
import bdi4jade.extension.remediation.logics.UnaryPredicate;
/**
* @author jgfaccin
*
*/
-public class On extends UnaryPredicate<String> {
+public class On extends UnaryPredicate<Device> {
private static final long serialVersionUID = -6789201413463229769L;
- public On(String concept) {
- super(concept);
+ public On(Device device) {
+ super(device);
}
}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/Open.java b/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/Open.java
index 61178b6..6a15ceb 100644
--- a/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/Open.java
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/Open.java
@@ -1,17 +1,18 @@
package bdi4jade.examples.undo.domain.predicate;
+import bdi4jade.examples.undo.domain.Window;
import bdi4jade.extension.remediation.logics.UnaryPredicate;
/**
* @author jgfaccin
*
*/
-public class Open extends UnaryPredicate<String> {
+public class Open extends UnaryPredicate<Window> {
private static final long serialVersionUID = -235923477441751683L;
- public Open(String concept) {
- super(concept);
+ public Open(Window window) {
+ super(window);
}
}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/TakeOff.java b/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/TakeOff.java
index c9f95b3..27f3e54 100644
--- a/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/TakeOff.java
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/domain/predicate/TakeOff.java
@@ -1,17 +1,18 @@
package bdi4jade.examples.undo.domain.predicate;
+import bdi4jade.examples.undo.domain.Alarm;
import bdi4jade.extension.remediation.logics.UnaryPredicate;
/**
* @author jgfaccin
*
*/
-public class TakeOff extends UnaryPredicate<String> {
+public class TakeOff extends UnaryPredicate<Alarm> {
private static final long serialVersionUID = -2757310546447891714L;
- public TakeOff(String concept) {
- super(concept);
+ public TakeOff(Alarm alarm) {
+ super(alarm);
}
}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/plan/AnswerRequestPlanBody.java b/bdi-jade-test/src/bdi4jade/examples/undo/plan/AnswerRequestPlanBody.java
new file mode 100644
index 0000000..50169c7
--- /dev/null
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/plan/AnswerRequestPlanBody.java
@@ -0,0 +1,50 @@
+package bdi4jade.examples.undo.plan;
+
+import java.util.Random;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import bdi4jade.annotation.Parameter;
+import bdi4jade.annotation.Parameter.Direction;
+import bdi4jade.plan.Plan.EndState;
+import bdi4jade.plan.planbody.AbstractPlanBody;
+import jade.lang.acl.ACLMessage;
+
+/**
+ * @author jgfaccin
+ *
+ */
+public class AnswerRequestPlanBody extends AbstractPlanBody {
+
+ private static final long serialVersionUID = -3625377753974076464L;
+
+ private static final Log log = LogFactory.getLog(AnswerRequestPlanBody.class);
+ public static final String SUCCEEDED = "SUCCEEDED";
+
+ private ACLMessage requestMsg;
+
+ @Override
+ public void action() {
+ try {
+ log.info("Request received from agent " + requestMsg.getSender().getName() + "!");
+ ACLMessage reply = requestMsg.createReply();
+ reply.setContent(SUCCEEDED);
+
+ Random random = new Random(System.currentTimeMillis());
+ Thread.sleep(random.nextInt(10) * 1000);
+
+ this.myAgent.send(reply);
+ log.info("Reply sent to agent " + requestMsg.getSender().getName() + "!");
+ setEndState(EndState.SUCCESSFUL);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Parameter(direction = Direction.IN)
+ public void setMessage(ACLMessage requestMsg) {
+ this.requestMsg = requestMsg;
+ }
+
+}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestAlarmShutdownPlanBody.java b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestAlarmShutdownPlanBody.java
new file mode 100644
index 0000000..0cf9785
--- /dev/null
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestAlarmShutdownPlanBody.java
@@ -0,0 +1,92 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2011 Ingrid Nunes
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+
+package bdi4jade.examples.undo.plan.request;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import bdi4jade.belief.Belief;
+import bdi4jade.belief.PredicateBelief;
+import bdi4jade.examples.undo.domain.Alarm;
+import bdi4jade.examples.undo.plan.AnswerRequestPlanBody;
+import bdi4jade.extension.undo.RevertingPlanBody;
+import bdi4jade.plan.Plan.EndState;
+import jade.core.AID;
+import jade.lang.acl.ACLMessage;
+import jade.lang.acl.MessageTemplate;
+
+/**
+ * @author jgfaccin
+ *
+ */
+public class RequestAlarmShutdownPlanBody extends RevertingPlanBody {
+
+ private static final long serialVersionUID = -5910930807426504278L;
+
+ private static final Log log = LogFactory.getLog(RequestAlarmShutdownPlanBody.class);
+
+ public static final String MSG_CONTENT = "ALARM_SHUTDOWN";
+
+ private MessageTemplate mt;
+ private boolean sent = false;
+
+ @bdi4jade.annotation.Belief
+ private Belief<String, String> neighbour;
+ @bdi4jade.annotation.Belief
+ private PredicateBelief<Alarm> alarmTakeOff;
+
+ @Override
+ protected void execute() {
+ if (!sent) {
+ ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
+ msg.setContent(MSG_CONTENT);
+ msg.addReceiver(new AID(neighbour.getValue(), false));
+ msg.setConversationId("cin" + System.currentTimeMillis());
+ myAgent.send(msg);
+ this.mt = MessageTemplate.and(MessageTemplate.MatchConversationId(msg.getConversationId()),
+ MessageTemplate.MatchInReplyTo(msg.getReplyWith()));
+ this.sent = true;
+ log.info("Request sent to agent " + neighbour.getValue() + "!");
+ } else {
+ ACLMessage reply = myAgent.receive(mt);
+ if (reply != null) {
+ if (reply.getContent().equals(AnswerRequestPlanBody.SUCCEEDED)) {
+ alarmTakeOff.setValue(Boolean.FALSE, this.getGoal());
+ log.info(reply.getSender() + ": " + reply.getContent());
+ setEndState(EndState.SUCCESSFUL);
+ } else {
+ this.sent = false;
+ }
+ } else {
+ block();
+ }
+ }
+ }
+
+ @Override
+ public int onEnd() {
+ this.sent = false;
+ return super.onEnd();
+ }
+
+}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestAlarmTakeOffPlanBody.java b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestAlarmTakeOffPlanBody.java
new file mode 100644
index 0000000..7d3efcf
--- /dev/null
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestAlarmTakeOffPlanBody.java
@@ -0,0 +1,69 @@
+package bdi4jade.examples.undo.plan.request;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import bdi4jade.belief.Belief;
+import bdi4jade.belief.PredicateBelief;
+import bdi4jade.examples.undo.domain.Alarm;
+import bdi4jade.examples.undo.plan.AnswerRequestPlanBody;
+import bdi4jade.extension.undo.RevertingPlanBody;
+import bdi4jade.plan.Plan.EndState;
+import jade.core.AID;
+import jade.lang.acl.ACLMessage;
+import jade.lang.acl.MessageTemplate;
+
+/**
+ * @author jgfaccin
+ *
+ */
+public class RequestAlarmTakeOffPlanBody extends RevertingPlanBody {
+
+ private static final long serialVersionUID = -2892045378277486902L;
+
+ private static final Log log = LogFactory.getLog(RequestAlarmTakeOffPlanBody.class);
+
+ public static final String MSG_CONTENT = "ALARM_TAKE_OFF";
+
+ private MessageTemplate mt;
+ private boolean sent = false;
+
+ @bdi4jade.annotation.Belief
+ private Belief<String, String> neighbour;
+ @bdi4jade.annotation.Belief
+ private PredicateBelief<Alarm> alarmTakeOff;
+
+ @Override
+ protected void execute() {
+ if (!sent) {
+ ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
+ msg.setContent(MSG_CONTENT);
+ msg.addReceiver(new AID(neighbour.getValue(), false));
+ msg.setConversationId("cin" + System.currentTimeMillis());
+ myAgent.send(msg);
+ this.mt = MessageTemplate.and(MessageTemplate.MatchConversationId(msg.getConversationId()),
+ MessageTemplate.MatchInReplyTo(msg.getReplyWith()));
+ this.sent = true;
+ log.info("Request sent to agent " + neighbour.getValue() + "!");
+ } else {
+ ACLMessage reply = myAgent.receive(mt);
+ if (reply != null) {
+ if (reply.getContent().equals(AnswerRequestPlanBody.SUCCEEDED)) {
+ alarmTakeOff.setValue(Boolean.TRUE, this.getGoal());
+ log.info(reply.getSender() + ": " + reply.getContent());
+ setEndState(EndState.SUCCESSFUL);
+ } else {
+ this.sent = false;
+ }
+ } else {
+ block();
+ }
+ }
+ }
+
+ @Override
+ public int onEnd() {
+ this.sent = false;
+ return super.onEnd();
+ }
+}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestCloseValvePlanBody.java b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestCloseValvePlanBody.java
new file mode 100644
index 0000000..93f221e
--- /dev/null
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestCloseValvePlanBody.java
@@ -0,0 +1,70 @@
+package bdi4jade.examples.undo.plan.request;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import bdi4jade.belief.Belief;
+import bdi4jade.belief.PredicateBelief;
+import bdi4jade.examples.undo.domain.Alarm;
+import bdi4jade.examples.undo.plan.AnswerRequestPlanBody;
+import bdi4jade.extension.undo.RevertingPlanBody;
+import bdi4jade.plan.Plan.EndState;
+import jade.core.AID;
+import jade.lang.acl.ACLMessage;
+import jade.lang.acl.MessageTemplate;
+
+/**
+ * @author jgfaccin
+ *
+ */
+public class RequestCloseValvePlanBody extends RevertingPlanBody {
+
+ private static final long serialVersionUID = -4460070890955780068L;
+
+ private static final Log log = LogFactory.getLog(RequestCloseValvePlanBody.class);
+
+ public static final String MSG_CONTENT = "VALVE_CLOSE";
+
+ private MessageTemplate mt;
+ private boolean sent = false;
+
+ @bdi4jade.annotation.Belief
+ private Belief<String, String> neighbour;
+ @bdi4jade.annotation.Belief
+ private PredicateBelief<Alarm> valveClose;
+
+ @Override
+ protected void execute() {
+ if (!sent) {
+ ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
+ msg.setContent(MSG_CONTENT);
+ msg.addReceiver(new AID(neighbour.getValue(), false));
+ msg.setConversationId("cin" + System.currentTimeMillis());
+ myAgent.send(msg);
+ this.mt = MessageTemplate.and(MessageTemplate.MatchConversationId(msg.getConversationId()),
+ MessageTemplate.MatchInReplyTo(msg.getReplyWith()));
+ this.sent = true;
+ log.info("Request sent to agent " + neighbour.getValue() + "!");
+ } else {
+ ACLMessage reply = myAgent.receive(mt);
+ if (reply != null) {
+ if (reply.getContent().equals(AnswerRequestPlanBody.SUCCEEDED)) {
+ valveClose.setValue(Boolean.TRUE, this.getGoal());
+ log.info(reply.getSender() + ": " + reply.getContent());
+ setEndState(EndState.SUCCESSFUL);
+ } else {
+ this.sent = false;
+ }
+ } else {
+ block();
+ }
+ }
+ }
+
+ @Override
+ public int onEnd() {
+ this.sent = false;
+ return super.onEnd();
+ }
+
+}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestDoorsLockPlanBody.java b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestDoorsLockPlanBody.java
new file mode 100644
index 0000000..03aad36
--- /dev/null
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestDoorsLockPlanBody.java
@@ -0,0 +1,92 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2011 Ingrid Nunes
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+
+package bdi4jade.examples.undo.plan.request;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import bdi4jade.belief.Belief;
+import bdi4jade.belief.PredicateBelief;
+import bdi4jade.examples.undo.domain.Alarm;
+import bdi4jade.examples.undo.plan.AnswerRequestPlanBody;
+import bdi4jade.extension.undo.RevertingPlanBody;
+import bdi4jade.plan.Plan.EndState;
+import jade.core.AID;
+import jade.lang.acl.ACLMessage;
+import jade.lang.acl.MessageTemplate;
+
+/**
+ * @author jgfaccin
+ *
+ */
+public class RequestDoorsLockPlanBody extends RevertingPlanBody {
+
+ private static final long serialVersionUID = -8074373602287820071L;
+
+ private static final Log log = LogFactory.getLog(RequestDoorsLockPlanBody.class);
+
+ public static final String MSG_CONTENT = "DOORS_LOCK";
+
+ private MessageTemplate mt;
+ private boolean sent = false;
+
+ @bdi4jade.annotation.Belief
+ private Belief<String, String> neighbour;
+ @bdi4jade.annotation.Belief
+ private PredicateBelief<Alarm> doorsUnlock;
+
+ @Override
+ protected void execute() {
+ if (!sent) {
+ ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
+ msg.setContent(MSG_CONTENT);
+ msg.addReceiver(new AID(neighbour.getValue(), false));
+ msg.setConversationId("cin" + System.currentTimeMillis());
+ myAgent.send(msg);
+ this.mt = MessageTemplate.and(MessageTemplate.MatchConversationId(msg.getConversationId()),
+ MessageTemplate.MatchInReplyTo(msg.getReplyWith()));
+ this.sent = true;
+ log.info("Request sent to agent " + neighbour.getValue() + "!");
+ } else {
+ ACLMessage reply = myAgent.receive(mt);
+ if (reply != null) {
+ if (reply.getContent().equals(AnswerRequestPlanBody.SUCCEEDED)) {
+ doorsUnlock.setValue(Boolean.FALSE, this.getGoal());
+ log.info(reply.getSender() + ": " + reply.getContent());
+ setEndState(EndState.SUCCESSFUL);
+ } else {
+ this.sent = false;
+ }
+ } else {
+ block();
+ }
+ }
+ }
+
+ @Override
+ public int onEnd() {
+ this.sent = false;
+ return super.onEnd();
+ }
+
+}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestDoorsUnlockPlanBody.java b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestDoorsUnlockPlanBody.java
new file mode 100644
index 0000000..8ee65a9
--- /dev/null
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestDoorsUnlockPlanBody.java
@@ -0,0 +1,70 @@
+package bdi4jade.examples.undo.plan.request;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import bdi4jade.belief.Belief;
+import bdi4jade.belief.PredicateBelief;
+import bdi4jade.examples.undo.domain.Alarm;
+import bdi4jade.examples.undo.plan.AnswerRequestPlanBody;
+import bdi4jade.extension.undo.RevertingPlanBody;
+import bdi4jade.plan.Plan.EndState;
+import jade.core.AID;
+import jade.lang.acl.ACLMessage;
+import jade.lang.acl.MessageTemplate;
+
+/**
+ * @author jgfaccin
+ *
+ */
+public class RequestDoorsUnlockPlanBody extends RevertingPlanBody {
+
+ private static final long serialVersionUID = 1956459046559097703L;
+
+ private static final Log log = LogFactory.getLog(RequestDoorsUnlockPlanBody.class);
+
+ public static final String MSG_CONTENT = "DOORS_UNLOCK";
+
+ private MessageTemplate mt;
+ private boolean sent = false;
+
+ @bdi4jade.annotation.Belief
+ private Belief<String, String> neighbour;
+ @bdi4jade.annotation.Belief
+ private PredicateBelief<Alarm> doorsUnlock;
+
+ @Override
+ protected void execute() {
+ if (!sent) {
+ ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
+ msg.setContent(MSG_CONTENT);
+ msg.addReceiver(new AID(neighbour.getValue(), false));
+ msg.setConversationId("cin" + System.currentTimeMillis());
+ myAgent.send(msg);
+ this.mt = MessageTemplate.and(MessageTemplate.MatchConversationId(msg.getConversationId()),
+ MessageTemplate.MatchInReplyTo(msg.getReplyWith()));
+ this.sent = true;
+ log.info("Request sent to agent " + neighbour.getValue() + "!");
+ } else {
+ ACLMessage reply = myAgent.receive(mt);
+ if (reply != null) {
+ if (reply.getContent().equals(AnswerRequestPlanBody.SUCCEEDED)) {
+ doorsUnlock.setValue(Boolean.TRUE, this.getGoal());
+ log.info(reply.getSender() + ": " + reply.getContent());
+ setEndState(EndState.SUCCESSFUL);
+ } else {
+ this.sent = false;
+ }
+ } else {
+ block();
+ }
+ }
+ }
+
+ @Override
+ public int onEnd() {
+ this.sent = false;
+ return super.onEnd();
+ }
+
+}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestFansOffPlanBody.java b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestFansOffPlanBody.java
new file mode 100644
index 0000000..ce40e1d
--- /dev/null
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestFansOffPlanBody.java
@@ -0,0 +1,91 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2011 Ingrid Nunes
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+
+package bdi4jade.examples.undo.plan.request;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import bdi4jade.belief.Belief;
+import bdi4jade.belief.PredicateBelief;
+import bdi4jade.examples.undo.domain.Alarm;
+import bdi4jade.examples.undo.plan.AnswerRequestPlanBody;
+import bdi4jade.extension.undo.RevertingPlanBody;
+import bdi4jade.plan.Plan.EndState;
+import jade.core.AID;
+import jade.lang.acl.ACLMessage;
+import jade.lang.acl.MessageTemplate;
+
+/**
+ * @author jgfaccin
+ *
+ */
+public class RequestFansOffPlanBody extends RevertingPlanBody {
+
+ private static final long serialVersionUID = -3091070375458975704L;
+
+ private static final Log log = LogFactory.getLog(RequestFansOffPlanBody.class);
+
+ public static final String MSG_CONTENT = "FANS_ON";
+
+ private MessageTemplate mt;
+ private boolean sent = false;
+
+ @bdi4jade.annotation.Belief
+ private Belief<String, String> neighbour;
+ @bdi4jade.annotation.Belief
+ private PredicateBelief<Alarm> fansOn;
+
+ @Override
+ protected void execute() {
+ if (!sent) {
+ ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
+ msg.setContent(MSG_CONTENT);
+ msg.addReceiver(new AID(neighbour.getValue(), false));
+ msg.setConversationId("cin" + System.currentTimeMillis());
+ myAgent.send(msg);
+ this.mt = MessageTemplate.and(MessageTemplate.MatchConversationId(msg.getConversationId()),
+ MessageTemplate.MatchInReplyTo(msg.getReplyWith()));
+ this.sent = true;
+ log.info("Request sent to agent " + neighbour.getValue() + "!");
+ } else {
+ ACLMessage reply = myAgent.receive(mt);
+ if (reply != null) {
+ if (reply.getContent().equals(AnswerRequestPlanBody.SUCCEEDED)) {
+ fansOn.setValue(Boolean.FALSE, this.getGoal());
+ log.info(reply.getSender() + ": " + reply.getContent());
+ setEndState(EndState.SUCCESSFUL);
+ } else {
+ this.sent = false;
+ }
+ } else {
+ block();
+ }
+ }
+ }
+
+ @Override
+ public int onEnd() {
+ this.sent = false;
+ return super.onEnd();
+ }
+}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestFansOnPlanBody.java b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestFansOnPlanBody.java
new file mode 100644
index 0000000..58d4259
--- /dev/null
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestFansOnPlanBody.java
@@ -0,0 +1,69 @@
+package bdi4jade.examples.undo.plan.request;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import bdi4jade.belief.Belief;
+import bdi4jade.belief.PredicateBelief;
+import bdi4jade.examples.undo.domain.Alarm;
+import bdi4jade.examples.undo.plan.AnswerRequestPlanBody;
+import bdi4jade.extension.undo.RevertingPlanBody;
+import bdi4jade.plan.Plan.EndState;
+import jade.core.AID;
+import jade.lang.acl.ACLMessage;
+import jade.lang.acl.MessageTemplate;
+
+/**
+ * @author jgfaccin
+ *
+ */
+public class RequestFansOnPlanBody extends RevertingPlanBody {
+
+ private static final long serialVersionUID = 6823219775966702413L;
+
+ private static final Log log = LogFactory.getLog(RequestFansOnPlanBody.class);
+
+ public static final String MSG_CONTENT = "FANS_ON";
+
+ private MessageTemplate mt;
+ private boolean sent = false;
+
+ @bdi4jade.annotation.Belief
+ private Belief<String, String> neighbour;
+ @bdi4jade.annotation.Belief
+ private PredicateBelief<Alarm> fansOn;
+
+ @Override
+ protected void execute() {
+ if (!sent) {
+ ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
+ msg.setContent(MSG_CONTENT);
+ msg.addReceiver(new AID(neighbour.getValue(), false));
+ msg.setConversationId("cin" + System.currentTimeMillis());
+ myAgent.send(msg);
+ this.mt = MessageTemplate.and(MessageTemplate.MatchConversationId(msg.getConversationId()),
+ MessageTemplate.MatchInReplyTo(msg.getReplyWith()));
+ this.sent = true;
+ log.info("Request sent to agent " + neighbour.getValue() + "!");
+ } else {
+ ACLMessage reply = myAgent.receive(mt);
+ if (reply != null) {
+ if (reply.getContent().equals(AnswerRequestPlanBody.SUCCEEDED)) {
+ fansOn.setValue(Boolean.TRUE, this.getGoal());
+ log.info(reply.getSender() + ": " + reply.getContent());
+ setEndState(EndState.SUCCESSFUL);
+ } else {
+ this.sent = false;
+ }
+ } else {
+ block();
+ }
+ }
+ }
+
+ @Override
+ public int onEnd() {
+ this.sent = false;
+ return super.onEnd();
+ }
+}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestLightsOffPlanBody.java b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestLightsOffPlanBody.java
new file mode 100644
index 0000000..95a94a8
--- /dev/null
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestLightsOffPlanBody.java
@@ -0,0 +1,92 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2011 Ingrid Nunes
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+
+package bdi4jade.examples.undo.plan.request;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import bdi4jade.belief.Belief;
+import bdi4jade.belief.PredicateBelief;
+import bdi4jade.examples.undo.domain.Alarm;
+import bdi4jade.examples.undo.plan.AnswerRequestPlanBody;
+import bdi4jade.extension.undo.RevertingPlanBody;
+import bdi4jade.plan.Plan.EndState;
+import jade.core.AID;
+import jade.lang.acl.ACLMessage;
+import jade.lang.acl.MessageTemplate;
+
+/**
+ * @author jgfaccin
+ *
+ */
+public class RequestLightsOffPlanBody extends RevertingPlanBody {
+
+ private static final long serialVersionUID = 1586377160204597620L;
+
+ private static final Log log = LogFactory.getLog(RequestLightsOffPlanBody.class);
+
+ public static final String MSG_CONTENT = "LIGHTS_ON";
+
+ private MessageTemplate mt;
+ private boolean sent = false;
+
+ @bdi4jade.annotation.Belief
+ private Belief<String, String> neighbour;
+ @bdi4jade.annotation.Belief
+ private PredicateBelief<Alarm> lightsOn;
+
+ @Override
+ protected void execute() {
+ if (!sent) {
+ ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
+ msg.setContent(MSG_CONTENT);
+ msg.addReceiver(new AID(neighbour.getValue(), false));
+ msg.setConversationId("cin" + System.currentTimeMillis());
+ myAgent.send(msg);
+ this.mt = MessageTemplate.and(MessageTemplate.MatchConversationId(msg.getConversationId()),
+ MessageTemplate.MatchInReplyTo(msg.getReplyWith()));
+ this.sent = true;
+ log.info("Request sent to agent " + neighbour.getValue() + "!");
+ } else {
+ ACLMessage reply = myAgent.receive(mt);
+ if (reply != null) {
+ if (reply.getContent().equals(AnswerRequestPlanBody.SUCCEEDED)) {
+ lightsOn.setValue(Boolean.FALSE, this.getGoal());
+ log.info(reply.getSender() + ": " + reply.getContent());
+ setEndState(EndState.SUCCESSFUL);
+ } else {
+ this.sent = false;
+ }
+ } else {
+ block();
+ }
+ }
+ }
+
+ @Override
+ public int onEnd() {
+ this.sent = false;
+ return super.onEnd();
+ }
+
+}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestLightsOnPlanBody.java b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestLightsOnPlanBody.java
new file mode 100644
index 0000000..84f6c08
--- /dev/null
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestLightsOnPlanBody.java
@@ -0,0 +1,70 @@
+package bdi4jade.examples.undo.plan.request;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import bdi4jade.belief.Belief;
+import bdi4jade.belief.PredicateBelief;
+import bdi4jade.examples.undo.domain.Alarm;
+import bdi4jade.examples.undo.plan.AnswerRequestPlanBody;
+import bdi4jade.extension.undo.RevertingPlanBody;
+import bdi4jade.plan.Plan.EndState;
+import jade.core.AID;
+import jade.lang.acl.ACLMessage;
+import jade.lang.acl.MessageTemplate;
+
+/**
+ * @author jgfaccin
+ *
+ */
+public class RequestLightsOnPlanBody extends RevertingPlanBody {
+
+ private static final long serialVersionUID = 6823219775966702413L;
+
+ private static final Log log = LogFactory.getLog(RequestLightsOnPlanBody.class);
+
+ public static final String MSG_CONTENT = "LIGHTS_ON";
+
+ private MessageTemplate mt;
+ private boolean sent = false;
+
+ @bdi4jade.annotation.Belief
+ private Belief<String, String> neighbour;
+ @bdi4jade.annotation.Belief
+ private PredicateBelief<Alarm> lightsOn;
+
+ @Override
+ protected void execute() {
+ if (!sent) {
+ ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
+ msg.setContent(MSG_CONTENT);
+ msg.addReceiver(new AID(neighbour.getValue(), false));
+ msg.setConversationId("cin" + System.currentTimeMillis());
+ myAgent.send(msg);
+ this.mt = MessageTemplate.and(MessageTemplate.MatchConversationId(msg.getConversationId()),
+ MessageTemplate.MatchInReplyTo(msg.getReplyWith()));
+ this.sent = true;
+ log.info("Request sent to agent " + neighbour.getValue() + "!");
+ } else {
+ ACLMessage reply = myAgent.receive(mt);
+ if (reply != null) {
+ if (reply.getContent().equals(AnswerRequestPlanBody.SUCCEEDED)) {
+ lightsOn.setValue(Boolean.TRUE, this.getGoal());
+ log.info(reply.getSender() + ": " + reply.getContent());
+ setEndState(EndState.SUCCESSFUL);
+ } else {
+ this.sent = false;
+ }
+ } else {
+ block();
+ }
+ }
+ }
+
+ @Override
+ public int onEnd() {
+ this.sent = false;
+ return super.onEnd();
+ }
+
+}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestWindowsOpenPlanBody.java b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestWindowsOpenPlanBody.java
new file mode 100644
index 0000000..a6870e1
--- /dev/null
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RequestWindowsOpenPlanBody.java
@@ -0,0 +1,70 @@
+package bdi4jade.examples.undo.plan.request;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import bdi4jade.belief.Belief;
+import bdi4jade.belief.PredicateBelief;
+import bdi4jade.examples.undo.domain.Alarm;
+import bdi4jade.examples.undo.plan.AnswerRequestPlanBody;
+import bdi4jade.extension.undo.RevertingPlanBody;
+import bdi4jade.plan.Plan.EndState;
+import jade.core.AID;
+import jade.lang.acl.ACLMessage;
+import jade.lang.acl.MessageTemplate;
+
+/**
+ * @author jgfaccin
+ *
+ */
+public class RequestWindowsOpenPlanBody extends RevertingPlanBody {
+
+ private static final long serialVersionUID = -349378558297777226L;
+
+ private static final Log log = LogFactory.getLog(RequestWindowsOpenPlanBody.class);
+
+ public static final String MSG_CONTENT = "WINDOWS_OPEN";
+
+ private MessageTemplate mt;
+ private boolean sent = false;
+
+ @bdi4jade.annotation.Belief
+ private Belief<String, String> neighbour;
+ @bdi4jade.annotation.Belief
+ private PredicateBelief<Alarm> windowsOpen;
+
+ @Override
+ protected void execute() {
+ if (!sent) {
+ ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
+ msg.setContent(MSG_CONTENT);
+ msg.addReceiver(new AID(neighbour.getValue(), false));
+ msg.setConversationId("cin" + System.currentTimeMillis());
+ myAgent.send(msg);
+ this.mt = MessageTemplate.and(MessageTemplate.MatchConversationId(msg.getConversationId()),
+ MessageTemplate.MatchInReplyTo(msg.getReplyWith()));
+ this.sent = true;
+ log.info("Request sent to agent " + neighbour.getValue() + "!");
+ } else {
+ ACLMessage reply = myAgent.receive(mt);
+ if (reply != null) {
+ if (reply.getContent().equals(AnswerRequestPlanBody.SUCCEEDED)) {
+ windowsOpen.setValue(Boolean.TRUE, this.getGoal());
+ log.info(reply.getSender() + ": " + reply.getContent());
+ setEndState(EndState.SUCCESSFUL);
+ } else {
+ this.sent = false;
+ }
+ } else {
+ block();
+ }
+ }
+ }
+
+ @Override
+ public int onEnd() {
+ this.sent = false;
+ return super.onEnd();
+ }
+
+}
diff --git a/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RevertingWindowsClosePlanBody.java b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RevertingWindowsClosePlanBody.java
new file mode 100644
index 0000000..31fc22d
--- /dev/null
+++ b/bdi-jade-test/src/bdi4jade/examples/undo/plan/request/RevertingWindowsClosePlanBody.java
@@ -0,0 +1,92 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2011 Ingrid Nunes
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://inf.ufrgs.br/prosoft/bdi4jade/
+//
+//----------------------------------------------------------------------------
+
+package bdi4jade.examples.undo.plan.request;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import bdi4jade.belief.Belief;
+import bdi4jade.belief.PredicateBelief;
+import bdi4jade.examples.undo.domain.Alarm;
+import bdi4jade.examples.undo.plan.AnswerRequestPlanBody;
+import bdi4jade.extension.undo.RevertingPlanBody;
+import bdi4jade.plan.Plan.EndState;
+import jade.core.AID;
+import jade.lang.acl.ACLMessage;
+import jade.lang.acl.MessageTemplate;
+
+/**
+ * @author jgfaccin
+ *
+ */
+public class RevertingWindowsClosePlanBody extends RevertingPlanBody {
+
+ private static final long serialVersionUID = -3897895422901594380L;
+
+ private static final Log log = LogFactory.getLog(RevertingWindowsClosePlanBody.class);
+
+ public static final String MSG_CONTENT = "WINDOWS_OPEN";
+
+ private MessageTemplate mt;
+ private boolean sent = false;
+
+ @bdi4jade.annotation.Belief
+ private Belief<String, String> neighbour;
+ @bdi4jade.annotation.Belief
+ private PredicateBelief<Alarm> windowsOpen;
+
+ @Override
+ protected void execute() {
+ if (!sent) {
+ ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
+ msg.setContent(MSG_CONTENT);
+ msg.addReceiver(new AID(neighbour.getValue(), false));
+ msg.setConversationId("cin" + System.currentTimeMillis());
+ myAgent.send(msg);
+ this.mt = MessageTemplate.and(MessageTemplate.MatchConversationId(msg.getConversationId()),
+ MessageTemplate.MatchInReplyTo(msg.getReplyWith()));
+ this.sent = true;
+ log.info("Request sent to agent " + neighbour.getValue() + "!");
+ } else {
+ ACLMessage reply = myAgent.receive(mt);
+ if (reply != null) {
+ if (reply.getContent().equals(AnswerRequestPlanBody.SUCCEEDED)) {
+ windowsOpen.setValue(Boolean.FALSE, this.getGoal());
+ log.info(reply.getSender() + ": " + reply.getContent());
+ setEndState(EndState.SUCCESSFUL);
+ } else {
+ this.sent = false;
+ }
+ } else {
+ block();
+ }
+ }
+ }
+
+ @Override
+ public int onEnd() {
+ this.sent = false;
+ return super.onEnd();
+ }
+
+}