unsw.cse.mica.tools.proxy
Class ProxyAgent

java.lang.Object
  extended by unsw.cse.mica.agent.DefaultAgent
      extended by unsw.cse.mica.tools.proxy.ProxyAgent
All Implemented Interfaces:
Agent, MessageHandler

public class ProxyAgent
extends DefaultAgent

A ProxyAgent handles the reading and writing of Proxy objects to and from a server.

Author:
Mark Reid

Constructor Summary
ProxyAgent()
           
 
Method Summary
 void add(ProxySet set)
          Add a new proxy set for this ProxyAgent to manage communications for.
 boolean delete(Proxy proxy)
          Remove the Mob corresponding to the given Proxy object from the Swarm server.
 java.util.List getMobs(java.lang.String type)
          Return a List of Mobs on te server with the given type.
 void handleDeletedMob(Mob m)
          Deleted Mobs are turned into Proxy objects and removed from the ProxySet associated with the Mob's type.
 void handleNewMob(Mob m)
          A ProxyAgent handles new mobs by testing their type and adding a new Proxy object for that Mob to the ProxySet corresponding to the type.
 void handleTypeManagerChanged()
          The default implementation of handleTypeManagerChanged() does nothing.
 void init(MicaProperties args)
          Start the agent.
 boolean write(Proxy proxy)
          Writes the given Proxy object to the server as a Mob, updating the Proxy object's MobId field accordingly.
 
Methods inherited from class unsw.cse.mica.agent.DefaultAgent
getTransport, handleReplacedMob, setTransport, terminate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProxyAgent

public ProxyAgent()
Method Detail

init

public void init(MicaProperties args)
Description copied from interface: Agent
Start the agent.

This signals to the agent that it should start.

Note: This function should not block -- it should return in a relatively short period of time, so that other parts of the Agent startup program can continue. If necessary, start your own thread to do your bidding.

It is safe to assume that by the time init() is called, setTransport() has been called.

The usual contents of an init() method would be:

Specified by:
init in interface Agent
Specified by:
init in class DefaultAgent
Parameters:
args - Additional arguments provided to the agent. If the agent is started from with the 'Runner' tool, the args array contains the values provided from within the runner's XML configuration file. Otherwise, the exact contents will depend on the calling method.

add

public void add(ProxySet set)
         throws MicaException
Add a new proxy set for this ProxyAgent to manage communications for. This method adds the set to this agent, configures the set so its agent is this and registers this agent for the set's mob types.

Parameters:
set - A new ProxySet that this ProxyAgent will handle.
Throws:
MicaException

write

public boolean write(Proxy proxy)
              throws MicaException
Writes the given Proxy object to the server as a Mob, updating the Proxy object's MobId field accordingly.

Parameters:
proxy - The proxy whose Mob should be written to the server
Returns:
true iff the Proxy was successfully written.
Throws:
MicaException

delete

public boolean delete(Proxy proxy)
Remove the Mob corresponding to the given Proxy object from the Swarm server.

Parameters:
proxy - The Proxy object whose Mob representation on the server is to be deleted.
Returns:
true if the Mob was successfully removed.

getMobs

public java.util.List getMobs(java.lang.String type)
                       throws MicaException
Return a List of Mobs on te server with the given type.

Parameters:
type - The type of mobs to return
Returns:
a List of Mobs on the server with the given type
Throws:
MicaException

handleNewMob

public void handleNewMob(Mob m)
A ProxyAgent handles new mobs by testing their type and adding a new Proxy object for that Mob to the ProxySet corresponding to the type.

Specified by:
handleNewMob in interface MessageHandler
Specified by:
handleNewMob in class DefaultAgent
Parameters:
m - the mob that has been written to the blackboard
See Also:
DefaultAgent.handleNewMob(unsw.cse.mica.data.Mob)

handleDeletedMob

public void handleDeletedMob(Mob m)
Deleted Mobs are turned into Proxy objects and removed from the ProxySet associated with the Mob's type.

Specified by:
handleDeletedMob in interface MessageHandler
Overrides:
handleDeletedMob in class DefaultAgent
Parameters:
m - the mob that has been deleted

handleTypeManagerChanged

public void handleTypeManagerChanged()
Description copied from class: DefaultAgent
The default implementation of handleTypeManagerChanged() does nothing.

Specified by:
handleTypeManagerChanged in interface MessageHandler
Overrides:
handleTypeManagerChanged in class DefaultAgent