Class CoordinatorRequestHandler

java.lang.Object
modelarium.multithreading.requestresponse.CoordinatorRequestHandler
Direct Known Subclasses:
CoordinatorRequestHandler.AgentAccess, CoordinatorRequestHandler.AllWorkersFinishTick, CoordinatorRequestHandler.AllWorkersUpdateCoordinator, CoordinatorRequestHandler.EnvironmentAttributesAccess, CoordinatorRequestHandler.FilteredAgentsAccess, CoordinatorRequestHandler.UpdateCoordinatorAgents

public abstract class CoordinatorRequestHandler extends Object
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).

  • Constructor Details

  • 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 name
      settings - the global model settings
      responseQueue - the shared response queue
      globalAgentSet - the global agent set known to the coordinator
      environment - the shared environment
    • handleCoordinatorRequest

      public static void handleCoordinatorRequest(Request request) throws InterruptedException
      Handles a coordinator request by dispatching it to the appropriate handler.
      Parameters:
      request - the incoming request from a worker
      Throws:
      InterruptedException
    • getThreadName

      protected String getThreadName()
      Returns:
      the coordinator thread name
    • getSettings

      protected ModelSettings getSettings()
      Returns:
      the global model settings
    • getResponseQueue

      protected BlockingQueue<Response> getResponseQueue()
      Returns:
      the queue to which coordinator responses are written
    • getGlobalAgentSet

      protected AgentSet getGlobalAgentSet()
      Returns:
      the current global set of all agents
    • getEnvironment

      protected Environment getEnvironment()
      Returns:
      the global environment
    • getWorkersWaiting

      protected List<String> getWorkersWaiting()
      Returns:
      the list of workers currently waiting for a synchronisation barrier
    • setWorkersWaiting

      protected void setWorkersWaiting(List<String> workersWaiting)
      Replaces the list of waiting workers (typically to reset it)
    • handleRequest

      public abstract void handleRequest(Request request) throws InterruptedException
      Handles an incoming request from a worker. Must be implemented by subclasses.
      Parameters:
      request - the request to handle
      Throws:
      InterruptedException