magenta
Class Agent

java.lang.Object
  |
  +--java.util.Observable
        |
        +--magenta.GdmoObject
              |
              +--magenta.AgentProxy
                    |
                    +--magenta.Agent
Direct Known Subclasses:
CLIManager, GUIManager, Nqueens, Queen

public class Agent
extends AgentProxy

class Agent - GdmoObject that forms foundation of Magenta.

Contains the components:

The Agent class does not handle events or have any interface but it contains the foundation upon which these applications can be built. Managers can be implemented by subclassing Agent and overriding the handleEvent method and using the hooks into the Agent's subcomponents provided by getObjectManager, getComManager, etc.

This class can be invoked from the commandline as follows. If hostname and port are not specified, they default to localhost:4444.

  usage: java magenta.Agent [hostname:port] 
  
GdmoObject attributes:
Port (ro) - port number which ComManager will listen on
HostName (ro) - hostname for this agent
HostInfo - sets port and hostname. Setting it for the first time starts the ComManager. It cannot be set after that.

Version:
2001.03.11 alokem creation
Author:
aloke mukherjee

Field Summary
private  ComManager cm
          handle to the internal ComManager component
static java.lang.String DEFAULTHOSTPORT
          default host:port that agent will listen on
private  EventManager em
          handle to the internal EventManager component
private  java.lang.String hostName
          hostname where this agent resides
private  ObjectManager om
          handle to the internal ObjectManager component
private  int port
          port this agent will listen on
 
Fields inherited from class magenta.AgentProxy
hostInfo
 
Fields inherited from class magenta.GdmoObject
classCtorCalls, instantiated, name, path
 
Fields inherited from class java.util.Observable
changed, obs
 
Constructor Summary
Agent(java.lang.String path, java.lang.String name)
          Agent constructor - Instantiate the components of a Magenta agent.
 
Method Summary
 ComManager getComManager()
          Agent::getComManager - get handle on ComManager.
 EventManager getEventManager()
          Agent::getEventManager - get handle on EventManager.
 java.lang.String getHostName()
          Agent::getHostName Access function for hostName member.
 ObjectManager getObjectManager()
          Agent::getObjectManager - access method for internal ObjectManager component
 int getPort()
          Agent::getPort - Access function for port member.
 java.lang.String handleEvent(java.lang.String eventreport)
          Agent::handleEvent - prints out an eventreport.
 void log(java.lang.String message)
          Agent::log - generic output method for debug related messages.
static void main(java.lang.String[] args)
          Agent main routine - The entry point for execution of this object.
 java.lang.String setHostInfo(java.lang.String newHostInfo)
          Agent::setHostInfo - set the hostname:port and start ComManager.
 
Methods inherited from class magenta.AgentProxy
getHostInfo, toString
 
Methods inherited from class magenta.GdmoObject
get, getName, getPath, set, setInstantiated, setName, updateClassCtorCalls
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

DEFAULTHOSTPORT

public static java.lang.String DEFAULTHOSTPORT
default host:port that agent will listen on

cm

private ComManager cm
handle to the internal ComManager component

em

private EventManager em
handle to the internal EventManager component

om

private ObjectManager om
handle to the internal ObjectManager component

hostName

private java.lang.String hostName
hostname where this agent resides

port

private int port
port this agent will listen on
Constructor Detail

Agent

public Agent(java.lang.String path,
             java.lang.String name)
Agent constructor - Instantiate the components of a Magenta agent. This form of constructor is required since this is derived class of GdmoObject.
Parameters:
path - path to the object in the objectmanager
name - name for this object in the objectmanager
Method Detail

setHostInfo

public java.lang.String setHostInfo(java.lang.String newHostInfo)
Agent::setHostInfo - set the hostname:port and start ComManager.
Overrides:
setHostInfo in class AgentProxy
Parameters:
newHostInfo - string in format hostname:port
Returns:
success or failure if hostinfo is incorrectly specified.

getComManager

public ComManager getComManager()
Agent::getComManager - get handle on ComManager.
Returns:
this Agent's ComManager object

getEventManager

public EventManager getEventManager()
Agent::getEventManager - get handle on EventManager.
Returns:
this Agent's EventManager object

getObjectManager

public ObjectManager getObjectManager()
Agent::getObjectManager - access method for internal ObjectManager component
Returns:
this Agent's ObjectManager object

log

public void log(java.lang.String message)
Agent::log - generic output method for debug related messages. Use this instead of System.out.println, so that the implementation of outputting debug messages can be centralized here. For example, override this method in a subclass to dump to message to a file instead of stdout or to provide more intelligent handling.
Parameters:
message - String object to be printed out or logged.

handleEvent

public java.lang.String handleEvent(java.lang.String eventreport)
Agent::handleEvent - prints out an eventreport. Override this method in a subclass to provide more intelligent handling.
Parameters:
eventreport - contents of event report.
Returns:
always returns "success"

getPort

public int getPort()
Agent::getPort - Access function for port member.
Returns:
the port on which this agent will accept new requests.

getHostName

public java.lang.String getHostName()
Agent::getHostName Access function for hostName member.
Returns:
the host where this agent resides.

main

public static void main(java.lang.String[] args)
Agent main routine - The entry point for execution of this object. Parse command-line arguments and instantiate Agent.
Parameters:
args - the command-line arguments