Class RPlan

All Implemented Interfaces:
IElement, IFinishableElement<Object>, IInternalPlan, IParameterElement, IPlan, jadex.javaparser.IMapAccess

public class RPlan extends RParameterElement implements IPlan, IInternalPlan
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.
  • Field Details

    • RPLANS

      public static final ThreadLocal<RPlan> RPLANS
      The rplans for plan threads.
    • reason

      protected Object reason
      The plan has a reason.
    • dispatchedelement

      protected Object dispatchedelement
      The plan has a dispatched element (current goal/event).
    • subgoals

      protected List<RGoal> subgoals
      The plan has subgoals attribute (hack!!! redundancy to goal_has_parentplan).
    • waitabstraction

      protected WaitAbstraction waitabstraction
      The plan has a wait abstraction attribute.
    • waitqueuewa

      protected WaitAbstraction waitqueuewa
      The plan has a waitqueue wait abstraction attribute.
    • waitqueue

      protected RPlan.Waitqueue waitqueue
      The waitqueue.
    • resumecommand

      protected jadex.common.ICommand<RPlan.ResumeCommandArgs> resumecommand
      The blocking resume.
    • resumecommands

      protected List<jadex.common.ICommand<RPlan.ResumeCommandArgs>> resumecommands
      The non-blocking resumes.
    • exception

      protected Exception exception
      The plan has exception attribute.
    • result

      protected Object result
      The result.
    • lifecyclestate

      protected RPlan.PlanLifecycleState lifecyclestate
      The plan has lifecycle state attribute.
    • processingstate

      protected RPlan.PlanProcessingState processingstate
      The plan has processing state attribute (ready or waiting).
    • body

      protected IPlanBody body
      The plan body.
    • candidate

      protected ICandidateInfo candidate
      The candidate from which this plan was created. Used for tried plans in proc elem.
    • listeners

      protected List<jadex.future.IResultListener<Object>> listeners
      The plan listeners.
    • cnt

      protected int cnt
      The wait cnt for rule names.
    • atomic

      protected boolean atomic
      The atomic flag.
    • finished

      public jadex.future.Future<Void> finished
      The finished future (if finishing or finished).
  • Constructor Details

  • 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 class RParameterElement
    • getPojoPlan

      public Object getPojoPlan()
      Get the pojo plan of a plan.
      Returns:
      The pojo plan.
    • initParameters

      public void initParameters(Map<String,Object> vals, MConfigParameterElement config)
      Create the parameters from model spec.
      Overrides:
      initParameters in class RParameterElement
    • getFetcherName

      public String getFetcherName()
      Get the name of the element in the fetcher (e.g. $goal).
      Specified by:
      getFetcherName in class RParameterElement
      Returns:
      The element name in the fetcher name.
    • getProcessingState

      public RPlan.PlanProcessingState getProcessingState()
      Get the processingState.
      Returns:
      The processingState.
    • setProcessingState

      public void setProcessingState(RPlan.PlanProcessingState processingstate)
      Set the processingState.
      Parameters:
      processingState - The processingState to set.
    • getLifecycleState

      public RPlan.PlanLifecycleState getLifecycleState()
      Get the lifecycleState.
      Returns:
      The lifecycleState.
    • setLifecycleState

      public void setLifecycleState(RPlan.PlanLifecycleState lifecyclestate)
      Set the lifecycleState.
      Parameters:
      lifecycleState - The lifecycleState to set.
    • notifyListeners

      public void notifyListeners()
      Notify the listeners.
    • addListener

      public void addListener(jadex.future.IResultListener<Object> listener)
      Add a new listener to get notified when the goal is finished.
      Specified by:
      addListener in interface IFinishableElement<Object>
      Parameters:
      listener - The listener.
    • removeListener

      public void removeListener(jadex.future.IResultListener<Object> listener)
      Remove a listener.
      Specified by:
      removeListener in interface IFinishableElement<Object>
      Parameters:
      listener - The listener.
    • getListeners

      public List<jadex.future.IResultListener<Object>> getListeners()
      Get the listeners.
      Returns:
      The listeners.
    • getReason

      public Object getReason()
      Get the reason.
      Specified by:
      getReason in interface IPlan
      Returns:
      The reason.
    • getDispatchedElement

      public Object getDispatchedElement()
      Get the dispatchedelement.
      Specified by:
      getDispatchedElement in interface IPlan
      Returns:
      The dispatchedelement.
    • setDispatchedElement

      public void setDispatchedElement(Object dispatchedelement)
      Set the dispatchedelement.
      Parameters:
      dispatchedelement - The dispatchedelement to set.
    • getException

      public Exception getException()
      Get the exception.
      Specified by:
      getException in interface IFinishableElement<Object>
      Specified by:
      getException in interface IInternalPlan
      Returns:
      The exception.
    • setException

      public void setException(Exception exception)
      Set the exception.
      Parameters:
      exception - The exception to set.
    • getBody

      public IPlanBody getBody()
      Get the body.
      Returns:
      The body.
    • setBody

      public void setBody(IPlanBody body)
      Set the body.
      Parameters:
      body - The body to set.
    • getCandidate

      public ICandidateInfo getCandidate()
      Get the candidate.
      Specified by:
      getCandidate in interface IInternalPlan
      Returns:
      The candidate.
    • setCandidate

      public void setCandidate(ICandidateInfo candidate)
      Set the candidate.
      Parameters:
      candidate - The candidate to set.
    • isWaitingFor

      public boolean isWaitingFor(Object procelem)
      Test if the plan is waiting for a process element.
    • getWaitAbstraction

      public WaitAbstraction getWaitAbstraction()
      Get the waitabstraction.
      Returns:
      The waitabstraction.
    • setWaitAbstraction

      public void setWaitAbstraction(WaitAbstraction waitabstraction)
      Set the waitabstraction.
      Parameters:
      waitabstraction - The waitabstraction to set.
    • isWaitqueueWaitingFor

      public boolean isWaitqueueWaitingFor(Object procelem)
      Test if the plan is always waiting for a process element (waitqueue wait).
    • getOrCreateWaitqueueWaitAbstraction

      public WaitAbstraction getOrCreateWaitqueueWaitAbstraction()
      Get the waitabstraction.
      Returns:
      The waitabstraction.
    • addToWaitqueue

      protected void addToWaitqueue(Object obj)
    • getFromWaitqueue

      public Object getFromWaitqueue(WaitAbstraction wa)
    • isPassed

      public boolean isPassed()
      Description copied from interface: IPlan
      Test if plan is passed.
      Specified by:
      isPassed in interface IInternalPlan
      Specified by:
      isPassed in interface IPlan
    • isFailed

      public boolean isFailed()
      Description copied from interface: IFinishableElement
      Test if element is failed.
      Specified by:
      isFailed in interface IFinishableElement<Object>
      Specified by:
      isFailed in interface IInternalPlan
      Returns:
      True, if is failed.
    • isAborted

      public boolean isAborted()
      Description copied from interface: IPlan
      Test if plan is aborted.
      Specified by:
      isAborted in interface IInternalPlan
      Specified by:
      isAborted in interface IPlan
    • 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 interface IFinishableElement<Object>
      Returns:
      True, if is finished.
    • addSubgoal

      public void addSubgoal(RGoal subgoal)
    • removeSubgoal

      public void removeSubgoal(RGoal subgoal)
    • abort

      public jadex.future.IFuture<Void> abort()
      Description copied from interface: IPlan
      Abort the plan.
      Specified by:
      abort in interface IPlan
      Returns:
    • getWaitqueue

      public RPlan.Waitqueue getWaitqueue()
      Get the waitqueue.
      Returns:
      The waitqueue.
    • waitFor

      public jadex.future.IFuture<Void> waitFor(long delay)
      Wait for a delay.
      Specified by:
      waitFor in interface IPlan
    • dispatchSubgoal

      public <T, E> jadex.future.IFuture<E> dispatchSubgoal(T goal)
      Dispatch a goal wait for its result.
      Specified by:
      dispatchSubgoal in interface IPlan
    • dispatchSubgoal

      public <T, E> jadex.future.IFuture<E> dispatchSubgoal(T goal, long timeout)
      Dispatch a goal wait for its result.
      Specified by:
      dispatchSubgoal in interface IPlan
    • waitForFactChanged

      public jadex.future.IFuture<jadex.rules.eca.ChangeInfo<?>> waitForFactChanged(String belname)
      Wait for a fact change of a belief.
      Specified by:
      waitForFactChanged in interface IPlan
    • 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 interface IPlan
    • waitForFactAdded

      public jadex.future.IFuture<jadex.rules.eca.ChangeInfo<?>> waitForFactAdded(String belname)
      Wait for a fact being added to a belief.
      Specified by:
      waitForFactAdded in interface IPlan
    • 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 interface IPlan
    • waitForFactRemoved

      public jadex.future.IFuture<jadex.rules.eca.ChangeInfo<?>> waitForFactRemoved(String belname)
      Wait for a fact being removed from a belief.
      Specified by:
      waitForFactRemoved in interface IPlan
    • 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 interface IPlan
    • waitForBeliefChanged

      public jadex.future.IFuture<jadex.rules.eca.ChangeInfo<?>> waitForBeliefChanged(String belname)
      Wait for a belief change.
      Specified by:
      waitForBeliefChanged in interface IPlan
    • waitForBeliefChanged

      public jadex.future.IFuture<jadex.rules.eca.ChangeInfo<?>> waitForBeliefChanged(String belname, long timeout)
      Wait for a belief change.
      Specified by:
      waitForBeliefChanged in interface IPlan
    • 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 interface IPlan
    • 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 interface IPlan
    • 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 interface IPlan
    • 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 interface IPlan
    • waitForCondition

      public jadex.future.IFuture<Void> waitForCondition(jadex.rules.eca.ICondition cond, String[] events)
      Wait for a condition.
      Specified by:
      waitForCondition in interface IPlan
    • waitForCondition

      public jadex.future.IFuture<Void> waitForCondition(jadex.rules.eca.ICondition cond, String[] events, long timeout)
      Wait for a condition.
      Specified by:
      waitForCondition in interface IPlan
    • addTimer

      public <T> void addTimer(long timeout, RPlan.ResumeCommand<T> rescom)
      Add a timer to the resume command if timeout is set.
    • getRuleName

      protected String 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

      public void addResumeCommand(jadex.common.ICommand<RPlan.ResumeCommandArgs> rescom)
    • removeResumeCommand

      public void removeResumeCommand(jadex.common.ICommand<jadex.common.Tuple2<Boolean,Boolean>> rescom)
    • getResumeCommands

      public List<jadex.common.ICommand<RPlan.ResumeCommandArgs>> getResumeCommands()
      Get the resumecommands.
      Returns:
      The resumecommands.
    • getResumeCommand

      public jadex.common.ICommand<RPlan.ResumeCommandArgs> getResumeCommand()
      Get the resumecommand.
      Returns:
      The resumecommand.
    • getResult

      public Object getResult()
      Get the result.
      Returns:
      The result.
    • setResult

      public void setResult(Object result)
      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

      public 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.
    • isSucceeded

      public boolean isSucceeded()
      Test if element is succeeded.
      Specified by:
      isSucceeded in interface IFinishableElement<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 class RParameterElement
    • executePlan

      public void executePlan()