|
From: <jom...@us...> - 2008-11-02 11:55:05
|
Revision: 1407
http://jason.svn.sourceforge.net/jason/?rev=1407&view=rev
Author: jomifred
Date: 2008-11-02 11:55:03 +0000 (Sun, 02 Nov 2008)
Log Message:
-----------
jason-moise: produce failure events for org. actions with new error annotations.
Modified Paths:
--------------
trunk/applications/jason-moise/example/writePaper/jaime.asl
trunk/applications/jason-moise/src/jmoise/OrgAgent.java
trunk/release-notes.txt
trunk/src/jason/asSemantics/ConcurrentInternalAction.java
trunk/src/jason/asSemantics/TransitionSystem.java
trunk/src/jason/bb/JDBCPersistentBB.java
Modified: trunk/applications/jason-moise/example/writePaper/jaime.asl
===================================================================
--- trunk/applications/jason-moise/example/writePaper/jaime.asl 2008-10-31 10:46:35 UTC (rev 1406)
+++ trunk/applications/jason-moise/example/writePaper/jaime.asl 2008-11-02 11:55:03 UTC (rev 1407)
@@ -15,11 +15,12 @@
// create a group to write a paper
+!create_group : true
<- //.send(orgManager, achieve, create_group(wpgroup)).
- jmoise.create_group(wpgroup,G);
+ jmoise.create_group(wpgroupa,G);
.print("Group ",G," created").
+-!create_group[error_msg(M),code(C),code_line(L)]
+ <- .print("Error creating group, command: ",C,", line ",L,", message: ",M).
-
/* Organisational Events */
/* Structural events */
Modified: trunk/applications/jason-moise/src/jmoise/OrgAgent.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/OrgAgent.java 2008-10-31 10:46:35 UTC (rev 1406)
+++ trunk/applications/jason-moise/src/jmoise/OrgAgent.java 2008-11-02 11:55:03 UTC (rev 1407)
@@ -10,16 +10,16 @@
import jason.asSemantics.Agent;
import jason.asSemantics.Circumstance;
import jason.asSemantics.Event;
+import jason.asSemantics.IntendedMeans;
import jason.asSemantics.Intention;
import jason.asSemantics.Message;
import jason.asSemantics.Unifier;
import jason.asSyntax.ASSyntax;
import jason.asSyntax.Atom;
-import jason.asSyntax.InternalActionLiteral;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.ListTermImpl;
import jason.asSyntax.Literal;
import jason.asSyntax.LiteralImpl;
-import jason.asSyntax.PlanBody;
-import jason.asSyntax.PlanBodyImpl;
import jason.asSyntax.Pred;
import jason.asSyntax.PredicateIndicator;
import jason.asSyntax.Structure;
@@ -27,7 +27,6 @@
import jason.asSyntax.Trigger;
import jason.asSyntax.UnnamedVar;
import jason.asSyntax.VarTerm;
-import jason.asSyntax.PlanBody.BodyType;
import jason.asSyntax.Trigger.TEOperator;
import jason.asSyntax.Trigger.TEType;
import jason.asSyntax.parser.ParseException;
@@ -317,23 +316,32 @@
private void resumeIntention(Intention pi, String content, Circumstance C) {
pi.setSuspended(false);
- C.addIntention(pi); // add it back in I
- Structure body = (Structure)pi.peek().removeCurrentStep(); // remove the internal action
- if (content.startsWith("error")) {
- // fail the IA
- PlanBody pbody = pi.peek().getPlan().getBody();
- Literal fail = new InternalActionLiteral(".fail");
- String msg = content.substring(7,content.length()-2);
- fail.addTerm(createStructure("error_msg", createString(msg)));
- fail.addTerm(createStructure("code", createString(body.toString())));
- if (body.getSrcInfo() != null) {
- fail.addTerm(createStructure("code_src", createString(body.getSrcInfo().getSrcFile())));
- fail.addTerm(createStructure("code_line", createNumber(body.getSrcInfo().getBeginSrcLine())));
+ if (content.startsWith("error")) { // fail the IA
+ IntendedMeans im = pi.peek();
+ Event failEvent = getTS().findEventForFailure(pi, im.getTrigger());
+ if (failEvent != null) {
+ Structure body = (Structure)im.getCurrentStep().getBodyTerm(); // get the internal action
+
+ ListTerm failAnnots = new ListTermImpl(); // create a list of error annotations
+ String msg = content.substring(7,content.length()-2);
+ failAnnots.add(createStructure("error", new Atom("org_error")));
+ failAnnots.add(createStructure("error_msg", createString(msg)));
+ failAnnots.add(createStructure("code", createString(body.toString())));
+ if (body.getSrcInfo() != null) {
+ failAnnots.add(createStructure("code_src", createString(body.getSrcInfo().getSrcFile())));
+ failAnnots.add(createStructure("code_line", createNumber(body.getSrcInfo().getBeginSrcLine())));
+ }
+ failEvent.getTrigger().getLiteral().addAnnots(failAnnots);
+ C.addEvent(failEvent);
+ if (logger.isLoggable(Level.FINE)) logger.fine("Generating goal deletion " + failEvent.getTrigger() + " from goal: " + im.getTrigger());
+ } else {
+ logger.warning("No fail event was generated for " + im.getTrigger());
}
- pbody.add(0, new PlanBodyImpl(BodyType.internalAction, fail));
- //getTS().getLogger().warning("Error in organisational action '"+body+"': "+content);
} else {
+ C.addIntention(pi); // add the intention back in I
+ Structure body = (Structure)pi.peek().removeCurrentStep(); // remove the internal action
+
// try to unify the return value
//System.out.println("answer is "+content+" or "+DefaultTerm.parse(content)+" with body "+body);
// if the last arg of body is a free var
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2008-10-31 10:46:35 UTC (rev 1406)
+++ trunk/release-notes.txt 2008-11-02 11:55:03 UTC (rev 1407)
@@ -31,6 +31,15 @@
. the version of JADE is upgraded to 3.6
+. new base class for internal actions: ConcurrentInternalAction. This
+ class can be used in place of DefaultInternalAction to create an IA
+ that suspend the intention while it is being executed. For example:
+ a plan may ask something to an user and wait the answer. If
+ DefaultInternalAction is used for that, all the agent thread is
+ blocked until the answer. With ConcurrentInternalAction, only the
+ intention using the IA is suspended. See demos/gui/gui1 and the API
+ doc of the new class.
+
New internal actions
. .term2string: transform term into strings and vice-versa.
Modified: trunk/src/jason/asSemantics/ConcurrentInternalAction.java
===================================================================
--- trunk/src/jason/asSemantics/ConcurrentInternalAction.java 2008-10-31 10:46:35 UTC (rev 1406)
+++ trunk/src/jason/asSemantics/ConcurrentInternalAction.java 2008-11-02 11:55:03 UTC (rev 1407)
@@ -15,7 +15,7 @@
Example: a plan may ask something to an user and wait the answer.
If DefaultInternalAction is used for that, all the agent thread is blocked until
- the answer. With SuspendInternalAction, only the intention using the IA is
+ the answer. With ConcurrentInternalAction, only the intention using the IA is
suspended. See demos/gui/gui1.
The code of an internal action that extends this class looks like:
Modified: trunk/src/jason/asSemantics/TransitionSystem.java
===================================================================
--- trunk/src/jason/asSemantics/TransitionSystem.java 2008-10-31 10:46:35 UTC (rev 1406)
+++ trunk/src/jason/asSemantics/TransitionSystem.java 2008-11-02 11:55:03 UTC (rev 1407)
@@ -870,6 +870,8 @@
}
private static final Atom aNOCODE = new Atom("no_code");
+
+ /** add default error annotations (error, error_msg, code, code_src, code_line) in the failure event */
private static void setDefaultFailureAnnots(Event failEvent, Term body, List<Term> failAnnots) {
// add default failure annots
if (failAnnots == null)
Modified: trunk/src/jason/bb/JDBCPersistentBB.java
===================================================================
--- trunk/src/jason/bb/JDBCPersistentBB.java 2008-10-31 10:46:35 UTC (rev 1406)
+++ trunk/src/jason/bb/JDBCPersistentBB.java 2008-11-02 11:55:03 UTC (rev 1407)
@@ -8,6 +8,7 @@
import jason.asSyntax.ListTermImpl;
import jason.asSyntax.Literal;
import jason.asSyntax.LiteralImpl;
+import jason.asSyntax.NumberTerm;
import jason.asSyntax.NumberTermImpl;
import jason.asSyntax.PredicateIndicator;
import jason.asSyntax.StringTerm;
@@ -23,6 +24,7 @@
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
+import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Calendar;
@@ -461,7 +463,6 @@
/** translates the current line of a result set into a Literal */
- @SuppressWarnings("deprecation")
protected Literal resultSetToLiteral(ResultSet rs, PredicateIndicator pi) throws SQLException {
ResultSetMetaData meta = belsDB.get(pi);
boolean isJasonTable = isCreatedByJason(pi);
@@ -482,15 +483,7 @@
break;
case Types.TIMESTAMP:
- Calendar time = Calendar.getInstance();
- time.setTime(rs.getTimestamp(c));
- parsed = ASSyntax.createStructure("timestamp",
- createNumber(time.get(Calendar.YEAR)),
- createNumber(time.get(Calendar.MONTH)),
- createNumber(time.get(Calendar.DAY_OF_MONTH)),
- createNumber(time.get(Calendar.HOUR_OF_DAY)),
- createNumber(time.get(Calendar.MINUTE)),
- createNumber(time.get(Calendar.SECOND)));
+ parsed = timestamp2structure(rs.getTimestamp(c));
break;
default:
@@ -525,6 +518,7 @@
}
return ldb;
}
+
protected String getTableName(Literal l) throws SQLException {
return getTableName(l.getPredicateIndicator());
@@ -610,7 +604,12 @@
if (t.isString()) {
q.append("'" + ((StringTerm) t).getString() + "'");
} else {
- q.append("'" + t.toString() + "'");
+ Timestamp timestamp = structure2timestamp(t);
+ if (timestamp != null) {
+ q.append("TIMESTAMP '" + structure2timestamp(t) + "'");
+ } else {
+ q.append("'" + t.toString() + "'");
+ }
}
if (i < meta.getColumnCount() - 1) {
q.append(",");
@@ -664,4 +663,40 @@
}
}
}
+
+ public static final String timestampFunctor = "timestamp";
+
+ /** translates a SQL timestamp into a structure like "timestamp(Y,M,D,H,M,S)" */
+ public static Structure timestamp2structure(Timestamp timestamp) throws SQLException {
+ Calendar time = Calendar.getInstance();
+ time.setTime(timestamp);
+ return ASSyntax.createStructure(timestampFunctor,
+ createNumber(time.get(Calendar.YEAR)),
+ createNumber(time.get(Calendar.MONTH)),
+ createNumber(time.get(Calendar.DAY_OF_MONTH)),
+ createNumber(time.get(Calendar.HOUR_OF_DAY)),
+ createNumber(time.get(Calendar.MINUTE)),
+ createNumber(time.get(Calendar.SECOND)));
+ }
+
+ /** translates structure like "timestamp(Y,M,D,H,M,S)" into a SQL timestamp */
+ @SuppressWarnings("deprecation")
+ public static Timestamp structure2timestamp(Term timestamp) throws SQLException {
+ if (timestamp.isStructure()) {
+ Structure s = (Structure)timestamp;
+ if (s.getFunctor().equals(timestampFunctor) && s.getArity() == 6) {
+ return new Timestamp(
+ (int)((NumberTerm)s.getTerm(0)).solve() - 1900,
+ (int)((NumberTerm)s.getTerm(1)).solve(),
+ (int)((NumberTerm)s.getTerm(2)).solve(),
+ (int)((NumberTerm)s.getTerm(3)).solve(),
+ (int)((NumberTerm)s.getTerm(4)).solve(),
+ (int)((NumberTerm)s.getTerm(5)).solve(),
+ 0
+ );
+ }
+ }
+ return null;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|