Class Base
java.lang.Object
|
+--Base
- Direct Known Subclasses:
- BaseVisual
- public class Base
- extends java.lang.Object
A base is the home of the agents. Every agent belongs to
exactly one base; agents can move between bases and send
messages to the base that are redirected to all other
agents in the same base.
Field Summary |
protected java.util.Vector |
agents
Contains all agents of the base |
Constructor Summary |
Base()
Creates a new base |
Base(java.lang.String aName)
Creates a new base with a name |
Method Summary |
void |
addAgent(Agent anAgent)
Adds a new agent to the base.
|
void |
messageReceived(Message aMessage)
Called on incoming messages.
(internal function, do not override)
The base usually doesn't receive messages directly, but
spreads each incoming message to all agents in the
base (broadcast). |
void |
onMessage(Message aMesage)
Called on incoming message.
|
void |
onUpdate()
Called when agent was added or removed.
|
void |
removeAgent(Agent anAgent)
Removes an agent from the base.
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
agents
protected java.util.Vector agents
- Contains all agents of the base
Base
public Base()
- Creates a new base
Base
public Base(java.lang.String aName)
- Creates a new base with a name
addAgent
public void addAgent(Agent anAgent)
- Adds a new agent to the base.
This function is called by an agent if he
wants to subscribe to a base (if he is created
or moves between bases)
Never call this function directly, the core of
the agent takes care of the subscribe/unsubscribe process
removeAgent
public void removeAgent(Agent anAgent)
- Removes an agent from the base.
This function is called by an agent if he
wants to unsubscribe from this base. That
is, if he is killed (destroyed) or moves
between bases.
messageReceived
public void messageReceived(Message aMessage)
- Called on incoming messages.
(internal function, do not override)
The base usually doesn't receive messages directly, but
spreads each incoming message to all agents in the
base (broadcast).
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
onUpdate
public void onUpdate()
- Called when agent was added or removed.
Important for the visual agent to update
the JList
onMessage
public void onMessage(Message aMesage)
- Called on incoming message.
Until now, this function doesn't process
messages that are send to a base.