unsw.cse.mica.agent
Class DefaultAgent

java.lang.Object
  extended by unsw.cse.mica.agent.DefaultAgent
All Implemented Interfaces:
Agent, MessageHandler
Direct Known Subclasses:
ProxyAgent

public abstract class DefaultAgent
extends java.lang.Object
implements Agent

The Default Agent is a utility class that inherits from the Agent class. It has implementations of the setTransport() and getTransport() methods, which are a reasonable default.

Generally, it is better to subclass DefaultAgent for most applications than to implement Agent. In future, more utility features are likely to be added to DefaultAgent.

Author:
waleed

Constructor Summary
DefaultAgent()
           
 
Method Summary
 AgentTransport getTransport()
          Get the current agent transport.
 void handleDeletedMob(Mob m)
          The default implementation of handleDeletedMob() does nothing.
abstract  void handleNewMob(Mob m)
          This method is called when a new MICA object has arrived.
 void handleReplacedMob(Mob oldMob, Mob newMob)
          The default implementation of handleReplacedMob() does nothing.
 void handleTypeManagerChanged()
          The default implementation of handleTypeManagerChanged() does nothing.
abstract  void init(MicaProperties args)
          Start the agent.
 void setTransport(AgentTransport at)
          Set the agent transport.
 void terminate()
          The default implementation of terminate() does nothing.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultAgent

public DefaultAgent()
Method Detail

setTransport

public void setTransport(AgentTransport at)
Set the agent transport. All future requests for blackboard connections will go through this agent transport.

Specified by:
setTransport in interface Agent
Parameters:
at - The agent transport.

getTransport

public AgentTransport getTransport()
Get the current agent transport.

Specified by:
getTransport in interface Agent
Returns:
The current agent transport.

init

public abstract void init(MicaProperties args)
                   throws MicaException
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
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.
Throws:
MicaException

terminate

public void terminate()
               throws MicaException
The default implementation of terminate() does nothing.

Specified by:
terminate in interface Agent
Throws:
MicaException

handleNewMob

public abstract void handleNewMob(Mob m)
Description copied from interface: MessageHandler
This method is called when a new MICA object has arrived.

Whenever a mob is written to the blackboard that the agent has registered an interest in the handleNewMob is called. It is passed the new Mob (MICA object) as a parameter so it can decide any further actions.

Note: The handleNewMob is called asynchronously. You should not make any assumptions about its synchronizations.

Specified by:
handleNewMob in interface MessageHandler
Parameters:
m - the mob that has been written to the blackboard

handleDeletedMob

public void handleDeletedMob(Mob m)
The default implementation of handleDeletedMob() does nothing.

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

handleReplacedMob

public void handleReplacedMob(Mob oldMob,
                              Mob newMob)
The default implementation of handleReplacedMob() does nothing.

Specified by:
handleReplacedMob in interface MessageHandler
Parameters:
oldMob - the old value of the mob (where the name is cleared)
newMob - the new value of the mob

handleTypeManagerChanged

public void handleTypeManagerChanged()
The default implementation of handleTypeManagerChanged() does nothing.

Specified by:
handleTypeManagerChanged in interface MessageHandler