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 class
Map a change info as Map:Entry.static class
Condition that tests if goal instances of an mgoal exist.static class
Init write for beliefs.static class
Init write for parameter.static class
Condition for checking the lifecycle state of a goal.static class
Condition that tests if goal instances of an mgoal exist.static class
Condition that tests if goal instances of an mplan exist. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BDIModel
The bdi model.protected RCapability
The 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.RuleSystem
The rule system.protected BDIAgent
The component. -
Constructor Summary
ConstructorsConstructorDescriptionBDIAgentFeature
(BDIAgent self) Factory method constructor for instance level. -
Method Summary
Modifier and TypeMethodDescriptionprotected static Object
adaptToCapability
(Object obj, String capa, IBDIModel bdimodel) Adapt element for use in inner capabilities.static void
addBeliefEvents
(MCapability mcapa, List<jadex.rules.eca.EventType> events, String belname, ClassLoader cl) Create belief events from a belief name.static void
addBeliefEvents
(List<jadex.rules.eca.EventType> events, String belname) Create belief events from a belief name.void
addBeliefListener
(String name, IBeliefListener listener) Add a belief listener.static void
static void
addExpressionEvents
(jadex.common.UnparsedExpression expression, List<jadex.rules.eca.EventType> events, MParameterElement owner) Init the event, when loaded from xml.static void
addInitArgs
(Object obj, Class<?> clazz, Class<?>[] argtypes, Object[] args) Add an entry to the init calls.static void
addInitWrite
(Object key, Runnable cmd) Add an init write.static void
addParameterEvents
(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.EventType
createBeliefEvent
(MCapability mcapa, String belname, String eventname) Create belief event from a belief name.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.static jadex.rules.eca.EventType
createEventType
(RawEvent rawev) Create an event type.<T,
E> jadex.future.IFuture <E> dispatchTopLevelGoal
(T goal) Dispatch a pojo goal wait for its result.void
Drop a pojo goal.findFieldWithOuterClass
(Object obj, String fieldname, boolean nonnull) protected static Field
findFieldWithSuperclass
(Class<?> cl, String fieldname, Object obj, boolean nonnull) static Object
getAbstractBeliefValue
(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 String
getBeliefName
(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.RuleSystem
Get the rulesystem.boolean
Check if the feature potentially executed user code in body.void
init()
protected jadex.future.IFuture
<Void> initCapabilities
(Object agent, jadex.common.Tuple2<jadex.common.FieldInfo, BDIModel>[] caps, int i) Init the capability pojo objects.protected void
injectAgent
(Object agent, jadex.micro.MicroModel model, String globalname) Inject the agent into annotated fields.protected void
invokeInitCalls
(Object pojo) Invoke init constructor calls.protected boolean
static void
observeValue
(jadex.rules.eca.RuleSystem rs, Object val, jadex.rules.eca.EventType etype, MBelief mbel) Observe a value.static void
performInitWrites
(Object key) Perform the writes of the init.static void
static List
<jadex.rules.eca.EventType> readAnnotationEvents
(Annotation[][] annos) Read the annotation events from method annotations.void
removeBeliefListener
(String name, IBeliefListener listener) Remove a belief listener.static void
setAbstractBeliefValue
(String capa, String name, Object value) Set the value of an abstract belief.protected static Object
setFieldValue
(Object obj, String fieldname, Object val) Set the value of a field.void
static void
unobserveObject
(Object object, jadex.rules.eca.EventType etype, jadex.rules.eca.RuleSystem rs) Unobserve an object.static void
unobserveValue
(String belname) Unobserving an old belief value.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.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.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.protected void
writeField
(Object val, String belname, String fieldname, Object obj) Method that is called automatically when a belief is written as field access.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.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.
-
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:
init
in interfaceIInternalBDIAgentFeature
-
terminate
public void terminate()- Specified by:
terminate
in 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:
getCapabilityObject
in 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:
getGoals
in 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:
getGoals
in interfaceIBDIAgentFeature
- Returns:
- All currently instantiated goals.
-
getGoal
Get the goal api representation for a pojo goal.- Specified by:
getGoal
in 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:
dispatchTopLevelGoal
in interfaceIExternalBDIAgentFeature
- Parameters:
goal
- The pojo goal.- Returns:
- The goal result.
-
dropGoal
Drop a pojo goal.- Specified by:
dropGoal
in 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:
adoptPlan
in interfaceIExternalBDIAgentFeature
- Parameters:
plan
- The pojo plan or plan name.- Returns:
- The plan result.
-
adoptPlan
Dispatch a goal wait for its result.- Specified by:
adoptPlan
in interfaceIExternalBDIAgentFeature
- Parameters:
plan
- The pojo plan or plan name.args
- The plan arguments.- Returns:
- The plan result.
-
addBeliefListener
Add a belief listener.- Specified by:
addBeliefListener
in interfaceIBDIAgentFeature
- Specified by:
addBeliefListener
in interfaceIInternalBDIAgentFeature
- Parameters:
name
- The belief name.listener
- The belief listener.
-
removeBeliefListener
Remove a belief listener.- Specified by:
removeBeliefListener
in interfaceIBDIAgentFeature
- Specified by:
removeBeliefListener
in 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:
getRuleSystem
in interfaceIInternalBDIAgentFeature
- Returns:
- The rulesystem.
-
getBDIModel
Get the bdimodel.- Specified by:
getBDIModel
in interfaceIInternalBDIAgentFeature
- Returns:
- the bdimodel.
-
getCapability
Get the state.- Specified by:
getCapability
in 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:
getEventAdders
in interfaceIInternalBDIAgentFeature
- Returns:
- The event adder.
-
getClassLoader
Description copied from interface:IInternalBDIAgentFeature
Get the class loader for the pojo agent.- Specified by:
getClassLoader
in interfaceIInternalBDIAgentFeature
-
getArgument
Description copied from interface:IBDIAgentFeature
Get an argument if supplied at agent creation.- Specified by:
getArgument
in interfaceIBDIAgentFeature
-