org.iids.aos.agentserver
Class AgentRunner

java.lang.Object
  extended by org.iids.aos.systemservices.module.AbstractModule
      extended by org.iids.aos.agentserver.AgentRunner
All Implemented Interfaces:
Module
Direct Known Subclasses:
BinaryAgentRunner, JavaAgentRunner

public abstract class AgentRunner
extends AbstractModule

Abstract AgentRunner superclass. An agent runner takes care of loading the agent code from the agent container, agent startup and termination. For each language that is to be supported for agents, one needs to implement the abstract functions present in this class, as well as the necessary agent wrappers for that specific language.

Author:
hidde (original java version), rjtimmer (abstract version)
See Also:
JavaAgentRunner, BinaryAgentRunner

Field Summary
protected  java.util.Hashtable<AgentID,AgentWrapper> agents
           
protected  AsCommunicator communicator
           
protected  AgentScapeConfig config
           
protected  java.util.Hashtable<AgentHandle,AgentID> handles
           
protected  HostManagerWrapper hostManagerWrapper
           
protected  AsLookupService lookupService
           
protected  AgentNegotiationLib neglib
           
protected  boolean running
           
protected  AgentRunnerServletModule servletModule
           
protected  AgentServer2WSGatewayModule wsGatewayModule
           
 
Constructor Summary
AgentRunner(java.lang.String modulename, AsCommunicator communicator, AgentScapeConfig config, AsLookupService lookupService, AgentServer2WSGatewayModule wsGatewayModule, AgentRunnerServletModule servletModule)
          Superclass of all agent runners.
 
Method Summary
 java.lang.String createDefaultAgentLease(AgentScapeID locationId, AgentHandle ah)
           
 java.lang.String createDefaultAgentLease(AgentScapeID locationId, AgentID aid)
          Create a default lease for an agent wanting to start/migrate.
 java.lang.String doHttpRequest(java.lang.String request)
           
protected  void finalize()
           
 int getAgentCPUtime(AgentHandle agentHandle)
           
 int getAgentCPUtime(AgentID agentID)
          Unimplemented, overload at will.
 AgentID getAgentId(AgentHandle agentHandle)
           
 java.util.Vector<AgentID> getAgents()
           
 Address getAgentServerAddress()
           
 AgentScapeID getAgentServerId()
           
 AsCommunicator getCommunicator()
           
 AgentWrapper getEntry(AgentID id)
          Obtain agent wrapper for a given agent.
abstract  java.lang.String getLanguage()
          Return a string with the language type of agents that can be run by this agent server.
 AgentNegotiationLib getNegotiationLib()
           
 boolean isStarted()
           
 void killAgent(AgentHandle agentHandle)
           
 void killAgent(AgentID agentID)
          Completely remove agent from the AgentScape host/location.
 void removeAgent(AgentHandle agentHandle)
           
abstract  void removeAgent(AgentID agentId)
          Remove agent from the agent runner.
 void setHostManagerWrapper(HostManagerWrapper hmw)
           
abstract  void shutdown()
           
 void start()
          Start the agent server.
abstract  void startAgent(AgentID agentId, java.lang.String[] args)
          Start agent from agent container.
 void stop()
          Stop the agent server, including all of the agents it has running.
abstract  void suspendAgent(AgentID agentId)
          Suspend and, if supported, serialize state of a running agent.
 
Methods inherited from class org.iids.aos.systemservices.module.AbstractModule
getModuleName
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hostManagerWrapper

protected HostManagerWrapper hostManagerWrapper

config

protected AgentScapeConfig config

communicator

protected AsCommunicator communicator

lookupService

protected AsLookupService lookupService

wsGatewayModule

protected AgentServer2WSGatewayModule wsGatewayModule

neglib

protected AgentNegotiationLib neglib

servletModule

protected AgentRunnerServletModule servletModule

agents

protected java.util.Hashtable<AgentID,AgentWrapper> agents

handles

protected java.util.Hashtable<AgentHandle,AgentID> handles

running

protected boolean running
Constructor Detail

AgentRunner

public AgentRunner(java.lang.String modulename,
                   AsCommunicator communicator,
                   AgentScapeConfig config,
                   AsLookupService lookupService,
                   AgentServer2WSGatewayModule wsGatewayModule,
                   AgentRunnerServletModule servletModule)
Superclass of all agent runners. It sets up the configuration and negotiation library for any specific AgentRunner subclass. The methods that are to be available through the AsCommunicator are also published.

Method Detail

getEntry

public AgentWrapper getEntry(AgentID id)
                      throws AgentIDUnknownException
Obtain agent wrapper for a given agent.

Throws:
AgentIDUnknownException

start

public void start()
Start the agent server.


