public abstract class ConcurrentInternalAction extends java.lang.Object implements InternalAction
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 and Description |
---|
ConcurrentInternalAction() |
Modifier and Type | Method and Description |
---|---|
boolean |
canBeUsedInContext()
Return true if the internal action can be used in plans' context
|
void |
destroy() |
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
|
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)
public void destroy() throws java.lang.Exception
destroy
in interface InternalAction
java.lang.Exception