ajanta.server
Class AgentEnv

java.lang.Object
  |
  +--ajanta.server.AgentEnv

public class AgentEnv
extends java.lang.Object

class AgentEnv represents the server's context. A reference to an AgentEnv object is passed to each agent when it is executed. Methods in the AgentEnv class provide the agent with primitive operations like migration, resource binding, etc.


Method Summary
 void createRMIProxy(java.lang.String interf)
          Create and install an RMI server which has the same interface as the caller agent.
 void createRMIProxy(java.lang.String interf, java.lang.String extension)
          Create and install an RMI server which has the same interface as the caller agent.
 ajanta.naming.URN createURN(java.lang.String name)
          Create a URN by appending the given string onto the server's URN
 void deleteResource(ajanta.naming.URN name)
          Delete registered resource entry whose URN is passed as argument.
 ajanta.naming.URN getAgentServerURN()
           
 ajanta.naming.URN getAgentURN()
          Find the name currently executing agent in the same thread group.
 ajanta.naming.CascadedCertificate getCascadedCertificate(int key_length, long duration)
           
 ajanta.agent.Agent getCurrentAgent()
          Find the currently executing agent in the same thread group.
 ajanta.naming.URN getHostURN()
          Return the current host's name
 ajanta.server.NRAccess getNameReg()
          Return a reference to the name registry access class ( NRAccess ) of the current agent server.
 ajanta.util.Resource getResource(ajanta.naming.URN resName)
          Return an a proxy for the named resource and if it has not yet been registered then return null.
 java.security.PrivateKey getTemporaryPrivateKey()
           
 java.security.PublicKey getTemporaryPublicKey()
           
 void go(ajanta.naming.URN dest)
          Migrate caller to the specified destination and execute the (parameterless) "run" method
 void go(ajanta.naming.URN dest, ajanta.util.MethodSpec act)
          Migrate caller to the specified destination and execute the method specified in the MethodSpec
 void go(ajanta.naming.URN dest, java.lang.String method, java.lang.Class[] formals, java.lang.Object[] actuals)
          Migrate caller agent to a specified destination and execute the named method with the specified formal and actual parameters
 void go(ajanta.naming.URN dest, java.lang.String method, java.lang.Object[] actuals)
          Migrate caller to the specified destination and execute the named method with the given actual parameters, assuming they exactly match the formal parameter types.
 void launch(ajanta.agent.Agent ag, ajanta.naming.URN dest)
          Send specified agent to the named destination and execute the (parameterless) "run" method
 void launch(ajanta.agent.Agent ag, ajanta.naming.URN dest, ajanta.util.MethodSpec act)
          Send specified agent to the named destination and execute the method specified in the MethodSpec
 void launch(ajanta.agent.Agent ag, ajanta.naming.URN dest, java.lang.String method, java.lang.Class[] formals, java.lang.Object[] actuals, boolean first)
          Launch the given agent to the desired destination, specifying the method to be executed there.
 void launch(ajanta.agent.Agent ag, ajanta.naming.URN dest, java.lang.String method, java.lang.Object[] actuals)
          Launch agent to the specified destination and execute the named method with the given actual parameters, assuming they exactly match the formal parameter types.
 boolean logEvent(ajanta.logger.Event e)
           
 void registerAgent(ajanta.agent.Agent ag)
          Registers an agent with the name registry, If an older entry exists try to rebind.
 void registerResource(ajanta.naming.URN name, ajanta.util.Resource obj)
          It creates a resource ( RREntry ) in the agent server's resource registry with the given resource name and resource object
 void registerResourceName(ajanta.naming.URN name)
          It creates a resource ( RREntry) in the agent server's resource registry.
 byte[] sign(byte[] text)
          Sign an agent with the agent server's private key.
 ajanta.util.Resource waitForResource(ajanta.naming.URN resName)
          Return an a proxy for the named resource and if it has not yet been registered then wait for it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCurrentAgent

public ajanta.agent.Agent getCurrentAgent()
Find the currently executing agent in the same thread group.

