T
- The subclass of WorldModel that this component understands.public abstract class AbstractComponent<T extends WorldModel<? extends Entity>> extends java.lang.Object implements Component
Modifier and Type | Field and Description |
---|---|
protected Config |
config
The configuration.
|
protected Connection |
connection
The connection to the kernel.
|
protected T |
model
The world model.
|
protected java.util.Random |
random
A random number generator.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractComponent()
Create a new AbstractComponent.
|
Modifier and Type | Method and Description |
---|---|
protected abstract T |
createWorldModel()
Construct the world model.
|
java.lang.String |
getName()
Get the name of this component.
|
java.lang.String |
getPreferredLogContext()
Get the preferred log context for this component.
|
protected java.lang.String |
getPreferredNDC()
Get the preferred nested diagnostic context to use when processing messages for this component.
|
Registry |
getPreferredRegistry(Registry parent)
Get the registry this component would like to use for its connection.
|
void |
initialise()
Initialise this component before connection.
|
protected void |
postConnect()
Perform any post-connection work required before acknowledgement of the connection is made.
|
protected void |
postConnect(Connection c,
java.util.Collection<Entity> entities,
Config kernelConfig)
Notification that connection to the kernel succeeded.
|
protected boolean |
processImmediately(Message msg)
Process an incoming message immediately.
|
protected void |
processMessage(Message msg)
Process an incoming message.
|
protected void |
send(Message msg)
Send a message to the kernel and silently ignore any errors.
|
void |
shutdown()
Shut this component down.
|
protected Connection connection
protected Config config
protected T extends WorldModel<? extends Entity> model
protected java.util.Random random
protected final void postConnect(Connection c, java.util.Collection<Entity> entities, Config kernelConfig)
c
- The kernel connection.entities
- The entities that the kernel sent on startup.kernelConfig
- The config that the kernel sent on startup.protected void postConnect()
protected abstract T createWorldModel()
protected final void send(Message msg)
msg
- The message to send.public java.lang.String getPreferredLogContext()
Component
getPreferredLogContext
in interface Component
protected java.lang.String getPreferredNDC()
public void initialise()
Component
initialise
in interface Component
public void shutdown()
Component
public java.lang.String getName()
Component
public Registry getPreferredRegistry(Registry parent)
Component
getPreferredRegistry
in interface Component
parent
- The parent registry.protected void processMessage(Message msg)
msg
- The incoming message.protected boolean processImmediately(Message msg)
processMessage(Message)
method.msg
- The incoming message.