Class BDIAgentFeature

java.lang.Object
jadex.bdi.runtime.impl.BDIAgentFeature
All Implemented Interfaces:
IBDIAgentFeature, IExternalBDIAgentFeature, IInternalBDIAgentFeature

public class BDIAgentFeature extends Object implements IBDIAgentFeature, IInternalBDIAgentFeature
The bdi agent feature implementation for pojo agents.
  • Field Details

    • self

      protected BDIAgent self
      The component.
    • bdimodel

      protected BDIModel bdimodel
      The bdi model.
    • rulesystem

      protected jadex.rules.eca.RuleSystem rulesystem
      The rule system.
    • capa

      protected RCapability capa
      The bdi state.
    • eventadders

      protected Map<jadex.rules.eca.EventType,jadex.common.IResultCommand<jadex.future.IFuture<Void>,PropertyChangeEvent>> eventadders
      The event adders.
    • newinitwrites

      protected static final Map<Object,List<Runnable>> newinitwrites
      Saved init writes.
  • Constructor Details

    • BDIAgentFeature

      public BDIAgentFeature(BDIAgent self)
      Factory method constructor for instance level.
  • Method Details

    • init

      public void init()
      Specified by:
      init in interface IInternalBDIAgentFeature
    • terminate

      public void terminate()
      Specified by:
      terminate in interface IInternalBDIAgentFeature
    • hasUserBody

      public boolean hasUserBody()
      Check if the feature potentially executed user code in body. Allows blocking operations in user bodies by using separate steps for each feature. Non-user-body-features are directly executed for speed. If unsure just return true. ;-)
    • addInitArgs

      public static void addInitArgs(Object obj, Class<?> clazz, Class<?>[] argtypes, Object[] args)
      Add an entry to the init calls.
      Parameters:
      obj - object instance that owns the field __initargs
      clazz - Class definition of the obj object
      argtypes - Signature of the init method
      args - Actual argument values for the init method
    • getInitCalls

      public static List<jadex.common.Tuple2<Class<?>[],Object[]>> getInitCalls(Object obj, Class<?> clazz)
      Get the init calls. Cleans the initargs field on return.
    • writeField

      protected void writeField(Object val, String belname, String fieldname, Object obj)
      Method that is called automatically when a belief is written as field access.
    • writeField

      protected void writeField(Object val, String belname, String fieldname, Object obj, jadex.rules.eca.EventType ev1, jadex.rules.eca.EventType ev2)
      Method that is called automatically when a belief is written as field access.
    • setFieldValue

      protected static Object setFieldValue(Object obj, String fieldname, Object val) throws IllegalAccessException
      Set the value of a field.
      Parameters:
      obj - The object.
      fieldname - The name of the field.
      Returns:
      The old field value.
      Throws:
      IllegalAccessException
    • findFieldWithOuterClass

      protected static jadex.common.Tuple2<Field,Object> findFieldWithOuterClass(Object obj, String fieldname, boolean nonnull)
      Parameters:
      obj -
      fieldname -
      Returns:
    • findFieldWithSuperclass

      protected static Field findFieldWithSuperclass(Class<?> cl, String fieldname, Object obj, boolean nonnull)
      Parameters:
      cl -
      fieldname -
      Returns:
    • writeField

      public static void writeField(Object val, String fieldname, Object obj, jadex.core.IComponent comp)
      Method that is called automatically when a belief is written as field access.
    • addInitWrite

      public static void addInitWrite(Object key, Runnable cmd)
      Add an init write.
    • performInitWrites

      public static void performInitWrites(Object key)
      Perform the writes of the init.
    • writeArrayField

      public static void writeArrayField(Object array, int index, Object val, Object agentobj, String fieldname)
      Method that is called automatically when a belief is written as array access.
    • unobserveValue

      public static void unobserveValue(String belname)
      Unobserving an old belief value.
      Parameters:
      belname - The belief name.
      agent - The agent.
    • observeValue

      public static void observeValue(jadex.rules.eca.RuleSystem rs, Object val, jadex.rules.eca.EventType etype, MBelief mbel)
      Observe a value.
    • getEventAdder

      protected static jadex.common.IResultCommand<jadex.future.IFuture<Void>,PropertyChangeEvent> getEventAdder(jadex.rules.eca.EventType etype, MBelief mbel, jadex.rules.eca.RuleSystem rs)
    • getAbstractBeliefValue

      public static Object getAbstractBeliefValue(String capa, String name, Class<?> type)
      Get the value of an abstract belief.
    • setAbstractBeliefValue

      public static void setAbstractBeliefValue(String capa, String name, Object value)
      Set the value of an abstract belief.
    • unobserveObject

      public static void unobserveObject(Object object, jadex.rules.eca.EventType etype, jadex.rules.eca.RuleSystem rs)
      Unobserve an object.
    • createChangeEvent

      public static void createChangeEvent(Object val, Object oldval, Object info, String belname)
      Caution: this method is used from byte engineered code, change signature with caution Create a belief changed event.
      Parameters:
      val - The new value.
      belname - The belief name.
      agent - The agent.
    • publishToolBeliefEvent

      public static void publishToolBeliefEvent(MBelief mbel)
    • getBeliefName

      protected static String getBeliefName(Object obj, String fieldname)
    • writeParameterField

      public static void writeParameterField(Object val, String fieldname, Object obj, jadex.core.IComponent dummy)
      Method that is called automatically when a parameter is written as field access.
      Parameters:
      val - The parameter value.
      fieldname - The name of the field the value is set upon.
      obj - The pojo object of the goal.
      agent - The agent.
    • writeArrayParameterField

      public static void writeArrayParameterField(Object array, int index, Object val, Object agentobj, String fieldname)
      Method that is called automatically when a parameter is written as array access.
    • isComponentThread

      protected boolean isComponentThread()
    • injectAgent

      protected void injectAgent(Object agent, jadex.micro.MicroModel model, String globalname)
      Inject the agent into annotated fields.
    • getCapabilityObject

      public Object getCapabilityObject(String name)
      Get a capability pojo object.
      Specified by:
      getCapabilityObject in interface IInternalBDIAgentFeature
      Returns:
      The capability pojo.
    • adaptToCapability

      protected static Object adaptToCapability(Object obj, String capa, IBDIModel bdimodel)
      Adapt element for use in inner capabilities.
      Parameters:
      obj - The object to adapt (e.g. a change event)
      capa - The capability name or null for agent.
    • initCapabilities

      protected jadex.future.IFuture<Void> initCapabilities(Object agent, jadex.common.Tuple2<jadex.common.FieldInfo,BDIModel>[] caps, int i)
      Init the capability pojo objects.
    • invokeInitCalls

      protected void invokeInitCalls(Object pojo)
      Invoke init constructor calls.
    • getGoals

      public <T> Collection<T> getGoals(Class<T> clazz)
      Get the goals of a given type as pojos.
      Specified by:
      getGoals in interface IBDIAgentFeature
      Parameters:
      clazz - The pojo goal class.
      Returns:
      The currently instantiated goals of that type.
    • getGoals

      public Collection<IGoal> getGoals()
      Get the current goals as api representation.
      Specified by:
      getGoals in interface IBDIAgentFeature
      Returns:
      All currently instantiated goals.
    • getGoal

      public IGoal getGoal(Object goal)
      Get the goal api representation for a pojo goal.
      Specified by:
      getGoal in interface IBDIAgentFeature
      Parameters:
      goal - The pojo goal.
      Returns:
      The api goal.
    • dispatchTopLevelGoal

      public <T, E> jadex.future.IFuture<E> dispatchTopLevelGoal(T goal)
      Dispatch a pojo goal wait for its result.
      Specified by:
      dispatchTopLevelGoal in interface IExternalBDIAgentFeature
      Parameters:
      goal - The pojo goal.
      Returns:
      The goal result.
    • dropGoal

      public void dropGoal(Object goal)
      Drop a pojo goal.
      Specified by:
      dropGoal in interface IBDIAgentFeature
      Parameters:
      goal - The pojo goal.
    • adoptPlan

      public <T, E> jadex.future.IFuture<E> adoptPlan(T plan)
      Dispatch a pojo plan and wait for its result.
      Specified by:
      adoptPlan in interface IExternalBDIAgentFeature
      Parameters:
      plan - The pojo plan or plan name.
      Returns:
      The plan result.
    • adoptPlan

      public <T, E> jadex.future.IFuture<E> adoptPlan(T plan, Object... args)
      Dispatch a goal wait for its result.
      Specified by:
      adoptPlan in interface IExternalBDIAgentFeature
      Parameters:
      plan - The pojo plan or plan name.
      args - The plan arguments.
      Returns:
      The plan result.
    • addBeliefListener

      public void addBeliefListener(String name, IBeliefListener listener)
      Add a belief listener.
      Specified by:
      addBeliefListener in interface IBDIAgentFeature
      Specified by:
      addBeliefListener in interface IInternalBDIAgentFeature
      Parameters:
      name - The belief name.
      listener - The belief listener.
    • removeBeliefListener

      public void removeBeliefListener(String name, IBeliefListener listener)
      Remove a belief listener.
      Specified by:
      removeBeliefListener in interface IBDIAgentFeature
      Specified by:
      removeBeliefListener in interface IInternalBDIAgentFeature
      Parameters:
      name - The belief name.
      listener - The belief listener.
    • getInjectionValues

      public static Object[] getInjectionValues(Class<?>[] ptypes, Annotation[][] anns, MElement melement, ChangeEvent event, RPlan rplan, RProcessableElement rpe)
      Get parameter values for injection into method and constructor calls.
    • getInjectionValues

      public static Object[] getInjectionValues(Class<?>[] ptypes, Annotation[][] anns, MElement melement, ChangeEvent event, RPlan rplan, RProcessableElement rpe, Collection<Object> vs)
      Get parameter values for injection into method and constructor calls.
      Returns:
      A valid assignment or null if no assignment could be found.
    • getRuleSystem

      public jadex.rules.eca.RuleSystem getRuleSystem()
      Get the rulesystem.
      Specified by:
      getRuleSystem in interface IInternalBDIAgentFeature
      Returns:
      The rulesystem.
    • getBDIModel

      public IBDIModel getBDIModel()
      Get the bdimodel.
      Specified by:
      getBDIModel in interface IInternalBDIAgentFeature
      Returns:
      the bdimodel.
    • getCapability

      public RCapability getCapability()
      Get the state.
      Specified by:
      getCapability in interface IInternalBDIAgentFeature
      Returns:
      the state.
    • getGoalEvents

      public static List<jadex.rules.eca.EventType> getGoalEvents(MGoal mgoal)
      Create goal events for a goal name. creates goaladopted, goaldropped goaloption, goalactive, goalsuspended goalinprocess, goalnotinprocess events.
    • addBeliefEvents

      public static void addBeliefEvents(List<jadex.rules.eca.EventType> events, String belname)
      Create belief events from a belief name. For normal beliefs beliefchanged.belname and factchanged.belname and for multi beliefs additionally factadded.belname and factremoved are created.
    • addBeliefEvents

      public static void addBeliefEvents(MCapability mcapa, List<jadex.rules.eca.EventType> events, String belname, ClassLoader cl)
      Create belief events from a belief name. For normal beliefs beliefchanged.belname and factchanged.belname and for multi beliefs additionally factadded.belname and factremoved are created.
    • createBeliefEvent

      public static jadex.rules.eca.EventType createBeliefEvent(MCapability mcapa, String belname, String eventname)
      Create belief event from a belief name. Checks if belief exists and creates event type.
    • addParameterEvents

      public static void addParameterEvents(MParameterElement mpelem, MCapability mcapa, List<jadex.rules.eca.EventType> events, String paramname, ClassLoader cl)
      Create parameter events from a belief name.
    • addExpressionEvents

      public static void addExpressionEvents(jadex.common.UnparsedExpression expression, List<jadex.rules.eca.EventType> events, MParameterElement owner)
      Init the event, when loaded from xml.
    • addEvent

      public static void addEvent(List<jadex.rules.eca.EventType> events, jadex.rules.eca.EventType event)
    • readAnnotationEvents

      public static List<jadex.rules.eca.EventType> readAnnotationEvents(Annotation[][] annos)
      Read the annotation events from method annotations.
    • createEventType

      public static jadex.rules.eca.EventType createEventType(RawEvent rawev)
      Create an event type.
    • getEventAdders

      public Map<jadex.rules.eca.EventType,jadex.common.IResultCommand<jadex.future.IFuture<Void>,PropertyChangeEvent>> getEventAdders()
      Get the event type.
      Specified by:
      getEventAdders in interface IInternalBDIAgentFeature
      Returns:
      The event adder.
    • getClassLoader

      public ClassLoader getClassLoader()
      Description copied from interface: IInternalBDIAgentFeature
      Get the class loader for the pojo agent.
      Specified by:
      getClassLoader in interface IInternalBDIAgentFeature
    • getArgument

      public Object getArgument(String name)
      Description copied from interface: IBDIAgentFeature
      Get an argument if supplied at agent creation.
      Specified by:
      getArgument in interface IBDIAgentFeature