Returns:
Reference to if one exists in current thread group and null otherwise
See Also:
Agent

getAgentURN

public ajanta.naming.URN getAgentURN()
Find the name currently executing agent in the same thread group.

Returns:
URN of the agent if one exists in current thread group and null otherwise
See Also:
URN

getNameReg

public ajanta.server.NRAccess getNameReg()
Return a reference to the name registry access class ( NRAccess ) of the current agent server.

Returns:
NRAccess object of the agent server.
See Also:
NRAccess

go

public void go(ajanta.naming.URN dest,
               java.lang.String method,
               java.lang.Class[] formals,
               java.lang.Object[] actuals)
        throws java.net.UnknownHostException,
               LaunchFailedException
Migrate caller agent to a specified destination and execute the named method with the specified formal and actual parameters

Parameters:
dest - URN of the destination
method - name of the method to execute
formals - array of class names of method parametrs
actuals - array of objects i.e. values of the parametrs to the method
java.net.UnknownHostException
LaunchFailedException

go

public void go(ajanta.naming.URN dest,
               java.lang.String method,
               java.lang.Object[] actuals)
        throws java.net.UnknownHostException,
               LaunchFailedException
Migrate caller to the specified destination and execute the named method with the given actual parameters, assuming they exactly match the formal parameter types.

Parameters:
dest - URN of the destination
method - name of the method to execute
actuals - array of objects i.e. values of the parametrs to the method
java.net.UnknownHostException
LaunchFailedException

go

public void go(ajanta.naming.URN dest)
        throws java.net.UnknownHostException,
               LaunchFailedException
Migrate caller to the specified destination and execute the (parameterless) "run" method

Parameters:
dest - URN of the destination
java.net.UnknownHostException
LaunchFailedException

go

public void go(ajanta.naming.URN dest,
               ajanta.util.MethodSpec act)
        throws java.net.UnknownHostException,
               LaunchFailedException
Migrate caller to the specified destination and execute the method specified in the MethodSpec

Parameters:
dest - URN of the destination
act - MethodSpec of the method tb executed at destination
java.net.UnknownHostException
LaunchFailedException
See Also:
MethodSpec

launch

public void launch(ajanta.agent.Agent ag,
                   ajanta.naming.URN dest,
                   java.lang.String method,
                   java.lang.Class[] formals,
                   java.lang.Object[] actuals,
                   boolean first)
            throws LaunchFailedException
Launch the given agent to the desired destination, specifying the method to be executed there. It is internally called by go methods with first = false.

Parameters:
ag - Reference to the agent being launched
dest - URN of the destination
method - name of the method to execute
formals - array of class names of method parametrs
actuals - array of objects i.e. values of the parametrs to the method
first - true indicate very first launch of the agent ( just after creation ) wheras false indicates a luanch at a later stage in the itinerary
LaunchFailedException
See Also:
Agent

launch

public void launch(ajanta.agent.Agent ag,
                   ajanta.naming.URN dest,
                   java.lang.String method,
                   java.lang.Object[] actuals)
            throws java.net.UnknownHostException,
                   LaunchFailedException
Launch agent to the specified destination and execute the named method with the given actual parameters, assuming they exactly match the formal parameter types.

Parameters:
ag - Reference to the agent being launched
dest - URN of the destination
method - name of the method to execute
actuals - array of objects i.e. values of the parametrs to the method
java.net.UnknownHostException
LaunchFailedException
See Also:
Agent

launch

public void launch(ajanta.agent.Agent ag,
                   ajanta.naming.URN dest)
            throws java.net.UnknownHostException,
                   LaunchFailedException
Send specified agent to the named destination and execute the (parameterless) "run" method

Parameters:
ag - Reference to the agent being launched
dest - URN of the destination
java.net.UnknownHostException
LaunchFailedException
See Also:
Agent

launch

public void launch(ajanta.agent.Agent ag,
                   ajanta.naming.URN dest,
                   ajanta.util.MethodSpec act)
            throws java.net.UnknownHostException,
                   LaunchFailedException
Send specified agent to the named destination and execute the method specified in the MethodSpec

Parameters:
ag - Reference to the agent being launched
dest - URN of the destination
act - MethodSpec to be executed
java.net.UnknownHostException
LaunchFailedException
See Also:
ajnata.util.MethodSpec

getHostURN

public ajanta.naming.URN getHostURN()
Return the current host's name

Returns:
URN of the current agent server ( host )

registerResourceName

public void registerResourceName(ajanta.naming.URN name)
It creates a resource ( RREntry) in the agent server's resource registry. It just associate a null entry with the given URN of the resource. It is usefuel when someone has to wait for a resource which will be initialized by second party at a later stage. It helps in synchronizing them.

Parameters:
name - URN of the resource to be created

registerResource

public void registerResource(ajanta.naming.URN name,
                             ajanta.util.Resource obj)
It creates a resource ( RREntry ) in the agent server's resource registry with the given resource name and resource object

Parameters:
name - URN of the resource to be created
obj - Resource object to be registered
See Also:
Resource

deleteResource

public void deleteResource(ajanta.naming.URN name)
Delete registered resource entry whose URN is passed as argument.

Parameters:
name - URN of the resource

waitForResource

public ajanta.util.Resource waitForResource(ajanta.naming.URN resName)
Return an a proxy for the named resource and if it has not yet been registered then wait for it. The proxy to be returned depends on the credentials of the calling agent.Special case - if the resource being requested is this server,return a pointer to the agent server object itself

Parameters:
resName - URN of the resource
Returns:
Resource instance of the proxy for the requested resource.

getResource

public ajanta.util.Resource getResource(ajanta.naming.URN resName)
Return an a proxy for the named resource and if it has not yet been registered then return null. The proxy to be returned depends on the credentials of the calling agent.Special case - if the resource being requested is this server,return a pointer to the agent server object itself

Parameters:
resName - URN of the resource
Returns:
Resource instance of the proxy for the requested resource.

createURN

public ajanta.naming.URN createURN(java.lang.String name)
Create a URN by appending the given string onto the server's URN

Parameters:
name - - string used for urn
Returns:
newly creted URN of the form server urn: name

createRMIProxy

public void createRMIProxy(java.lang.String interf)
Create and install an RMI server which has the same interface as the caller agent. The proxy server has an embedded reference to the agent. It receives the RMI calls and forwards them to the agent. The interface, and the associated proxy class must currently be available on the agent server's classpath. It calls createRMIProxy (String interf,String extension) with extension as "".

Parameters:
interf - name of the "Remote" interface which the agent supports. Extension of the proxy class is "Proxy".

createRMIProxy

public void createRMIProxy(java.lang.String interf,
                           java.lang.String extension)
Create and install an RMI server which has the same interface as the caller agent. The proxy server has an embedded reference to the agent. It receives the RMI calls and forwards them to the agent. The interface, and the associated proxy class must currently be available on the agent server's classpath.

Parameters:
interf - name of the "Remote" interface which the agent supports.
extension - file name extension of the proxy class name, if it is "" then by default "Proxy" is used as extension.

registerAgent

public void registerAgent(ajanta.agent.Agent ag)
Registers an agent with the name registry, If an older entry exists try to rebind.

Parameters:
ag - Agent to be registered

sign

public byte[] sign(byte[] text)
            throws java.security.SignatureException
Sign an agent with the agent server's private key.

Parameters:
text - Content to be signed
java.security.SignatureException

getCascadedCertificate

public ajanta.naming.CascadedCertificate getCascadedCertificate(int key_length,
                                                                long duration)

getTemporaryPrivateKey

public java.security.PrivateKey getTemporaryPrivateKey()

getTemporaryPublicKey

public java.security.PublicKey getTemporaryPublicKey()

logEvent

public boolean logEvent(ajanta.logger.Event e)

getAgentServerURN

public ajanta.naming.URN getAgentServerURN()