Class AgentMethodAction
- All Implemented Interfaces:
EventListener
,EventHandler<ActionEvent>
Agent.handleRequestActionMessage(RequestActionMessage)
method of an agent when
triggered.
This action is useful when you want to trigger an agent's method from a graphical user interface, for example.
Using this, developers should be aware that the agent's method will be called in the caller thread, and not in the agent's thread. This can lead to concurrency issues if the agent's method is not thread-safe.
Moreover, from an agent-oriented programming perspective, this could be seen as a bad
practice, as it breaks the encapsulation of the agent's behavior. So, it could be a
better solution to use the RequestAgentMessageAction
that does not directly
call the agent's method, but only sends a RequestActionMessage
to the agent,
which will be processed only when the agent decides to do so.
Still, there are cases where using a direct call to the agent's method does not impact the control flow of the agent, and it can be a useful tool to interact with the agent from the outside, especially in a graphical user interface.
- See Also:
-
Property Summary
-
Constructor Summary
ConstructorsConstructorDescriptionAgentMethodAction
(Agent agent, String methodName, Object... params) Creates a new AgentMethodAction that will call the given method of the given agent when triggered. -
Method Summary
Methods inherited from class madkit.action.ActionWithData
setActionData
Methods inherited from class org.controlsfx.control.action.Action
acceleratorProperty, disabledProperty, getAccelerator, getEventHandler, getGraphic, getLongText, getProperties, getStyle, getStyleClass, getText, graphicProperty, handle, isDisabled, isSelected, lock, longTextProperty, selectedProperty, setAccelerator, setDisabled, setEventHandler, setGraphic, setLongText, setSelected, setStyle, setText, styleProperty, textProperty
-
Constructor Details
-
AgentMethodAction
Creates a new AgentMethodAction that will call the given method of the given agent when triggered.- Parameters:
agent
- the agent that will receive the requestmethodName
- the name of the method to callparams
- the parameters to pass to the method
-