Package jadex.bdi.runtime.impl
Class RPlan
java.lang.Object
jadex.bdi.runtime.impl.RElement
jadex.bdi.runtime.impl.RParameterElement
jadex.bdi.runtime.impl.RPlan
- All Implemented Interfaces:
IElement
,IFinishableElement<Object>
,IInternalPlan
,IParameterElement
,IPlan
,jadex.javaparser.IMapAccess
Runtime element of a plan.
todo: Currently we do not have @PlanParameter. Do we need them?
They are only visible as long as the plan lives, so only plan
conditions could use them.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
static enum
static class
class
static final record
class
Waitque holds events for later processing.Nested classes/interfaces inherited from class jadex.bdi.runtime.impl.RParameterElement
RParameterElement.RParameter, RParameterElement.RParameterSet
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
The atomic flag.protected IPlanBody
The plan body.protected ICandidateInfo
The candidate from which this plan was created.protected int
The wait cnt for rule names.protected Object
The plan has a dispatched element (current goal/event).protected Exception
The plan has exception attribute.jadex.future.Future
<Void> The finished future (if finishing or finished).protected RPlan.PlanLifecycleState
The plan has lifecycle state attribute.The plan listeners.protected RPlan.PlanProcessingState
The plan has processing state attribute (ready or waiting).protected Object
The plan has a reason.protected Object
The result.protected jadex.common.ICommand
<RPlan.ResumeCommandArgs> The blocking resume.protected List
<jadex.common.ICommand<RPlan.ResumeCommandArgs>> The non-blocking resumes.static final ThreadLocal
<RPlan> The rplans for plan threads.The plan has subgoals attribute (hack!!! redundancy to goal_has_parentplan).protected WaitAbstraction
The plan has a wait abstraction attribute.protected RPlan.Waitqueue
The waitqueue.protected WaitAbstraction
The plan has a waitqueue wait abstraction attribute.Fields inherited from class jadex.bdi.runtime.impl.RParameterElement
parameters, parametersets
Fields inherited from class jadex.bdi.runtime.impl.RElement
id, modelelement
-
Constructor Summary
ConstructorsConstructorDescriptionRPlan
(MPlan mplan, ICandidateInfo candidate, Object reason, Map<String, Object> mappingvals, MConfigParameterElement config) Create a new plan. -
Method Summary
Modifier and TypeMethodDescriptionjadex.future.IFuture
<Void> abort()
Abort the plan.void
addListener
(jadex.future.IResultListener<Object> listener) Add a new listener to get notified when the goal is finished.void
addResumeCommand
(jadex.common.ICommand<RPlan.ResumeCommandArgs> rescom) void
addSubgoal
(RGoal subgoal) <T> void
addTimer
(long timeout, RPlan.ResumeCommand<T> rescom) Add a timer to the resume command if timeout is set.protected void
addToWaitqueue
(Object obj) void
Called after unblocking the component thread.<T> void
beforeBlock
(jadex.future.Future<T> fut) Called before blocking the component thread.static RPlan
createRPlan
(MPlan mplan, ICandidateInfo candidate, Object reason, Map<String, Object> binding, MConfigParameterElement config) Create a new rplan based on an mplan.<T,
E> jadex.future.IFuture <E> dispatchSubgoal
(T goal) Dispatch a goal wait for its result.<T,
E> jadex.future.IFuture <E> dispatchSubgoal
(T goal, long timeout) Dispatch a goal wait for its result.void
getBody()
Get the body.Get the candidate.Get the dispatchedelement.Get the exception.Get the name of the element in the fetcher (e.g.Get the lifecycleState.Get the listeners.Get the waitabstraction.Get the pojo plan of a plan.Get the processingState.Get the reason.Get the result.jadex.common.ICommand
<RPlan.ResumeCommandArgs> Get the resumecommand.List
<jadex.common.ICommand<RPlan.ResumeCommandArgs>> Get the resumecommands.protected String
Get the waitabstraction.Get the waitqueue.void
initParameters
(Map<String, Object> vals, MConfigParameterElement config) Create the parameters from model spec.boolean
Test if plan is aborted.boolean
Check if the element is currently part of the agent's reasoning.boolean
isAtomic()
Get the atomic.boolean
isFailed()
Test if element is failed.boolean
Test if goal is finished.boolean
Test, if the plan end state (passed/failed/aborted) is started or done.boolean
isPassed()
Test if plan is passed.boolean
Test if element is succeeded.boolean
isWaitingFor
(Object procelem) Test if the plan is waiting for a process element.boolean
isWaitqueueWaitingFor
(Object procelem) Test if the plan is always waiting for a process element (waitqueue wait).void
Notify the listeners.void
removeListener
(jadex.future.IResultListener<Object> listener) Remove a listener.void
removeResumeCommand
(jadex.common.ICommand<jadex.common.Tuple2<Boolean, Boolean>> rescom) void
removeSubgoal
(RGoal subgoal) void
setAtomic
(boolean atomic) The atomic to set.void
Set the body.void
setCandidate
(ICandidateInfo candidate) Set the candidate.void
setDispatchedElement
(Object dispatchedelement) Set the dispatchedelement.void
setException
(Exception exception) Set the exception.boolean
Start the finishing of the plan.void
setLifecycleState
(RPlan.PlanLifecycleState lifecyclestate) Set the lifecycleState.void
setProcessingState
(RPlan.PlanProcessingState processingstate) Set the processingState.void
Set the result.void
setupEventsRule
(Collection<jadex.rules.eca.EventType> events) Set up a rule for the waitqueue to signal to what kinds of events this plan in principle reacts to.void
setWaitAbstraction
(WaitAbstraction waitabstraction) Set the waitabstraction.protected void
Check if plan is already aborted.jadex.future.IFuture
<Void> waitFor
(long delay) Wait for a delay.jadex.future.IFuture
<jadex.rules.eca.ChangeInfo<?>> waitForBeliefChanged
(String belname) Wait for a belief change.jadex.future.IFuture
<jadex.rules.eca.ChangeInfo<?>> waitForBeliefChanged
(String belname, long timeout) Wait for a belief change.<T> jadex.future.IFuture
<jadex.rules.eca.ChangeInfo<T>> waitForCollectionChange
(String belname, long timeout, jadex.common.IFilter<jadex.rules.eca.ChangeInfo<T>> filter) Wait for a collection change.<T> jadex.future.IFuture
<jadex.rules.eca.ChangeInfo<T>> waitForCollectionChange
(String belname, long timeout, Object id) Wait for a collection change.jadex.future.IFuture
<Void> waitForCondition
(jadex.rules.eca.ICondition cond, String[] events) Wait for a condition.jadex.future.IFuture
<Void> waitForCondition
(jadex.rules.eca.ICondition cond, String[] events, long timeout) Wait for a condition.jadex.future.IFuture
<jadex.rules.eca.ChangeInfo<?>> waitForFactAdded
(String belname) Wait for a fact being added to a belief.jadex.future.IFuture
<jadex.rules.eca.ChangeInfo<?>> waitForFactAdded
(String belname, long timeout) Wait for a fact being added to a belief.jadex.future.IFuture
<jadex.rules.eca.ChangeInfo<?>> waitForFactAddedOrRemoved
(String belname) Wait for a fact being added or removed to a belief.jadex.future.IFuture
<jadex.rules.eca.ChangeInfo<?>> waitForFactAddedOrRemoved
(String belname, long timeout) Wait for a fact being added or removed to a belief.jadex.future.IFuture
<jadex.rules.eca.ChangeInfo<?>> waitForFactChanged
(String belname) Wait for a fact change of a belief.jadex.future.IFuture
<jadex.rules.eca.ChangeInfo<?>> waitForFactChanged
(String belname, long timeout) Wait for a fact change of a belief.jadex.future.IFuture
<jadex.rules.eca.ChangeInfo<?>> waitForFactRemoved
(String belname) Wait for a fact being removed from a belief.jadex.future.IFuture
<jadex.rules.eca.ChangeInfo<?>> waitForFactRemoved
(String belname, long timeout) Wait for a fact being removed from a belief.jadex.future.IFuture
<jadex.rules.eca.ChangeInfo<?>> waitForFactX
(String belname, String[] evtypes, long timeout, jadex.common.IFilter<jadex.rules.eca.ChangeInfo<?>> filter) Wait for a fact being added to a belief..jadex.javaparser.SimpleValueFetcher
wrapFetcher
(jadex.common.IValueFetcher fetcher) Add reason to fetcher.Methods inherited from class jadex.bdi.runtime.impl.RParameterElement
addParameter, addParameterSet, createParameter, createParameter, createParameterSet, createParameterSet, get, getParameter, getParameters, getParameterSet, getParameterSets, getType, hasParameter, hasParameterSet, testWriteOK
Methods inherited from class jadex.bdi.runtime.impl.RElement
getAgent, getCapability, getCount, getId, getMCapability, getModelElement, getRuleSystem, setId, setModelElement, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface jadex.bdi.runtime.IElement
getCount, getModelElement
Methods inherited from interface jadex.bdi.runtime.IParameterElement
getParameter, getParameters, getParameterSet, getParameterSets, getType, hasParameter, hasParameterSet
-
Field Details
-
RPLANS
The rplans for plan threads. -
reason
The plan has a reason. -
dispatchedelement
The plan has a dispatched element (current goal/event). -
subgoals
The plan has subgoals attribute (hack!!! redundancy to goal_has_parentplan). -
waitabstraction
The plan has a wait abstraction attribute. -
waitqueuewa
The plan has a waitqueue wait abstraction attribute. -
waitqueue
The waitqueue. -
resumecommand
The blocking resume. -
resumecommands
The non-blocking resumes. -
exception
The plan has exception attribute. -
result
The result. -
lifecyclestate
The plan has lifecycle state attribute. -
processingstate
The plan has processing state attribute (ready or waiting). -
body
The plan body. -
candidate
The candidate from which this plan was created. Used for tried plans in proc elem. -
listeners
The plan listeners. -
cnt
protected int cntThe wait cnt for rule names. -
atomic
protected boolean atomicThe atomic flag. -
finished
The finished future (if finishing or finished).
-
-
Constructor Details
-
RPlan
public RPlan(MPlan mplan, ICandidateInfo candidate, Object reason, Map<String, Object> mappingvals, MConfigParameterElement config) Create a new plan.
-
-
Method Details
-
createRPlan
public static RPlan createRPlan(MPlan mplan, ICandidateInfo candidate, Object reason, Map<String, Object> binding, MConfigParameterElement config) Create a new rplan based on an mplan. Reason is Object (not RProcessableElement) because it can be also ChangeEvent -
wrapFetcher
public jadex.javaparser.SimpleValueFetcher wrapFetcher(jadex.common.IValueFetcher fetcher) Add reason to fetcher.- Overrides:
wrapFetcher
in classRParameterElement
-
getPojoPlan
Get the pojo plan of a plan.- Returns:
- The pojo plan.
-
initParameters
Create the parameters from model spec.- Overrides:
initParameters
in classRParameterElement
-
getFetcherName
Get the name of the element in the fetcher (e.g. $goal).- Specified by:
getFetcherName
in classRParameterElement
- Returns:
- The element name in the fetcher name.
-
getProcessingState
Get the processingState.- Returns:
- The processingState.
-
setProcessingState
Set the processingState.- Parameters:
processingState
- The processingState to set.
-
getLifecycleState
Get the lifecycleState.- Returns:
- The lifecycleState.
-
setLifecycleState
Set the lifecycleState.- Parameters:
lifecycleState
- The lifecycleState to set.
-
notifyListeners
public void notifyListeners()Notify the listeners. -
addListener
Add a new listener to get notified when the goal is finished.- Specified by:
addListener
in interfaceIFinishableElement<Object>
- Parameters:
listener
- The listener.
-
removeListener
Remove a listener.- Specified by:
removeListener
in interfaceIFinishableElement<Object>
- Parameters:
listener
- The listener.
-
getListeners
Get the listeners.- Returns:
- The listeners.
-
getReason
Get the reason. -
getDispatchedElement
Get the dispatchedelement.- Specified by:
getDispatchedElement
in interfaceIPlan
- Returns:
- The dispatchedelement.
-
setDispatchedElement
Set the dispatchedelement.- Parameters:
dispatchedelement
- The dispatchedelement to set.
-
getException
Get the exception.- Specified by:
getException
in interfaceIFinishableElement<Object>
- Specified by:
getException
in interfaceIInternalPlan
- Returns:
- The exception.
-
setException
Set the exception.- Parameters:
exception
- The exception to set.
-
getBody
Get the body.- Returns:
- The body.
-
setBody
Set the body.- Parameters:
body
- The body to set.
-
getCandidate
Get the candidate.- Specified by:
getCandidate
in interfaceIInternalPlan
- Returns:
- The candidate.
-
setCandidate
Set the candidate.- Parameters:
candidate
- The candidate to set.
-
isWaitingFor
Test if the plan is waiting for a process element. -
getWaitAbstraction
Get the waitabstraction.- Returns:
- The waitabstraction.
-
setWaitAbstraction
Set the waitabstraction.- Parameters:
waitabstraction
- The waitabstraction to set.
-
isWaitqueueWaitingFor
Test if the plan is always waiting for a process element (waitqueue wait). -
getOrCreateWaitqueueWaitAbstraction
Get the waitabstraction.- Returns:
- The waitabstraction.
-
addToWaitqueue
-
getFromWaitqueue
-
isPassed
public boolean isPassed()Description copied from interface:IPlan
Test if plan is passed.- Specified by:
isPassed
in interfaceIInternalPlan
- Specified by:
isPassed
in interfaceIPlan
-
isFailed
public boolean isFailed()Description copied from interface:IFinishableElement
Test if element is failed.- Specified by:
isFailed
in interfaceIFinishableElement<Object>
- Specified by:
isFailed
in interfaceIInternalPlan
- Returns:
- True, if is failed.
-
isAborted
public boolean isAborted()Description copied from interface:IPlan
Test if plan is aborted.- Specified by:
isAborted
in interfaceIInternalPlan
- Specified by:
isAborted
in interfaceIPlan
-
setFinishing
public boolean setFinishing()Start the finishing of the plan. / public void setFinishing() { if(finished!=null) System.out.println("setFini fail: "+finished); assert finished==null; assert getAgent().getFeature(IExecutionFeature.class).isComponentThread(); finished = new Future(); } -
isFinishing
public boolean isFinishing()Test, if the plan end state (passed/failed/aborted) is started or done. -
isFinished
public boolean isFinished()Description copied from interface:IFinishableElement
Test if goal is finished.- Specified by:
isFinished
in interfaceIFinishableElement<Object>
- Returns:
- True, if is finished.
-
addSubgoal
-
removeSubgoal
-
abort
Description copied from interface:IPlan
Abort the plan. -
getWaitqueue
Get the waitqueue.- Returns:
- The waitqueue.
-
waitFor
Wait for a delay. -
dispatchSubgoal
public <T,E> jadex.future.IFuture<E> dispatchSubgoal(T goal) Dispatch a goal wait for its result.- Specified by:
dispatchSubgoal
in interfaceIPlan
-
dispatchSubgoal
public <T,E> jadex.future.IFuture<E> dispatchSubgoal(T goal, long timeout) Dispatch a goal wait for its result.- Specified by:
dispatchSubgoal
in interfaceIPlan
-
waitForFactChanged
Wait for a fact change of a belief.- Specified by:
waitForFactChanged
in interfaceIPlan
-
waitForFactChanged
public jadex.future.IFuture<jadex.rules.eca.ChangeInfo<?>> waitForFactChanged(String belname, long timeout) Wait for a fact change of a belief.- Specified by:
waitForFactChanged
in interfaceIPlan
-
waitForFactAdded
Wait for a fact being added to a belief.- Specified by:
waitForFactAdded
in interfaceIPlan
-
waitForFactAdded
public jadex.future.IFuture<jadex.rules.eca.ChangeInfo<?>> waitForFactAdded(String belname, long timeout) Wait for a fact being added to a belief.- Specified by:
waitForFactAdded
in interfaceIPlan
-
waitForFactRemoved
Wait for a fact being removed from a belief.- Specified by:
waitForFactRemoved
in interfaceIPlan
-
waitForFactRemoved
public jadex.future.IFuture<jadex.rules.eca.ChangeInfo<?>> waitForFactRemoved(String belname, long timeout) Wait for a fact being removed from a belief.- Specified by:
waitForFactRemoved
in interfaceIPlan
-
waitForBeliefChanged
Wait for a belief change.- Specified by:
waitForBeliefChanged
in interfaceIPlan
-
waitForBeliefChanged
public jadex.future.IFuture<jadex.rules.eca.ChangeInfo<?>> waitForBeliefChanged(String belname, long timeout) Wait for a belief change.- Specified by:
waitForBeliefChanged
in interfaceIPlan
-
waitForFactX
public jadex.future.IFuture<jadex.rules.eca.ChangeInfo<?>> waitForFactX(String belname, String[] evtypes, long timeout, jadex.common.IFilter<jadex.rules.eca.ChangeInfo<?>> filter) Wait for a fact being added to a belief.. -
waitForFactAddedOrRemoved
public jadex.future.IFuture<jadex.rules.eca.ChangeInfo<?>> waitForFactAddedOrRemoved(String belname) Wait for a fact being added or removed to a belief.- Specified by:
waitForFactAddedOrRemoved
in interfaceIPlan
-
waitForFactAddedOrRemoved
public jadex.future.IFuture<jadex.rules.eca.ChangeInfo<?>> waitForFactAddedOrRemoved(String belname, long timeout) Wait for a fact being added or removed to a belief.- Specified by:
waitForFactAddedOrRemoved
in interfaceIPlan
-
waitForCollectionChange
public <T> jadex.future.IFuture<jadex.rules.eca.ChangeInfo<T>> waitForCollectionChange(String belname, long timeout, jadex.common.IFilter<jadex.rules.eca.ChangeInfo<T>> filter) Wait for a collection change.- Specified by:
waitForCollectionChange
in interfaceIPlan
-
waitForCollectionChange
public <T> jadex.future.IFuture<jadex.rules.eca.ChangeInfo<T>> waitForCollectionChange(String belname, long timeout, Object id) Wait for a collection change.- Specified by:
waitForCollectionChange
in interfaceIPlan
-
waitForCondition
public jadex.future.IFuture<Void> waitForCondition(jadex.rules.eca.ICondition cond, String[] events) Wait for a condition.- Specified by:
waitForCondition
in interfaceIPlan
-
waitForCondition
public jadex.future.IFuture<Void> waitForCondition(jadex.rules.eca.ICondition cond, String[] events, long timeout) Wait for a condition.- Specified by:
waitForCondition
in interfaceIPlan
-
addTimer
Add a timer to the resume command if timeout is set. -
getRuleName
- Returns:
-
beforeBlock
public <T> void beforeBlock(jadex.future.Future<T> fut) Called before blocking the component thread. -
afterBlock
public void afterBlock()Called after unblocking the component thread. -
testBodyAborted
protected void testBodyAborted()Check if plan is already aborted. -
addResumeCommand
-
removeResumeCommand
-
getResumeCommands
Get the resumecommands.- Returns:
- The resumecommands.
-
getResumeCommand
Get the resumecommand.- Returns:
- The resumecommand.
-
getResult
Get the result.- Returns:
- The result.
-
setResult
Set the result.- Parameters:
result
- The result to set.
-
isAtomic
public boolean isAtomic()Get the atomic.- Returns:
- The atomic
-
setAtomic
public void setAtomic(boolean atomic) The atomic to set.- Parameters:
atomic
- The atomic to set
-
setupEventsRule
Set up a rule for the waitqueue to signal to what kinds of events this plan in principle reacts to. -
isSucceeded
public boolean isSucceeded()Test if element is succeeded.- Specified by:
isSucceeded
in interfaceIFinishableElement<Object>
- Returns:
- True, if is succeeded.
-
isAdopted
public boolean isAdopted()Check if the element is currently part of the agent's reasoning. E.g. the bases are always adopted and all of their contents such as goals, plans and beliefs.- Specified by:
isAdopted
in classRParameterElement
-
executePlan
public void executePlan()
-