T
- The subclass of WorldModel that this simulator understands.public abstract class AbstractSimulator<T extends WorldModel<? extends Entity>> extends AbstractComponent<T> implements Simulator
Modifier and Type | Field and Description |
---|---|
protected int |
simulatorID
The ID of this simulator.
|
config, connection, model, random
Modifier | Constructor and Description |
---|---|
protected |
AbstractSimulator()
Create a new AbstractSimulator.
|
Modifier and Type | Method and Description |
---|---|
void |
connect(Connection connection,
RequestIDGenerator generator,
Config config)
Connect this component to the kernel.
|
int |
getSimulatorID()
Get this simulator's ID.
|
protected void |
handleCommands(KSCommands c)
Handle a KSCommands object from the server.
|
protected void |
handleUpdate(KSUpdate u)
Handle a KSUpdate object from the server.
|
void |
postConnect(Connection c,
int id,
java.util.Collection<Entity> entities,
Config kernelConfig)
Notification that this simulator has been connected to the kernel.
|
protected void |
processCommands(KSCommands c,
ChangeSet changes)
Process the commands from the server and populate a ChangeSet.
|
protected boolean |
processImmediately(Message msg)
Process an incoming message immediately.
|
protected void |
processMessage(Message msg)
Process an incoming message.
|
protected java.util.List<EntityID> |
requestNewEntityIDs(int count)
Request some new entity IDs from the kernel.
|
void |
shutdown()
Shut this component down.
|
createWorldModel, getName, getPreferredLogContext, getPreferredNDC, getPreferredRegistry, initialise, postConnect, postConnect, send
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getName, getPreferredLogContext, getPreferredRegistry, initialise
public final int getSimulatorID()
public void postConnect(Connection c, int id, java.util.Collection<Entity> entities, Config kernelConfig)
Simulator
postConnect
in interface Simulator
c
- The connection to the kernel.id
- The ID of this simulator.entities
- The set of Entities the kernel sent to this simulator on connection.kernelConfig
- The Config the kernel send to this simulator on connection.public void connect(Connection connection, RequestIDGenerator generator, Config config) throws ConnectionException, ComponentConnectionException, java.lang.InterruptedException
Component
connect
in interface Component
connection
- The Connection to use.generator
- The RequestIDGenerator to use.config
- The system configuration.ConnectionException
- If there is a problem communicating with the kernel.ComponentConnectionException
- If the connection fails.java.lang.InterruptedException
- If the thread is interrupted before the connection attempt completes.public void shutdown()
Component
shutdown
in interface Component
shutdown
in class AbstractComponent<T extends WorldModel<? extends Entity>>
protected void handleUpdate(KSUpdate u)
u
- The Update object.protected void handleCommands(KSCommands c)
c
- The Commands object.protected void processCommands(KSCommands c, ChangeSet changes)
c
- The commands to process.changes
- The ChangeSet to populate.protected java.util.List<EntityID> requestNewEntityIDs(int count) throws java.lang.InterruptedException
count
- The number to request.java.lang.InterruptedException
protected void processMessage(Message msg)
AbstractComponent
processMessage
in class AbstractComponent<T extends WorldModel<? extends Entity>>
msg
- The incoming message.protected boolean processImmediately(Message msg)
AbstractComponent
AbstractComponent.processMessage(Message)
method.processImmediately
in class AbstractComponent<T extends WorldModel<? extends Entity>>
msg
- The incoming message.