Class CoordinatorRequestHandler
java.lang.Object
modelarium.multithreading.requestresponse.CoordinatorRequestHandler
- Direct Known Subclasses:
CoordinatorRequestHandler.AgentAccess,CoordinatorRequestHandler.AllWorkersFinishTick,CoordinatorRequestHandler.AllWorkersUpdateCoordinator,CoordinatorRequestHandler.EnvironmentAttributesAccess,CoordinatorRequestHandler.FilteredAgentsAccess,CoordinatorRequestHandler.UpdateCoordinatorAgents
Abstract base class for handling requests sent to the coordinator thread in a synchronised model.
Each request type is mapped to a specific implementation of this handler. The initialise(java.lang.String, modelarium.ModelSettings, java.util.concurrent.BlockingQueue<modelarium.multithreading.requestresponse.Response>, modelarium.agents.AgentSet, modelarium.environments.Environment)
method sets up this mapping, and handleCoordinatorRequest(Request) dispatches requests accordingly.
All handler subclasses must implement handleRequest(Request).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classProvides access to an individual agent by name.static classHandles synchronisation for when all workers finish a tick.static classHandles synchronisation for when all workers have updated the coordinator.static classProvides access to the current environment state.static classProvides access to a filtered subset of the global agent set.static classUpdates the global agent set with new agent states received from workers. -
Constructor Summary
ConstructorsConstructorDescriptionCoordinatorRequestHandler(String threadName, ModelSettings settings, BlockingQueue<Response> responseQueue, AgentSet globalAgentSet, Environment environment) -
Method Summary
Modifier and TypeMethodDescriptionprotected Environmentprotected AgentSetprotected BlockingQueue<Response> protected ModelSettingsprotected Stringstatic voidhandleCoordinatorRequest(Request request) Handles a coordinator request by dispatching it to the appropriate handler.abstract voidhandleRequest(Request request) Handles an incoming request from a worker.static voidinitialise(String threadName, ModelSettings settings, BlockingQueue<Response> responseQueue, AgentSet globalAgentSet, Environment environment) Initialises the handler map for the coordinator, assigning an instance of each request type's handler.protected voidsetWorkersWaiting(List<String> workersWaiting) Replaces the list of waiting workers (typically to reset it)
-
Constructor Details
-
CoordinatorRequestHandler
public CoordinatorRequestHandler(String threadName, ModelSettings settings, BlockingQueue<Response> responseQueue, AgentSet globalAgentSet, Environment environment)
-
-
Method Details
-
initialise
public static void initialise(String threadName, ModelSettings settings, BlockingQueue<Response> responseQueue, AgentSet globalAgentSet, Environment environment) Initialises the handler map for the coordinator, assigning an instance of each request type's handler.- Parameters:
threadName- the coordinator thread's namesettings- the global model settingsresponseQueue- the shared response queueglobalAgentSet- the global agent set known to the coordinatorenvironment- the shared environment
-
handleCoordinatorRequest
Handles a coordinator request by dispatching it to the appropriate handler.- Parameters:
request- the incoming request from a worker- Throws:
InterruptedException
-
getThreadName
- Returns:
- the coordinator thread name
-
getSettings
- Returns:
- the global model settings
-
getResponseQueue
- Returns:
- the queue to which coordinator responses are written
-
getGlobalAgentSet
- Returns:
- the current global set of all agents
-
getEnvironment
- Returns:
- the global environment
-
getWorkersWaiting
- Returns:
- the list of workers currently waiting for a synchronisation barrier
-
setWorkersWaiting
Replaces the list of waiting workers (typically to reset it) -
handleRequest
Handles an incoming request from a worker. Must be implemented by subclasses.- Parameters:
request- the request to handle- Throws:
InterruptedException
-