|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectse.sics.tasim.sim.Simulation
public abstract class Simulation
Field Summary | |
---|---|
static java.lang.String |
COORDINATOR
|
static int |
COORDINATOR_INDEX
|
protected static int |
RECOVERY_AFTER_NEXT_TICK
|
protected static int |
RECOVERY_IMMEDIATELY
|
protected static int |
RECOVERY_NONE
|
Constructor Summary | |
---|---|
protected |
Simulation(ConfigManager config)
|
Method Summary | |
---|---|
protected void |
addTimeListener(TimeListener listener)
|
int |
agentIndex(java.lang.String name)
|
protected void |
clearTimeListeners()
|
protected abstract void |
completeStopSimulation()
Notification when this simulation has been stopped. |
protected int |
createBuiltinAgents(java.lang.String base,
int role)
Creates agents with the specified names and registers them in this simulation. |
protected int |
createBuiltinAgents(java.lang.String base,
int role,
java.lang.Class baseClass)
|
protected int |
createDummies(java.lang.String base,
int role,
int numberOfAgents)
|
protected int |
createDummies(java.lang.String base,
int role,
int numberOfAgents,
java.lang.String namePrefix)
|
protected void |
createExternalAgent(java.lang.String name,
int role,
int participantID)
|
protected void |
finalize()
|
protected SimulationAgent |
getAgent(int participantID)
|
protected SimulationAgent |
getAgent(java.lang.String name)
|
protected abstract int |
getAgentRecoverMode(SimulationAgent agent)
Called whenever an external agent has logged in and needs to recover its state. |
protected SimulationAgent[] |
getAgents()
|
protected SimulationAgent[] |
getAgents(int role)
|
ConfigManager |
getConfig()
|
EventWriter |
getEventWriter()
|
protected LogWriter |
getLogWriter()
|
java.util.Random |
getRandom()
|
long |
getServerTime()
|
SimulationInfo |
getSimulationInfo()
|
ThreadPool |
getSimulationThreadPool()
|
protected TimeListener[] |
getTimeListeners()
|
protected int |
getTimeUnitCount()
|
protected java.lang.String |
getTimeUnitName()
|
protected void |
invokeLater(java.lang.Runnable target)
Causes target.run() to be executed with the simulation thread. |
protected abstract void |
messageReceived(Message message)
Delivers a message to the coordinator (the simulation). |
protected void |
nextTimeUnitFinished(int timeUnit)
Called when a new time unit has begun similar to time listeners but this method is guaranteed to be called after the time listeners. |
protected void |
nextTimeUnitStarted(int timeUnit)
Called when entering a new time unit similar to time listeners but this method is guaranteed to be called before the time listeners. |
protected abstract void |
prepareStopSimulation()
Notification when this simulation is preparing to stop. |
protected abstract void |
recoverAgent(SimulationAgent agent)
Called whenever an external agent has logged in and needs to recover its state. |
protected SimulationAgent |
registerAgent(Agent agent,
java.lang.String name,
int role,
int participantID)
Registers the specified agent in this simulation and initializes it. |
protected void |
removeTimeListener(TimeListener listener)
|
protected void |
requestStopSimulation()
|
protected void |
sendMessage(Message message)
Sends the specified message from the simulation coordinator to the agent specified as the receiver in the message. |
protected void |
sendMessage(java.lang.String receiver,
Transportable content)
Sends the specified message from the simulation coordinator to the agent specified as the receiver in the message. |
protected void |
sendToRole(int role,
Transportable content)
|
protected abstract void |
setupSimulation()
|
protected abstract void |
startSimulation()
|
protected void |
startTickTimer(long startServerTime,
int millisPerTimeUnit)
|
protected abstract boolean |
validateMessage(SimulationAgent receiver,
Message message)
Validates this message to ensure that it may be delivered to the agent. |
protected abstract boolean |
validateMessageToRole(int role,
Transportable content)
Validates this message from the coordinator to ensure that it may be broadcasted to all agents with the specified role. |
protected abstract boolean |
validateMessageToRole(SimulationAgent sender,
int role,
Transportable content)
Validates this message to ensure that it may be broadcasted to all agents with the specified role. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String COORDINATOR
public static final int COORDINATOR_INDEX
protected static final int RECOVERY_NONE
protected static final int RECOVERY_IMMEDIATELY
protected static final int RECOVERY_AFTER_NEXT_TICK
Constructor Detail |
---|
protected Simulation(ConfigManager config)
Method Detail |
---|
protected void requestStopSimulation()
public ConfigManager getConfig()
public long getServerTime()
public SimulationInfo getSimulationInfo()
public java.util.Random getRandom()
public ThreadPool getSimulationThreadPool()
public EventWriter getEventWriter()
protected LogWriter getLogWriter()
public int agentIndex(java.lang.String name)
protected SimulationAgent getAgent(java.lang.String name)
protected SimulationAgent getAgent(int participantID)
protected SimulationAgent[] getAgents()
protected SimulationAgent[] getAgents(int role)
protected SimulationAgent registerAgent(Agent agent, java.lang.String name, int role, int participantID)
agent
- the agent to be registeredname
- the name of the agentrole
- the role of the agentparticipantID
- the id of the agent or -1 if the agent is not a registered
agentprotected void invokeLater(java.lang.Runnable target)
protected void startTickTimer(long startServerTime, int millisPerTimeUnit)
protected TimeListener[] getTimeListeners()
protected void addTimeListener(TimeListener listener)
protected void removeTimeListener(TimeListener listener)
protected void clearTimeListeners()
protected abstract void setupSimulation() throws IllegalConfigurationException
IllegalConfigurationException
protected java.lang.String getTimeUnitName()
protected int getTimeUnitCount()
protected abstract void startSimulation()
protected abstract void prepareStopSimulation()
protected abstract void completeStopSimulation()
protected void nextTimeUnitStarted(int timeUnit)
timeUnit
- the current time unitprotected void nextTimeUnitFinished(int timeUnit)
timeUnit
- the current time unitprotected abstract int getAgentRecoverMode(SimulationAgent agent)
RECOVERY_NONE
if the simulation not yet have been started.
The simulation might recover the agent using this method if recovering
the agent can be done using the agent communication thread. In that case
RECOVERY_NONE
should be returned. If any other recover mode
is returned, the simulation will later be asked to recover the agent
using the simulation thread by a call to recoverAgent
.
A common case might be when an agent reestablishing a lost connection to
the server.
agent
- the SimulationAgent
to be recovered.
RECOVERY_NONE
,
RECOVERY_IMMEDIATELY
,
RECOVERY_AFTER_NEXT_TICK
,
recoverAgent(SimulationAgent)
protected abstract void recoverAgent(SimulationAgent agent)
A common case might be when an agent reestablishing a lost connection to the server.
agent
- the SimulationAgent
to be recovered.protected void sendMessage(java.lang.String receiver, Transportable content)
receiver
- the message to sendprotected void sendMessage(Message message)
message
- the message to sendprotected void sendToRole(int role, Transportable content)
protected abstract boolean validateMessage(SimulationAgent receiver, Message message)
receiver
- the agent to deliver the message tomessage
- the message to validate
protected abstract boolean validateMessageToRole(SimulationAgent sender, int role, Transportable content)
sender
- the agent sender the messagerole
- the role of all receiving agentscontent
- the message content
protected abstract boolean validateMessageToRole(int role, Transportable content)
role
- the role of all receiving agentscontent
- the message content
protected abstract void messageReceived(Message message)
message
- the messageprotected void createExternalAgent(java.lang.String name, int role, int participantID)
protected int createBuiltinAgents(java.lang.String base, int role) throws IllegalConfigurationException
base
- the base of the agent propertyrole
- the role of the agents
IllegalConfigurationException
- if an error occursprotected int createBuiltinAgents(java.lang.String base, int role, java.lang.Class baseClass) throws IllegalConfigurationException
IllegalConfigurationException
protected int createDummies(java.lang.String base, int role, int numberOfAgents) throws IllegalConfigurationException
IllegalConfigurationException
protected int createDummies(java.lang.String base, int role, int numberOfAgents, java.lang.String namePrefix) throws IllegalConfigurationException
IllegalConfigurationException
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |