Class RequestResponseInterface

java.lang.Object
modelarium.multithreading.requestresponse.RequestResponseInterface

public class RequestResponseInterface extends Object
Provides a per-thread interface for sending requests to and receiving responses from the simulation coordinator in a synchronised agent-based model.

This abstraction helps worker threads interact with the coordinator using higher-level methods instead of directly manipulating queues.

  • Constructor Details

    • RequestResponseInterface

      public RequestResponseInterface(String name, ModelSettings settings, RequestResponseController requestResponseController)
      Constructs a new interface bound to the given model element or thread.
      Parameters:
      name - the name of this component (typically the thread or agent name)
      settings - the shared model settings
      requestResponseController - the controller that provides the queues
  • Method Details

    • waitUntilAllWorkersFinishTick

      public void waitUntilAllWorkersFinishTick() throws InterruptedException
      Waits until all workers have completed their current simulation tick.
      Throws:
      InterruptedException
    • waitUntilAllWorkersUpdateCoordinator

      public void waitUntilAllWorkersUpdateCoordinator() throws InterruptedException
      Waits until all workers have updated the coordinator with their agent data.
      Throws:
      InterruptedException
    • getAgentFromCoordinator

      public Agent getAgentFromCoordinator(String requesterAgentName, String targetAgentName) throws InterruptedException
      Requests a specific agent from the coordinator.
      Parameters:
      requesterAgentName - the name of the requesting agent
      targetAgentName - the name of the agent to retrieve
      Returns:
      the Agent instance returned by the coordinator
      Throws:
      InterruptedException
    • getFilteredAgentsFromCoordinator

      public AgentSet getFilteredAgentsFromCoordinator(String requesterAgentName, Predicate<Agent> agentFilter) throws InterruptedException
      Requests a filtered subset of agents from the coordinator.
      Parameters:
      requesterAgentName - the name of the requester
      agentFilter - a predicate to apply to the global agent set
      Returns:
      an AgentSet containing matching agents
      Throws:
      InterruptedException
    • getEnvironmentFromCoordinator

      public Environment getEnvironmentFromCoordinator(String requesterAgentName) throws InterruptedException
      Requests the current environment state from the coordinator.
      Parameters:
      requesterAgentName - the requesting agent's name
      Returns:
      the current Environment instance
      Throws:
      InterruptedException
    • updateCoordinatorAgents

      public void updateCoordinatorAgents(AgentSet agentSet) throws InterruptedException
      Sends an update to the coordinator with the current agent set for this thread.
      Parameters:
      agentSet - the updated set of agents
      Throws:
      InterruptedException