Class AgentMethodAction

All Implemented Interfaces:
EventListener, EventHandler<ActionEvent>

public class AgentMethodAction extends ActionWithData
An Action that directly calls the 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:
  • Constructor Details

    • AgentMethodAction

      public AgentMethodAction(Agent agent, String methodName, Object... params)
      Creates a new AgentMethodAction that will call the given method of the given agent when triggered.
      Parameters:
      agent - the agent that will receive the request
      methodName - the name of the method to call
      params - the parameters to pass to the method