public class Container
extends java.lang.Object
RealTimePlatform
.
By default, messages sent between agents are not cloned. The developer must
ensure that a message or any object contained in the message is not modified
after it has been sent or received. During deployment, this default behavior
can be changed using setAutoClone(boolean)
.
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<AgentID,Agent> |
agents |
protected java.util.Map<AgentID,Agent> |
agentsToAdd |
protected boolean |
autoclone |
protected java.lang.Object |
cloner |
protected java.lang.reflect.Method |
doClone |
static java.lang.String |
FAST_CLONER |
protected java.util.Set<AgentID> |
idle |
protected boolean |
inited |
protected boolean |
initing |
protected java.util.Set<MessageListener> |
listeners |
protected java.util.logging.Logger |
log |
protected java.lang.String |
name |
protected Platform |
platform |
protected boolean |
running |
static java.lang.String |
SERIAL_CLONER |
protected java.util.Map<java.lang.String,java.util.Set<AgentID>> |
services |
protected java.util.Map<AgentID,java.util.Set<Agent>> |
topics |
Constructor and Description |
---|
Container(Platform platform)
Creates a container.
|
Container(Platform platform,
java.lang.String name)
Creates a named container.
|
Modifier and Type | Method and Description |
---|---|
AgentID |
add(Agent agent)
Adds an agent to the container.
|
AgentID |
add(java.lang.String name,
Agent agent)
Adds an agent to the container.
|
boolean |
addListener(MessageListener listener)
Adds a listener to the container.
|
AgentID |
agentForService(java.lang.String service)
Finds an agent providing a named service.
|
AgentID[] |
agentsForService(java.lang.String service)
Finds all agents providing a named service.
|
boolean |
canLocateAgent(AgentID aid)
Checks if an agent can be located.
|
<T extends java.io.Serializable> |
clone(T obj)
Deep clones an object.
|
boolean |
containsAgent(AgentID aid)
Checks if an agent exists in the container.
|
void |
deregister(AgentID aid)
Deregisters an agent as a provider of all services.
|
boolean |
deregister(AgentID aid,
java.lang.String service)
Deregisters an agent as a provider of a specific service.
|
Agent |
getAgent(AgentID aid)
Gets an agent given its id.
|
AgentID[] |
getAgents()
Gets all agent ids in the container.
|
boolean |
getAutoClone()
Returns whether autoclone is enabled.
|
java.lang.String |
getName()
Gets the name of the container.
|
Platform |
getPlatform()
Gets the platform on which the container runs.
|
java.lang.String[] |
getServices()
Gets a list of all services that agents in this container provide.
|
java.lang.String |
getState()
Gets human readble state information for container.
|
protected void |
initComplete()
Called when the container is initialized.
|
protected boolean |
isDuplicate(AgentID aid)
Checks if an agent id already exists in the container.
|
boolean |
isIdle()
Checks if all agents in the container are idle.
|
boolean |
isRunning()
Checks if the container is currently running.
|
boolean |
kill(AgentID aid)
Terminates an agent.
|
boolean |
kill(java.lang.String name)
Terminates an agent.
|
boolean |
register(AgentID aid,
java.lang.String service)
Registers an agent in the directory service as a provider of a named service.
|
boolean |
removeListener(MessageListener listener)
Removes a listener from the container.
|
boolean |
send(Message m)
Sends a message.
|
boolean |
send(Message m,
boolean relay)
Sends a message.
|
void |
setAutoClone(boolean b)
Enables or disables autocloning.
|
void |
setCloner(java.lang.String name)
Sets the cloner to use for deep cloning.
|
void |
setName(java.lang.String name)
Sets the name of the container.
|
void |
shutdown()
Terminates the container and all agents in it.
|
protected void |
start()
Starts the container and all agents in it.
|
boolean |
subscribe(AgentID aid,
AgentID topic)
Subscribes an agent to messages sent to a topic.
|
java.lang.String |
toString()
Gets a string representation of the container.
|
void |
unsubscribe(AgentID aid)
Unsubscribes an agent from all topics.
|
boolean |
unsubscribe(AgentID aid,
AgentID topic)
Unsubscribes an agent from a topic.
|
public static final java.lang.String SERIAL_CLONER
public static final java.lang.String FAST_CLONER
protected java.lang.String name
protected Platform platform
protected java.util.Map<java.lang.String,java.util.Set<AgentID>> services
protected java.util.logging.Logger log
protected boolean running
protected boolean initing
protected boolean inited
protected java.lang.Object cloner
protected java.lang.reflect.Method doClone
protected boolean autoclone
protected java.util.Set<AgentID> idle
protected java.util.Set<MessageListener> listeners
public Container(Platform platform)
platform
- platform on which the container runs.public Container(Platform platform, java.lang.String name)
platform
- platform on which the container runs.name
- name of the container.public Platform getPlatform()
public void setName(java.lang.String name)
name
- name of the container.public java.lang.String getName()
public void setCloner(java.lang.String name)
name
- name of the cloner to use.public <T extends java.io.Serializable> T clone(T obj)
obj
- object to clone.public void setAutoClone(boolean b)
b
- true to enable autocloning, false to disable it.public boolean getAutoClone()
public AgentID add(java.lang.String name, Agent agent)
Agent names should only contain alphanumeric characters and underscores. The first character should not be a digit. Names with special characters such as '-', '.', '@', etc are considered reserved and should be avoided.
While agent names inconsistent with this guideline may not be rejected today, they may not work well on all platforms. In future, we may enforce this guideline more strictly.
name
- name of the agent.agent
- the agent object.public AgentID add(Agent agent)
agent
- the agent object.public boolean containsAgent(AgentID aid)
aid
- agent id to check.public boolean canLocateAgent(AgentID aid)
aid
- agent id to locate.public Agent getAgent(AgentID aid)
aid
- agent id.public AgentID[] getAgents()
public boolean kill(AgentID aid)
aid
- id of agent to terminate.public boolean kill(java.lang.String name)
name
- name of agent to terminate.public boolean addListener(MessageListener listener)
listener
- listener.public boolean removeListener(MessageListener listener)
listener
- listener.public boolean send(Message m)
m
- message to deliverpublic boolean send(Message m, boolean relay)
m
- message to deliverrelay
- enable relaying to associated remote containers.public boolean subscribe(AgentID aid, AgentID topic)
aid
- id of agent to subscribe.topic
- topic to subscribe to.public boolean unsubscribe(AgentID aid, AgentID topic)
aid
- id of agent to unsubscribe.topic
- topic to unsubscribe from.public void unsubscribe(AgentID aid)
aid
- id of agent to unsubscribe.public boolean register(AgentID aid, java.lang.String service)
aid
- id of agent providing the service.service
- name of the service.public java.lang.String[] getServices()
public AgentID agentForService(java.lang.String service)
service
- name of the service.public AgentID[] agentsForService(java.lang.String service)
service
- name of the service.public boolean deregister(AgentID aid, java.lang.String service)
aid
- id of agent to deregister.service
- name of the service to deregister.public void deregister(AgentID aid)
aid
- id of agent to deregister.protected void initComplete()
protected void start()
public void shutdown()
public boolean isRunning()
public boolean isIdle()
public java.lang.String getState()
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
protected boolean isDuplicate(AgentID aid)
aid
- the agent id to check.