agentland.resource
Class ManagedAgent

java.lang.Object
  |
  +--java.rmi.server.RemoteObject
        |
        +--java.rmi.server.RemoteServer
              |
              +--java.rmi.server.UnicastRemoteObject
                    |
                    +--metaglue.AgentAgent
                          |
                          +--agentland.util.GoodAgent
                                |
                                +--agentland.resource.ManagedAgent
All Implemented Interfaces:
Agent, Good, Managed, MetagluePrimitives, Remote, Serializable, Spy
Direct Known Subclasses:
AlphaLEDSignAgent, AppGrammarAgent, BeeperAgent, ConfuciusWebAgent, ConnectionMonitorAgent, DaemonAgent, DeviceAgent, DisplayHTMLAgent, ExecAgent, ForwardingResourceManagerAgent, GrammarCenterAgent, GrammarInspectorAgent, GuiAskerAgent, GuiManagerAgent, HAL2001Agent, LEDManagerAgent, LoudMouthAgent, ManagedSpeechAgent, MessAgent, MSWindowAgent, MultimodalAskerAgent, NewsModelAgent, NewsWallGuiAgent, NewsWallScrollAgent, ProjectionScreenMetaAgent, ProjectionScreenSpeechAgent, RandomThoughtAgent, ResolverAgent, ResourceRetrieverAgent, SAMAgent, SpeechOutAgent, SpeechStateAgent, SpeechTextGetterAgent, StartAgent, SuperSpyAgent, TextGetterAgent, TextOutputAgent, TranslatorAgent, WindowsWebBrowserAgent

public class ManagedAgent
extends GoodAgent
implements Managed

The resource manager allows agents to invisibly used our resource system (whatever it may be) without fuss. When an agent does a relies on call it gets back an EHA as normal, but the resource part of the agent keeps that object in a hashtable and replaced the agent stub with the new agents stub if the resources are swapped on the agent When an agent extends the resource agent, it can both use resources and provide them. In fact you must extend resource agent if you want to do either. Hopefully extending the research agent, and doing nothing else, but will suffice in most cases (with the possible addition of describing the agent in whatever language necessary). WARNING: reliesOn( occ ) and reliesOn( occ, des ) are now resource requests. However reliesOn( AgentID ) is NOT.

See Also:
Serialized Form

Inner classes inherited from class metaglue.AgentAgent
AgentAgent.Attribute
 
Field Summary
protected  ResourceManager rm
          This is the ResourceManager which gives us all our resources.
protected  Society society
          Our society, to ask questions of and stuff.
 
Fields inherited from class agentland.util.GoodAgent
alert, notifier
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Fields inherited from interface metaglue.Agent
ALIVE, DIED, NO_METAGLUE, NOT_RUNNING, STARTING
 
Constructor Summary
ManagedAgent()
          Our constructor.
 
Method Summary
 boolean connect(AgentID start, AgentID end)
          Connect two agents together (in whatever sense makes sense.)
protected  void getAlert()
           
 Need getNeed(String requestName)
          This is a very simple implementation of getNeed -- it returns medium need if we have the request and 0 if we do not have it.
