ajanta.agent
Class Agent

java.lang.Object
  |
  +--ajanta.agent.Agent
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ItinAgent, ReportableAgent, SecureAgent

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

The Agent class is the generic mobile agent. It serves as the base class for all agents. Application-specific agents should be programmed as sub-classes of Agent.

See Also:
Credentials, AgentStatus, Serialized Form

Field Summary
 byte[] creatorSignature
          signature of the credential signed by creator of the agent
 ajanta.agent.Credentials cred
          Credentials of the agent
 ajanta.server.AgentEnv host
          host is the object reference to the current server's environment object.
 java.lang.Object myRef
           
 ajanta.naming.URN name
          URN ( name ) of the agent
 byte[] ownerSignature
          signature of the credential signed by owner of the agent
 ajanta.agent.AgentStatus status
          status object is modified whenever a recall request is pending.
 
Constructor Summary
Agent()
          Default constructor of the agent which assigns cred, host, ownerSignature and creatorSignature as null
Agent(ajanta.agent.Credentials cred)
          It assigns host, ownerSignature and creatorSignature as null.
Agent(ajanta.agent.Credentials cred, ajanta.server.AgentEnv host)
          It assigns ownerSignature and creatorSignature as null.
 
Method Summary
 void agentEntry()
          It system defined entry protocol and is the first method to be automatically executed every time an agent arrives at a server.
 void agentExit()
          Agent's server executes this method just before it is sent off to another server.
abstract  void arrive()
          The arrive() method represents an entry protocol.
 void colocate(ajanta.naming.URN target)
          This method is called to relocate the agent at the server where a specified "target" object is currently resident.
 void colocate(ajanta.naming.URN target, ajanta.util.MethodSpec as)
          This method is called to relocate the agent at the server where a specified "target" object is currently resident.
abstract  void depart()
          The depart() method represents an exit protocol.
 void meet(ajanta.naming.URN reportTo, ajanta.util.MethodSpec as)
          This method acts as the starting point of execution for an agent when it is relocated at a server.
 void recallCommand(ajanta.naming.URN whoInvoked, ajanta.naming.URN reportTo)
          This method is executed by the agent server currenlty hosting this agent when it receives a recall request for this agent.
 void run()
          It is a empty method which can be overridden in subclasses.
 void signCreator(ajanta.naming.URN serverURN, ajanta.server.AgentEnv host)
          It signs the credentials byte of the agent with specified server's ( creator) private keys and store it in creatorSignature
 void signOwner()
          It signs the credentials byte of the agent with owner's private keys and store it in ownerSignature
 void start(ajanta.server.AgentEnv host, ajanta.naming.URN dest, ajanta.util.MethodSpec action)
          After agent has been created this method is called to launch the agent to appropriate server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

public ajanta.naming.URN name
URN ( name ) of the agent


cred

public ajanta.agent.Credentials cred
Credentials of the agent


ownerSignature

public byte[] ownerSignature
signature of the credential signed by owner of the agent


creatorSignature

public byte[] creatorSignature
signature of the credential signed by creator of the agent


host

public transient ajanta.server.AgentEnv host
host is the object reference to the current server's environment object.


status

public ajanta.agent.AgentStatus status
status object is modified whenever a recall request is pending. This information is checked in the agentExit method, which is executed when the agent is about to leave a server.


myRef

public java.lang.Object myRef
Constructor Detail

Agent

public Agent()
Default constructor of the agent which assigns cred, host, ownerSignature and creatorSignature as null


Agent

public Agent(ajanta.agent.Credentials cred)
It assigns host, ownerSignature and creatorSignature as null. cred is assigned to the Credentials passed as argument.


Agent

public Agent(ajanta.agent.Credentials cred,
             ajanta.server.AgentEnv host)
It assigns ownerSignature and creatorSignature as null. cred is assigned to the Credentials object passed as argument and host to AgentEnv object.

Method Detail

agentEntry

public final void agentEntry()
It system defined entry protocol and is the first method to be automatically executed every time an agent arrives at a server.


arrive

public abstract void arrive()
The arrive() method represents an entry protocol. It is automatically executed every time an agent arrives at a server. It is an abstract method, and must be overridden in subclasses to define the application-specific entry protocol.


depart

public abstract void depart()
The depart() method represents an exit protocol. It is automatically executed every time an agent leaves a server. It is an abstract method, and must be overridden in subclasses to define the application-specific exit protocol.


agentExit

public final void agentExit()
Agent's server executes this method just before it is sent off to another server. It checks agent's status to find whether a recall is pending or not. If a recall is pending then it colocate the agent to returnTo server set in recall command . If returnTo is not set then it is colocated to guardian of the agent.


run

public void run()
It is a empty method which can be overridden in subclasses. This is the default method which get executed on a server if no other method is specified


start

public void start(ajanta.server.AgentEnv host,
                  ajanta.naming.URN dest,
                  ajanta.util.MethodSpec action)
           throws LaunchFailedException,
                  java.net.UnknownHostException
After agent has been created this method is called to launch the agent to appropriate server.

Parameters:
host - AgentEnv instance representing server's environment
dest - URN of the destination server
action - MethodSpec representing the method to be executed on the server if null then run method is executed
LaunchFailedException
java.net.UnknownHostException

colocate

public void colocate(ajanta.naming.URN target)
This method is called to relocate the agent at the server where a specified "target" object is currently resident.

Parameters:
target - URN of the target object

colocate

public void colocate(ajanta.naming.URN target,
                     ajanta.util.MethodSpec as)
This method is called to relocate the agent at the server where a specified "target" object is currently resident. It execute the meet method on the server. Meet method execute the specified method in the MethodSpec

Parameters:
target - URN of the target object
as - MethodSpec representing the method to be executed by meet method

meet

public void meet(ajanta.naming.URN reportTo,
                 ajanta.util.MethodSpec as)
          throws java.lang.Exception
This method acts as the starting point of execution for an agent when it is relocated at a server. The meet method contains the specification of the actions to be performed by the agent when it is relocated.

java.lang.Exception

recallCommand

public void recallCommand(ajanta.naming.URN whoInvoked,
                          ajanta.naming.URN reportTo)
This method is executed by the agent server currenlty hosting this agent when it receives a recall request for this agent. It set the recallPending status of the agent to true.

Parameters:
whoInvoked - URN of the recaller
reportTo - URN of object with whom agent has to colocate on recall

signCreator

public void signCreator(ajanta.naming.URN serverURN,
                        ajanta.server.AgentEnv host)
It signs the credentials byte of the agent with specified server's ( creator) private keys and store it in creatorSignature

Parameters:
serverURN - URN of the creator of the agent

signOwner

public void signOwner()
It signs the credentials byte of the agent with owner's private keys and store it in ownerSignature