com.cliftonsnyder.clutch
Class Agent

java.lang.Object
  extended by com.cliftonsnyder.clutch.Agent
All Implemented Interfaces:
java.io.Serializable, java.lang.Runnable
Direct Known Subclasses:
Mapper, Reducer

public abstract class Agent
extends java.lang.Object
implements java.io.Serializable, java.lang.Runnable

A mobile agent Object that will provide the basis for a Clutch network

Author:
Clifton L. Snyder
See Also:
Serialized Form

Nested Class Summary
static class Agent.State
           
 
Field Summary
protected  Agent.State agentState
          a variable representing the current state of the Agent
protected  java.util.List<Agent> ancestorList
          a list of all of the ancestors of the Agent (i.e., a List of all Agents in the path from this Agent to the "root" Agent)
protected  java.util.List<Agent> children
          a List of the children of the Agent
protected  java.lang.String id
          an identifier for the Agent
protected  int level
          an integer to be used for tracking the position of the Agent
protected  int maxPeers
          the maximum number of peers that the Agent will be allowed
protected  Agent parent
          the parent of the Agent
protected  ClutchState state
          contains state information about the Agent
 
Constructor Summary
Agent()
          an empty, parameterless constructor; this is necessary if this class is going to "play nice" with ProActive
Agent(ClutchState state)
          constructs a new Agent object, with maxPeers maximum peers
 
Method Summary
 void addChild(Agent child)
          adds a child to the list of this Agent's children
abstract  Agent createAgent(Node newAgentNode, Node newDataNode)
          method to be implemented by subclasses of Agent; this is where the interesting organization of a Clutch network will take place
 Agent.State getAgentState()
           
 java.util.List<Agent> getAncestorList()
           
 java.util.List<Agent> getChildren()
          getter for the children of this Agent
 java.lang.String getHostName()
          retrieves the hostname of the Agent
 java.lang.String getID()
          gets the ID of the Agent
 int getLevel()
          gets the position of the Agent wrt the other Agents in the system
 Agent getParent()
          getter for this Agent's parent
 Agent getRef()
          gets a reference to the Agent; this method is needed when programming with ProActive, as it may be necessary to return a reference to a remote stub (as opposed to a pointed to this)
abstract  boolean isNew()
          determines whether or not the Agent is newly created or is a current member of a Clutch network
 boolean isRoot()
           
static void main(java.lang.String[] args)
          usage: java [jvm args] com.cliftonsnyder.clutch.Agent [config file]
 void removeChild(int childIndex)
           
 void removeChild(java.lang.String id)
          removes a child from this Agent's List of children
 void setAgentState(Agent.State agentState)
           
 void setAncestorList(java.util.List<Agent> ancestorList)
           
 void setID(java.lang.String id)
          setter for the Agent's id
 void setLevel(int level)
          setter for the Agent's level
 void setMaxPeers(int maxPeers)
          sets the maximum number of peers that an Agent is allowed to have
 void setParent(Agent parent)
          setter for the Agent's parent
 void setState(ClutchState state)
          sets the state information for the Agent
abstract  void shutdown()
          shut down the Agent
abstract  java.lang.String status()
          gives a String representation of the current status of the Agent
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.lang.Runnable
run
 

Field Detail

agentState

protected Agent.State agentState
a variable representing the current state of the Agent


ancestorList

protected java.util.List<Agent> ancestorList
a list of all of the ancestors of the Agent (i.e., a List of all Agents in the path from this Agent to the "root" Agent)


children

protected java.util.List<Agent> children
a List of the children of the Agent


id

protected java.lang.String id
an identifier for the Agent


level

protected int level
an integer to be used for tracking the position of the Agent


maxPeers

protected int maxPeers
the maximum number of peers that the Agent will be allowed


parent

protected Agent parent
the parent of the Agent


state

protected ClutchState state
contains state information about the Agent

Constructor Detail

Agent

public Agent()
an empty, parameterless constructor; this is necessary if this class is going to "play nice" with ProActive


Agent

public Agent(ClutchState state)
constructs a new Agent object, with maxPeers maximum peers

Parameters:
maxPeers - the maximum number of peers that the Agent will be allowed
Method Detail

main

public static void main(java.lang.String[] args)
usage: java [jvm args] com.cliftonsnyder.clutch.Agent [config file]

Parameters:
args - this method takes a single (optional) argument, which is the path to a Clutch configuration file

addChild

public void addChild(Agent child)
adds a child to the list of this Agent's children

Parameters:
child - the child to be added

createAgent

public abstract Agent createAgent(Node newAgentNode,
                                  Node newDataNode)
method to be implemented by subclasses of Agent; this is where the interesting organization of a Clutch network will take place

Parameters:
agentInfo - the ProActive Node to which the eventual Agent is to be attached
Returns:
a newly constructed Agent object that is attached to the Clutch network (i.e., has a parent and possibly some children)

getAgentState

public Agent.State getAgentState()
Returns:
the state variable of this Agent

getAncestorList

public java.util.List<Agent> getAncestorList()
Returns:
the List of ancestors for this Agent

getChildren

public java.util.List<Agent> getChildren()
getter for the children of this Agent

Returns:
a List containing the children of this Agent

getHostName

public java.lang.String getHostName()
retrieves the hostname of the Agent

Returns:
the hostname of the Agent

getID

public java.lang.String getID()
gets the ID of the Agent

Returns:
the ID of the Agent

getLevel

public int getLevel()
gets the position of the Agent wrt the other Agents in the system

Returns:
the position of the Agent

getParent

public Agent getParent()
getter for this Agent's parent

Returns:
this Agent's parent

getRef

public Agent getRef()
gets a reference to the Agent; this method is needed when programming with ProActive, as it may be necessary to return a reference to a remote stub (as opposed to a pointed to this)

Returns:
a reference to the Agent

isNew

public abstract boolean isNew()
determines whether or not the Agent is newly created or is a current member of a Clutch network

Returns:
true iff the Agent is newly created, false otherwise

isRoot

public boolean isRoot()
Returns:
true iff this Agent has no parent - i.e., true if this Agent's parent variable is null; otherwise, false

removeChild

public void removeChild(java.lang.String id)
removes a child from this Agent's List of children

Parameters:
id - the id of the child to remove

removeChild

public void removeChild(int childIndex)
Parameters:
childIndex - removes the child at the specified index from this Agent's child List

setAgentState

public void setAgentState(Agent.State agentState)
Parameters:
agentState - sets this Agent's state variable to agentState, unless this Agent is already in the state SHUTDOWN or ERROR

setAncestorList

public void setAncestorList(java.util.List<Agent> ancestorList)
Parameters:
ancestorList - sets this Agent's list of ancestors

setID

public void setID(java.lang.String id)
setter for the Agent's id

Parameters:
id - the new id for the agent

setLevel

public void setLevel(int level)
setter for the Agent's level

Parameters:
level - the new level for the Agent

setMaxPeers

public void setMaxPeers(int maxPeers)
sets the maximum number of peers that an Agent is allowed to have

Parameters:
maxPeers - the maximum number of peers that an Agent is allowed to have

setParent

public void setParent(Agent parent)
setter for the Agent's parent

Parameters:
parent - the new parent for the Agent

setState

public void setState(ClutchState state)
sets the state information for the Agent

Parameters:
state - a ClutchState object with local state information about the Agent

shutdown

public abstract void shutdown()
shut down the Agent


status

public abstract java.lang.String status()
gives a String representation of the current status of the Agent

Returns:
a String representation of the current status of the Agent

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object