Package jadex.bdi.runtime.impl
Class BDIAgentFeature
java.lang.Object
jadex.bdi.runtime.impl.BDIAgentFeature
- All Implemented Interfaces:
IBDIAgentFeature,IExternalBDIAgentFeature,IInternalBDIAgentFeature
The bdi agent feature implementation for pojo agents.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classMap a change info as Map:Entry.static classCondition that tests if goal instances of an mgoal exist.static classInit write for beliefs.static classInit write for parameter.static classCondition for checking the lifecycle state of a goal.static classCondition that tests if goal instances of an mgoal exist.static classCondition that tests if goal instances of an mplan exist. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BDIModelThe bdi model.protected RCapabilityThe bdi state.protected Map<jadex.rules.eca.EventType, jadex.common.IResultCommand<jadex.future.IFuture<Void>, PropertyChangeEvent>> The event adders.Saved init writes.protected jadex.rules.eca.RuleSystemThe rule system.protected BDIAgentThe component. -
Constructor Summary
ConstructorsConstructorDescriptionBDIAgentFeature(BDIAgent self) Factory method constructor for instance level. -
Method Summary
Modifier and TypeMethodDescriptionprotected static ObjectadaptToCapability(Object obj, String capa, IBDIModel bdimodel) Adapt element for use in inner capabilities.static voidaddBeliefEvents(MCapability mcapa, List<jadex.rules.eca.EventType> events, String belname, ClassLoader cl) Create belief events from a belief name.static voidaddBeliefEvents(List<jadex.rules.eca.EventType> events, String belname) Create belief events from a belief name.voidaddBeliefListener(String name, IBeliefListener listener) Add a belief listener.static voidstatic voidaddExpressionEvents(jadex.common.UnparsedExpression expression, List<jadex.rules.eca.EventType> events, MParameterElement owner) Init the event, when loaded from xml.static voidaddInitArgs(Object obj, Class<?> clazz, Class<?>[] argtypes, Object[] args) Add an entry to the init calls.static voidaddInitWrite(Object key, Runnable cmd) Add an init write.static voidaddParameterEvents(MParameterElement mpelem, MCapability mcapa, List<jadex.rules.eca.EventType> events, String paramname, ClassLoader cl) Create parameter events from a belief name.<T,E> jadex.future.IFuture <E> adoptPlan(T plan) Dispatch a pojo plan and wait for its result.<T,E> jadex.future.IFuture <E> Dispatch a goal wait for its result.static jadex.rules.eca.EventTypecreateBeliefEvent(MCapability mcapa, String belname, String eventname) Create belief event from a belief name.static voidcreateChangeEvent(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.static jadex.rules.eca.EventTypecreateEventType(RawEvent rawev) Create an event type.<T,E> jadex.future.IFuture <E> dispatchTopLevelGoal(T goal) Dispatch a pojo goal wait for its result.voidDrop a pojo goal.findFieldWithOuterClass(Object obj, String fieldname, boolean nonnull) protected static FieldfindFieldWithSuperclass(Class<?> cl, String fieldname, Object obj, boolean nonnull) static ObjectgetAbstractBeliefValue(String capa, String name, Class<?> type) Get the value of an abstract belief.getArgument(String name) Get an argument if supplied at agent creation.Get the bdimodel.protected static StringgetBeliefName(Object obj, String fieldname) Get the state.getCapabilityObject(String name) Get a capability pojo object.Get the class loader for the pojo agent.protected static jadex.common.IResultCommand<jadex.future.IFuture<Void>, PropertyChangeEvent> getEventAdder(jadex.rules.eca.EventType etype, MBelief mbel, jadex.rules.eca.RuleSystem rs) Map<jadex.rules.eca.EventType, jadex.common.IResultCommand<jadex.future.IFuture<Void>, PropertyChangeEvent>> Get the event type.Get the goal api representation for a pojo goal.static List<jadex.rules.eca.EventType> getGoalEvents(MGoal mgoal) Create goal events for a goal name.getGoals()Get the current goals as api representation.<T> Collection<T> Get the goals of a given type as pojos.getInitCalls(Object obj, Class<?> clazz) Get the init calls.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.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.jadex.rules.eca.RuleSystemGet the rulesystem.booleanCheck if the feature potentially executed user code in body.voidinit()protected jadex.future.IFuture<Void> initCapabilities(Object agent, jadex.common.Tuple2<jadex.common.FieldInfo, BDIModel>[] caps, int i) Init the capability pojo objects.protected voidinjectAgent(Object agent, jadex.micro.MicroModel model, String globalname) Inject the agent into annotated fields.protected voidinvokeInitCalls(Object pojo) Invoke init constructor calls.protected booleanstatic voidobserveValue(jadex.rules.eca.RuleSystem rs, Object val, jadex.rules.eca.EventType etype, MBelief mbel) Observe a value.static voidperformInitWrites(Object key) Perform the writes of the init.static voidstatic List<jadex.rules.eca.EventType> readAnnotationEvents(Annotation[][] annos) Read the annotation events from method annotations.voidremoveBeliefListener(String name, IBeliefListener listener) Remove a belief listener.static voidsetAbstractBeliefValue(String capa, String name, Object value) Set the value of an abstract belief.protected static ObjectsetFieldValue(Object obj, String fieldname, Object val) Set the value of a field.voidstatic voidunobserveObject(Object object, jadex.rules.eca.EventType etype, jadex.rules.eca.RuleSystem rs) Unobserve an object.static voidunobserveValue(String belname) Unobserving an old belief value.static voidwriteArrayField(Object array, int index, Object val, Object agentobj, String fieldname) Method that is called automatically when a belief is written as array access.static voidwriteArrayParameterField(Object array, int index, Object val, Object agentobj, String fieldname) Method that is called automatically when a parameter is written as array access.static voidwriteField(Object val, String fieldname, Object obj, jadex.core.IComponent comp) Method that is called automatically when a belief is written as field access.protected voidwriteField(Object val, String belname, String fieldname, Object obj) Method that is called automatically when a belief is written as field access.protected voidwriteField(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.static voidwriteParameterField(Object val, String fieldname, Object obj, jadex.core.IComponent dummy) Method that is called automatically when a parameter is written as field access.
-
Field Details
-
self
The component. -
bdimodel
The bdi model. -
rulesystem
protected jadex.rules.eca.RuleSystem rulesystemThe rule system. -
capa
The bdi state. -
eventadders
protected Map<jadex.rules.eca.EventType,jadex.common.IResultCommand<jadex.future.IFuture<Void>, eventaddersPropertyChangeEvent>> The event adders. -
newinitwrites
Saved init writes.
-
-
Constructor Details
-
BDIAgentFeature
Factory method constructor for instance level.
-
-
Method Details
-
init
public void init()- Specified by:
initin interfaceIInternalBDIAgentFeature
-
terminate
public void terminate()- Specified by:
terminatein interfaceIInternalBDIAgentFeature
-
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
Add an entry to the init calls.- Parameters:
obj- object instance that owns the field __initargsclazz- Class definition of the obj objectargtypes- Signature of the init methodargs- 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
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
Method that is called automatically when a belief is written as field access. -
addInitWrite
Add an init write. -
performInitWrites
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
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
Get the value of an abstract belief. -
setAbstractBeliefValue
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
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
-
getBeliefName
-
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
Inject the agent into annotated fields. -
getCapabilityObject
Get a capability pojo object.- Specified by:
getCapabilityObjectin interfaceIInternalBDIAgentFeature- Returns:
- The capability pojo.
-
adaptToCapability
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
Invoke init constructor calls. -
getGoals
Get the goals of a given type as pojos.- Specified by:
getGoalsin interfaceIBDIAgentFeature- Parameters:
clazz- The pojo goal class.- Returns:
- The currently instantiated goals of that type.
-
getGoals
Get the current goals as api representation.- Specified by:
getGoalsin interfaceIBDIAgentFeature- Returns:
- All currently instantiated goals.
-
getGoal
Get the goal api representation for a pojo goal.- Specified by:
getGoalin interfaceIBDIAgentFeature- 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:
dispatchTopLevelGoalin interfaceIExternalBDIAgentFeature- Parameters:
goal- The pojo goal.- Returns:
- The goal result.
-
dropGoal
Drop a pojo goal.- Specified by:
dropGoalin interfaceIBDIAgentFeature- 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:
adoptPlanin interfaceIExternalBDIAgentFeature- Parameters:
plan- The pojo plan or plan name.- Returns:
- The plan result.
-
adoptPlan
Dispatch a goal wait for its result.- Specified by:
adoptPlanin interfaceIExternalBDIAgentFeature- Parameters:
plan- The pojo plan or plan name.args- The plan arguments.- Returns:
- The plan result.
-
addBeliefListener
Add a belief listener.- Specified by:
addBeliefListenerin interfaceIBDIAgentFeature- Specified by:
addBeliefListenerin interfaceIInternalBDIAgentFeature- Parameters:
name- The belief name.listener- The belief listener.
-
removeBeliefListener
Remove a belief listener.- Specified by:
removeBeliefListenerin interfaceIBDIAgentFeature- Specified by:
removeBeliefListenerin interfaceIInternalBDIAgentFeature- 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:
getRuleSystemin interfaceIInternalBDIAgentFeature- Returns:
- The rulesystem.
-
getBDIModel
Get the bdimodel.- Specified by:
getBDIModelin interfaceIInternalBDIAgentFeature- Returns:
- the bdimodel.
-
getCapability
Get the state.- Specified by:
getCapabilityin interfaceIInternalBDIAgentFeature- Returns:
- the state.
-
getGoalEvents
Create goal events for a goal name. creates goaladopted, goaldropped goaloption, goalactive, goalsuspended goalinprocess, goalnotinprocess events. -
addBeliefEvents
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
Read the annotation events from method annotations. -
createEventType
Create an event type. -
getEventAdders
public Map<jadex.rules.eca.EventType,jadex.common.IResultCommand<jadex.future.IFuture<Void>, getEventAdders()PropertyChangeEvent>> Get the event type.- Specified by:
getEventAddersin interfaceIInternalBDIAgentFeature- Returns:
- The event adder.
-
getClassLoader
Description copied from interface:IInternalBDIAgentFeatureGet the class loader for the pojo agent.- Specified by:
getClassLoaderin interfaceIInternalBDIAgentFeature
-
getArgument
Description copied from interface:IBDIAgentFeatureGet an argument if supplied at agent creation.- Specified by:
getArgumentin interfaceIBDIAgentFeature
-