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
Direct Known Subclasses:
BeeperAgent, DeviceAgent, ExecAgent, MessAgent, ProjectionScreenMetaAgent, ProjectionScreenSpeechAgent, ResourceRetrieverAgent

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
 
Fields inherited from interface metaglue.Agent
ALIVE, DIED, NO_METAGLUE, NOT_RUNNING, STARTING
 
Constructor Summary
ManagedAgent()
           
 
Method Summary
 boolean connect(AgentID start, AgentID end)
          Connect two agents together (in whatever sense makes sense.)
protected  void getAlert()
           
 float 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.
 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.
 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 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, defrost, defrostAll, defrostBoolean, defrostInt, defrostString, fixAttribute, fixAttribute, freeze, freeze, freeze, freezeAll, freezeVar, getAgentID, getAttribute, getCatalog, getCatalogID, getDesignation, getFrozenVariables, getLogLevel, getMetaglueAgent, getMetaglueAgentID, getOccupation, getProperties, getSociety, log, log, obtainMetaglueAgent, obtainMetaglueAgent, obtainMetaglueAgentByName, reliesOn, reliesOnSynch, removeFrozen, replaceExceptionHandler, setFreezeName, setLogLevel, setLogName, shutdown, startAgent, startAgentOn, startAgentOn, startup, status, tiedTo, tiedTo, tiedTo, tiedTo, tieToDesignation, 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, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

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
Method Detail

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

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

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
Tags copied from class: 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
Tags copied from class: AgentAgent
See Also:
AgentAgent.reliesOn(String)

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 float 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 sthis 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?