protected  boolean isAvailable(Agent a)
          This method returns true if the agent stub given as a parameter can still be used (i.e.
protected  boolean isAvailable(String resBunchName)
          Checks if all resources in the resource bunch with the given name are available.
 Agent reliesOn(String occ)
          This most general reliesOn should grab resource.
 Agent reliesOn(String occ, Object des)
          This most general reliesOn should grab resource.
 void replace(Resource old_r, Resource new_r)
          A callback from the resource manager saying the resource has been replaced by a new resource in a given request.
 void replace(String requestName, String resourceName, Resource new_r)
          Does yanking given the name of a resource and the request bunch that got the resource
 ResourceBunch request(Request req, Context con)
          The main request type.
 ResourceBunch request(String req)
          This request assumes no context.
 ResourceBunch request(String request, Context con)
          A general request.
 Agent requestAgent(String occupation)
          The real request agent.
 Agent requestAgent(String occupation, String des)
          Request any agent implementing a given Interface.
 Vector resources(Filter f)
          Get all resources used that match the given filter.
 Vector resourcesByAgentID(Filter f)
          Given a filter, look through the agentIDs of the resources for matches, instead of looking at the Resource objects themselves.
 void setNeed(String requestName, float need)
          Allows the agent to set its need for any resource it uses (or plans to use)
 void tiedTo(ResourceBunch rb)
          This method is a shortcut for tiedTo -- it takes in a resource bunch as the argument.
protected  void yank(Resource r)
          yank an individual resource.
 void yank(ResourceBunch rb)
          A callback from the resource manager (or other) saying resource is dead.
 void yank(String requestName)
          Does yanking given the name of the initial request that got us a resource bunch
 
Methods inherited from class agentland.util.GoodAgent
addSpy, addSpy, alert, alertString, beep, error, getHistory, getHistoryElement, getPersistentMap, log, notify, removeSpy, removeSpy, resetHistory, safeRely, safeRely, safeRely, setNiceLogName, tell
 
Methods inherited from class metaglue.AgentAgent
addMonitor, alive, buildEHAFor, defrost, defrostAll, defrostBoolean, defrostInt, defrostString, fixAttribute, fixAttribute, freeze, freeze, freeze, freezeAll, freezeVar, getAgentID, getAttribute, getCatalog, getCatalogID, getDesignation, getFrozenVariables, getLogLevel, getMetaglueAgent, getMetaglueAgentID, getOccupation, getOldLogs, getProperties, getProxyHandlerClass, getSociety, installAPH, log, log, lookupClass, reliesOn, reliesOnSynch, removeAPHFromCatalog, removeFrozen, setFreezeName, setLogLevel, setLogName, shutdown, startAgent, startAgentOn, startAgentOn, startup, status, tiedTo, tiedTo, tiedTo, tiedTo, tieToDesignation, toString, whereAreYou
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface agentland.util.Good
getHistory, getHistoryElement, resetHistory
 
Methods inherited from interface metaglue.Agent
addMonitor, alive, getAgentID, getMetaglueAgentID, getOldLogs, shutdown, startup, whereAreYou
 
Methods inherited from interface agentland.util.Spy
tell
 

Field Detail

rm

protected ResourceManager rm
This is the ResourceManager which gives us all our resources.

society

protected Society society
Our society, to ask questions of and stuff.
Constructor Detail

ManagedAgent

public ManagedAgent()
             throws RemoteException
Our constructor.
Method Detail

isAvailable

protected boolean isAvailable(String resBunchName)
Checks if all resources in the resource bunch with the given name are available. Note that the name of the resource bunch is the name of the REQUEST that obtained this bunch.

isAvailable

protected boolean isAvailable(Agent a)
This method returns true if the agent stub given as a parameter can still be used (i.e. has not been yanked); managed agents should use this method to find out if they hadn't lost a resource before attempting to use it

request

public ResourceBunch request(String req)
This request assumes no context.

request

public ResourceBunch request(String request,
                             Context con)
A general request. Go get the resource.

request

public ResourceBunch request(Request req,
                             Context con)
The main request type. Takes a request and a context, and grabs a bunch. Does all the pulling apart and stashing bits internally (changes bunch so it points to stubs, not agentIDs.

requestAgent

public Agent requestAgent(String occupation,
                          String des)
Request any agent implementing a given Interface. This request takes an occupation (i.e. an Interface for some kind of agent) as a Resource, and goes and finds it. NOTE: It also takes des, which seems wrong to me and I don't like it. However, since this is the name translating thing, it must be so. Perhaps? Hmm....... -luke Returns null if request for resource fails.

requestAgent

public Agent requestAgent(String occupation)
The real request agent. Does not take desig, which seems better.

yank

public void yank(String requestName)
          throws RemoteException
Does yanking given the name of the initial request that got us a resource bunch
Specified by:
yank in interface Managed

yank

public void yank(ResourceBunch rb)
A callback from the resource manager (or other) saying resource is dead.
Specified by:
yank in interface Managed

yank

protected void yank(Resource r)
yank an individual resource.

replace

public void replace(String requestName,
                    String resourceName,
                    Resource new_r)
             throws RemoteException
Does yanking given the name of a resource and the request bunch that got the resource
Specified by:
replace in interface Managed

replace

public void replace(Resource old_r,
                    Resource new_r)
A callback from the resource manager saying the resource has been replaced by a new resource in a given request.
Specified by:
replace in interface Managed

connect

public boolean connect(AgentID start,
                       AgentID end)
                throws RemoteException
Connect two agents together (in whatever sense makes sense.)

reliesOn

public Agent reliesOn(String occ)
This most general reliesOn should grab resource.
Overrides:
reliesOn in class AgentAgent
Following copied from class: metaglue.AgentAgent
Parameters:
agentID - agentID of agent to start
Returns:
stub to agent
Throws:
SpreadError - some reliance could not spread
AgentNotDefinedError - some part of the agent was not completely defined
NativityError - an error occurred during the construction of agent.
InvalidArgumentException - (runtime) agentID is null

reliesOn

public Agent reliesOn(String occ,
                      Object des)
This most general reliesOn should grab resource.
Overrides:
reliesOn in class AgentAgent
Following copied from class: metaglue.AgentAgent
See Also:
AgentAgent.reliesOn(String)

tiedTo

public void tiedTo(ResourceBunch rb)
            throws RemoteException
This method is a shortcut for tiedTo -- it takes in a resource bunch as the argument. It asks the resource bunch what it should be tied to and if it gets an AgentID, it call appropriate tiedTo in AgentAgent; if it gets back a name of a host, it uses the other tiedTo.

getAlert

protected void getAlert()
Overrides:
getAlert in class GoodAgent

setNeed

public void setNeed(String requestName,
                    float need)
             throws RemoteException
Allows the agent to set its need for any resource it uses (or plans to use)

getNeed

public Need getNeed(String requestName)
             throws RemoteException
This is a very simple implementation of getNeed -- it returns medium need if we have the request and 0 if we do not have it. Other agents can override it to dynamically calculate the need in case it changes frequently.
Specified by:
getNeed in interface Managed
Parameters:
requestName - The name of the request -- for simple agent this will be the occupation requested

resources

public Vector resources(Filter f)
Get all resources used that match the given filter. The filter should filter on Resource objects. null filter means get all resources used.
Specified by:
resources in interface Managed
Returns:
Vector of Resources (containing AgentIDs), or empty vector if none. Never returns null.

resourcesByAgentID

public Vector resourcesByAgentID(Filter f)
Given a filter, look through the agentIDs of the resources for matches, instead of looking at the Resource objects themselves. Currently not used. Possibly useful someday?