|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jason.asSemantics.ConcurrentInternalAction
public abstract class ConcurrentInternalAction
This class can be used in place of DefaultInternalAction to create an IA that suspend the intention while it is being executed. 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. The code of an internal action that extends this class looks like:
public class ...... extends ConcurrentInternalAction { public Object execute(final TransitionSystem ts, Unifier un, final Term[] args) throws Exception { .... final String key = suspendInt(ts, "gui", 5000); // suspend the intention (max 5 seconds) startInternalAction(ts, new Runnable() { // to not block the agent thread, start a thread that performs the task and resume the intention latter public void run() { .... the code of the IA ..... if ( ... all Ok ...) resumeInt(ts, key); // resume the intention with success else failInt(ts, key); // resume the intention with fail } }); ... } public void timeout(TransitionSystem ts, String intentionKey) { // called back when the intention should be resumed/failed by timeout (after 5 seconds in this example) ... this method have to decide what to do with actions finished by timeout: resume or fail ... to call resumeInt(ts,intentionKey) or failInt(ts, intentionKey) } }
Constructor Summary | |
---|---|
ConcurrentInternalAction()
|
Method Summary | |
---|---|
boolean |
canBeUsedInContext()
Return true if the internal action can be used in plans' context |
java.lang.Object |
execute(TransitionSystem ts,
Unifier un,
Term[] args)
Executes the internal action. |
void |
failInt(TransitionSystem ts,
java.lang.String intentionKey)
fails the intention identified by intentionKey |
Term[] |
prepareArguments(Literal body,
Unifier un)
Prepare body's terms to be used in 'execute', normally it consist of cloning and applying each term |
static void |
resume(TransitionSystem ts,
java.lang.String intentionKey,
boolean abort,
java.util.List<Term> failAnnots)
|
void |
resumeInt(TransitionSystem ts,
java.lang.String intentionKey)
resume the intention identified by intentionKey |
void |
startInternalAction(TransitionSystem ts,
java.lang.Runnable code)
|
java.lang.String |
suspendInt(TransitionSystem ts,
java.lang.String basekey,
int timeout)
Suspend the current intention, put it in the PendingIntention (PI) structure and assigns it to a key. |
boolean |
suspendIntention()
Returns true if the internal action (IA) should suspend the intention where the IA is called |
abstract void |
timeout(TransitionSystem ts,
java.lang.String intentionKey)
called back when some intention should be resumed/failed by timeout |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ConcurrentInternalAction()
Method Detail |
---|
public boolean canBeUsedInContext()
InternalAction
canBeUsedInContext
in interface InternalAction
public boolean suspendIntention()
InternalAction
suspendIntention
in interface InternalAction
public Term[] prepareArguments(Literal body, Unifier un)
InternalAction
prepareArguments
in interface InternalAction
public java.lang.Object execute(TransitionSystem ts, Unifier un, Term[] args) throws java.lang.Exception
InternalAction
execute
in interface InternalAction
java.lang.Exception
public java.lang.String suspendInt(TransitionSystem ts, java.lang.String basekey, int timeout)
ts
- the "engine" of the agentbasekey
- the base key to form final key used to get the intention back from PI (e.g. "moise", "cartago", ...)timeout
- the max time the intention will be in PI, the value 0 means until "resume"
public void startInternalAction(TransitionSystem ts, java.lang.Runnable code)
public abstract void timeout(TransitionSystem ts, java.lang.String intentionKey)
public void resumeInt(TransitionSystem ts, java.lang.String intentionKey)
public void failInt(TransitionSystem ts, java.lang.String intentionKey)
public static void resume(TransitionSystem ts, java.lang.String intentionKey, boolean abort, java.util.List<Term> failAnnots)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |