Package modelarium
Class ModelElementAccessor
java.lang.Object
modelarium.ModelElementAccessor
Provides a model element (either an agent or the environment) with access
to relevant simulation resources such as the local environment, other agents,
and shared utilities, including communication and caching systems.
This class abstracts access logic based on model settings, including:
- Local access versus coordinated inter-thread access
- Optional caching of agents and environments
- Safe agent filtering with predicate functions
- The associated model clock
-
Constructor Summary
ConstructorsConstructorDescriptionModelElementAccessor(ModelElement modelElement, AgentSet localAgentSet, ModelSettings settings, WorkerCache cache, RequestResponseInterface requestResponseInterface, Environment localEnvironment) Constructs a new accessor for a model element. -
Method Summary
Modifier and TypeMethodDescriptionbooleandoesAgentExistInThisCore(String agentName) Checks whether an agent with the given name exists in this core/thread.getAgentByName(String targetAgentName) Retrieves an agent by name, checking local storage first, then cache, then (if enabled) contacting the coordinator.Retrieves the current environment for the model element.getFilteredAgents(Predicate<Agent> filter) Retrieves a set of agents that match the given filter predicate.Retrieves the associated clock instance.voidsetModelClock(ModelClock clock) Sets the associated clock instance.
-
Constructor Details
-
ModelElementAccessor
public ModelElementAccessor(ModelElement modelElement, AgentSet localAgentSet, ModelSettings settings, WorkerCache cache, RequestResponseInterface requestResponseInterface, Environment localEnvironment) Constructs a new accessor for a model element.- Parameters:
modelElement- the model element (agent or environment) this accessor serveslocalAgentSet- the set of agents assigned to this core/threadsettings- the shared model settings objectcache- the local cache for agent/environment access (may be null if not used)requestResponseInterface- the communication interface for synchronised coordinationlocalEnvironment- the local copy of the environment assigned to this model element
-
-
Method Details
-
setModelClock
Sets the associated clock instance. Once a clock has been set, it cannot be reset.- Parameters:
clock- theModelClockinstance to set with
-
getModelClock
Retrieves the associated clock instance.- Returns:
- the
ModelClockinstance
-
doesAgentExistInThisCore
Checks whether an agent with the given name exists in this core/thread.- Parameters:
agentName- the name of the agent to check- Returns:
- true if the agent exists locally
-
getAgentByName
Retrieves an agent by name, checking local storage first, then cache, then (if enabled) contacting the coordinator.- Parameters:
targetAgentName- the name of the agent to retrieve- Returns:
- the agent instance, or null if not found or if retrieval failed
-
getFilteredAgents
Retrieves a set of agents that match the given filter predicate. May involve coordinator requests or use of cached results, depending on settings.- Parameters:
filter- the predicate used to select agents- Returns:
- an
AgentSetcontaining the matching agents, or null if retrieval fails
-
getEnvironment
Retrieves the current environment for the model element. This may be the local environment, a cached copy, or one retrieved from the coordinator.- Returns:
- the environment instance available to this model element
-