stop

public void stop()
Stop the agent server, including all of the agents it has running.


isStarted

public boolean isStarted()

getNegotiationLib

public AgentNegotiationLib getNegotiationLib()

setHostManagerWrapper

public void setHostManagerWrapper(HostManagerWrapper hmw)

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

getAgents

public final java.util.Vector<AgentID> getAgents()

getAgentCPUtime

public int getAgentCPUtime(AgentID agentID)
                    throws AgentIDUnknownException
Unimplemented, overload at will.

Throws:
AgentIDUnknownException

getAgentCPUtime

public int getAgentCPUtime(AgentHandle agentHandle)
                    throws AgentUnknownException
Throws:
AgentUnknownException

startAgent

public abstract void startAgent(AgentID agentId,
                                java.lang.String[] args)
                         throws AgentIDUnknownException,
                                AgentStartupException
Start agent from agent container.

The agent is supposed to be already registered with the registration service. The runner takes care of reading the code segment(s) from the container and doing agent startup.

Parameters:
agentId - ID of the agent the will be associated with the running agent.
args - Optional (may be null or empty) initialization arguments for the agent.
Throws:
AgentIDUnknownException
AgentStartupException

suspendAgent

public abstract void suspendAgent(AgentID agentId)
                           throws AgentIDUnknownException,
                                  AgentSuspendException
Suspend and, if supported, serialize state of a running agent.

After an agent is suspended, it can be (re) moved. The most recent state of the agent is now supposed to be stored in the agent container, so the agent can be safely migrated.

Throws:
AgentIDUnknownException
AgentSuspendException

removeAgent

public abstract void removeAgent(AgentID agentId)
                          throws AgentIDUnknownException
Remove agent from the agent runner.

If the agent (process) is still running, it is to be terminated, if this is supported by the language.

Note that this function does not (need to) remove the agent from the location (deregistration), which is done via the host manager. When you want to completely remove an agent, you can use the killAgent(org.iids.aos.systemservices.communicator.structs.AgentID) function, which implicitly calls this removeAgent function.

TODO: think about exceptions.

Parameters:
agentId - ID of the agent to be removed.
Throws:
AgentIDUnknownException

removeAgent

public void removeAgent(AgentHandle agentHandle)
                 throws AgentUnknownException
Throws:
AgentUnknownException

getLanguage

public abstract java.lang.String getLanguage()
Return a string with the language type of agents that can be run by this agent server. This is useful so that any part of the system can ask any agent server which agent language it is capable of running.


createDefaultAgentLease

public java.lang.String createDefaultAgentLease(AgentScapeID locationId,
                                                AgentID aid)
                                         throws NegotiationLibException
Create a default lease for an agent wanting to start/migrate. This one basically creates a lease with only the runtime environment specified. This is to hide lease details from parties that do not wish to be bothered by this.

In this sense it is quite similar to the createEmptyLeaseRequest function, with the only exception being that the 'language' field of environment resource is specified. The language is the same as the language supported by this agent runner.

The lease is sent to the target location,

Parameters:
locationId - The target location for the lease.
aid - The AgentID of the agent that initiated the lease creation
Returns:
lease identifier suitable for AgentScape.move() and createAgent function calls.
Throws:
NegotiationLibException - If the lease could not be created.

createDefaultAgentLease

public java.lang.String createDefaultAgentLease(AgentScapeID locationId,
                                                AgentHandle ah)
                                         throws NegotiationLibException,
                                                AgentUnknownException
Throws:
NegotiationLibException
AgentUnknownException

killAgent

public final void killAgent(AgentID agentID)
                     throws AgentIDUnknownException
Completely remove agent from the AgentScape host/location. This function requests the host manager to remove the agent from the host/location. This function is preferred over the removeAgent(org.iids.aos.systemservices.communicator.structs.AgentID) function, because the host manager also takes care of deregistration of the agent.

Throws:
SomeException - When agentID is not known by this instance of the agent runner.
AgentIDUnknownException

killAgent

public void killAgent(AgentHandle agentHandle)
               throws AgentUnknownException
Throws:
AgentUnknownException

getAgentId

public AgentID getAgentId(AgentHandle agentHandle)
                   throws AgentUnknownException
Throws:
AgentUnknownException

getAgentServerId

public AgentScapeID getAgentServerId()

getAgentServerAddress

public Address getAgentServerAddress()

shutdown

public abstract void shutdown()

getCommunicator

public AsCommunicator getCommunicator()
Specified by:
getCommunicator in interface Module
Overrides:
getCommunicator in class AbstractModule

doHttpRequest

public java.lang.String doHttpRequest(java.lang.String request)


Copyright © 2003, 2004 IIDS Group. All Rights Reserved.