Class RequestResponseInterface
java.lang.Object
modelarium.multithreading.requestresponse.RequestResponseInterface
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 Summary
ConstructorsConstructorDescriptionRequestResponseInterface(String name, ModelSettings settings, RequestResponseController requestResponseController) Constructs a new interface bound to the given model element or thread. -
Method Summary
Modifier and TypeMethodDescriptiongetAgentFromCoordinator(String requesterAgentName, String targetAgentName) Requests a specific agent from the coordinator.getEnvironmentFromCoordinator(String requesterAgentName) Requests the current environment state from the coordinator.getFilteredAgentsFromCoordinator(String requesterAgentName, Predicate<Agent> agentFilter) Requests a filtered subset of agents from the coordinator.voidupdateCoordinatorAgents(AgentSet agentSet) Sends an update to the coordinator with the current agent set for this thread.voidWaits until all workers have completed their current simulation tick.voidWaits until all workers have updated the coordinator with their agent data.
-
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 settingsrequestResponseController- the controller that provides the queues
-
-
Method Details
-
waitUntilAllWorkersFinishTick
Waits until all workers have completed their current simulation tick.- Throws:
InterruptedException
-
waitUntilAllWorkersUpdateCoordinator
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 agenttargetAgentName- the name of the agent to retrieve- Returns:
- the
Agentinstance 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 requesteragentFilter- a predicate to apply to the global agent set- Returns:
- an
AgentSetcontaining 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
Environmentinstance - Throws:
InterruptedException
-
updateCoordinatorAgents
Sends an update to the coordinator with the current agent set for this thread.- Parameters:
agentSet- the updated set of agents- Throws:
InterruptedException
-