projectinfosearch
Class AgentObject

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--projectinfosearch.AgentObject
All Implemented Interfaces:
Agent, java.lang.Runnable, java.io.Serializable

public class AgentObject
extends java.lang.Thread
implements Agent, java.io.Serializable

represents a virtual agent able to travel to different servers and achieve a given task

See Also:
Serialized Form

Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AgentObject(java.net.InetAddress homeAddr, int homePort)
          "Stores" the home address and the home port
 
Method Summary
 void agentArrived(AgentServer srv, java.net.InetAddress srvInetAddress, int serverPort)
          When an AgentObject arrives at a server, this method is invoqued.
 int getCounter()
          returns the counter which counts the number of visited servers
 java.net.InetAddress getHomeAddress()
          returns the homeAddress
 int getHomePort()
          returns the homePort
 java.lang.String getState()
          returns the current state of the AgentObject
 java.util.Vector getSum()
          returns the vector containing the sums computed at the visited AgentServers
 java.lang.String getTask()
          returns the task of the AgentObject
 java.util.Vector getVisitedServers()
          returns the vector containing the visited AgentServers
 void run()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AgentObject

public AgentObject(java.net.InetAddress homeAddr,
                   int homePort)
"Stores" the home address and the home port
Parameters:
-homeAddr - represents the InetAddress of the AgentClient where the agent was created
-homePort - represents the port number of the AgentClient where the agent was created
Method Detail

agentArrived

public void agentArrived(AgentServer srv,
                         java.net.InetAddress srvInetAddress,
                         int serverPort)
When an AgentObject arrives at a server, this method is invoqued. It starts a thread which searches for a file called number.text and adds the number it contains if it exists. The sum is stored in a Vector. Then it asks the server for its neighbors and asks to be sent to one of them. If all the neighbors have already been visited, it asks to be sent home. This method also adds the AgentServer's servrePort and InetAddress to the visitedServer Vector
Specified by:
agentArrived in interface Agent
Parameters:
srv - is an object representing an AgentServer where the AgentObject currently lives.
srvInetAddress - is the InetAddress of the AgentServer where the AgentObject currently lives.
serverPort - is the serverPort number of the AgentServer where the AgentObject currently lives.

run

public void run()
Overrides:
run in class java.lang.Thread

getHomeAddress

public java.net.InetAddress getHomeAddress()
returns the homeAddress
Returns:
-homeAddr of the AgentObject

getHomePort

public int getHomePort()
returns the homePort
Returns:
-homePort of the AgentObject

getState

public java.lang.String getState()
returns the current state of the AgentObject
Returns:
-state of the AgentObject

getTask

public java.lang.String getTask()
returns the task of the AgentObject
Returns:
-task of the AgentObject

getSum

public java.util.Vector getSum()
returns the vector containing the sums computed at the visited AgentServers
Returns:
-vector containing the sums

getCounter

public int getCounter()
returns the counter which counts the number of visited servers
Returns:
-counter

getVisitedServers

public java.util.Vector getVisitedServers()
returns the vector containing the visited AgentServers
Returns:
-vector containing the visited AgentServers