agentland.naming
Class TranslatorAgent

java.lang.Object
  |
  +--java.rmi.server.RemoteObject
        |
        +--java.rmi.server.RemoteServer
              |
              +--java.rmi.server.UnicastRemoteObject
                    |
                    +--metaglue.AgentAgent
                          |
                          +--agentland.util.GoodAgent
                                |
                                +--agentland.resource.ManagedAgent
                                      |
                                      +--agentland.naming.TranslatorAgent
All Implemented Interfaces:
Agent, Good, Managed, MetagluePrimitives, Remote, Serializable, Spy, Translator

public class TranslatorAgent
extends ManagedAgent
implements Translator

Basic Implementation of a Translator

See Also:
ManagedAgent, Translator, Serialized Form

Inner classes inherited from class metaglue.AgentAgent
AgentAgent.Attribute
 
Field Summary
protected  TranslatorEngine engine
           
protected  PersistentMap names
           
 
Fields inherited from class agentland.resource.ManagedAgent
rm, society
 
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
TranslatorAgent()
           
 
Method Summary
 boolean addChild(AgentID child, boolean permanent)
          Adds a child resolver -- the child resolvers will be queried if the name could not be resolved by this agent.
 boolean addName(Serializable thing, Serializable name)
          Allows you to add a name to a thing
 boolean addNames(Serializable thing, Collection names)
          A convenience method -- allows you to add several names at once
 boolean forgetAll()
          Tells the resolver to forget all of the name-thing bindings
 Collection getAllNames()
          Returns all names of all things registered with this agent
 Collection getAllNames(Serializable thing)
          Finds all names for the thing.
 Collection getAllNamesForThings(Collection things)
          Get all the names for all the things passed in as the argument
 Collection getAllThings()
          Returns all things registered with this agent
 Serializable getUniqueName(Serializable thing)
          Get the unique name for the thing in the scope of this agent (all other things registered with this agent will be considered.
 Serializable getUniqueName(Serializable thing, Collection context)
          Find a unique name that distinguishes thing from stuff passed in the collection
 boolean removeChild(AgentID child)
          Removes the child (if it was a permanent child, the removal will be permanent)
 boolean removeName(Serializable thing, Serializable name)
          Remove a name from the list of names for the thing
 boolean removeThing(Serializable thing)
          Remove all names for the thing
 Collection resolveName(Serializable name)
          Returns all things associated with the name
 
Methods inherited from class agentland.resource.ManagedAgent
connect, getAlert, getNeed, isAvailable, isAvailable, reliesOn, reliesOn, replace, replace, request, request, request, requestAgent, requestAgent, resources, resourcesByAgentID, setNeed, tiedTo, yank, yank, yank
 
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.resource.Managed
getNeed, replace, replace, resources, yank, yank
 
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

names

protected PersistentMap names

engine

protected TranslatorEngine engine
Constructor Detail

TranslatorAgent

public TranslatorAgent()
                throws RemoteException
Method Detail

addName

public boolean addName(Serializable thing,
                       Serializable name)
                throws RemoteException
Allows you to add a name to a thing
Specified by:
addName in interface Translator
Returns:
true by default, false if something went terribly wrong

addNames

public boolean addNames(Serializable thing,
                        Collection names)
                 throws RemoteException
A convenience method -- allows you to add several names at once
Specified by:
addNames in interface Translator
Returns:
true if things went well, false if anything went wrong

removeName

public boolean removeName(Serializable thing,
                          Serializable name)
                   throws RemoteException
Remove a name from the list of names for the thing
Specified by:
removeName in interface Translator
Returns:
true if the name was removed, false if the name was not there or some other problem occured

getUniqueName

public Serializable getUniqueName(Serializable thing)
                           throws RemoteException
Get the unique name for the thing in the scope of this agent (all other things registered with this agent will be considered.
Specified by:
getUniqueName in interface Translator
Returns:
the unique name or null if no unique name was found for the thing

getUniqueName

public Serializable getUniqueName(Serializable thing,
                                  Collection context)
                           throws RemoteException
Find a unique name that distinguishes thing from stuff passed in the collection
Specified by:
getUniqueName in interface Translator
Returns:
returns a unique name (there may be more than one) or null if none could be found

getAllNames

public Collection getAllNames(Serializable thing)
                       throws RemoteException
Finds all names for the thing.
Specified by:
getAllNames in interface Translator
Returns:
will return an Empty list if no names were found (never null)

getAllNamesForThings

public Collection getAllNamesForThings(Collection things)
                                throws RemoteException
Get all the names for all the things passed in as the argument
Specified by:
getAllNamesForThings in interface Translator
Returns:
will return an Empty list if no names were found (never null)

removeThing

public boolean removeThing(Serializable thing)
                    throws RemoteException
Remove all names for the thing
Specified by:
removeThing in interface Translator
Returns:
true of all went well, false if the thing was not found or other trouble happened

resolveName

public Collection resolveName(Serializable name)
                       throws RemoteException
Returns all things associated with the name
Specified by:
resolveName in interface Translator
Returns:
will return an Empty list if no names were found (never null)

addChild

public boolean addChild(AgentID child,
                        boolean permanent)
                 throws RemoteException
Adds a child resolver -- the child resolvers will be queried if the name could not be resolved by this agent. Exact specification of the behavior will come later.
Specified by:
addChild in interface Translator
Parameters:
child - the agent id of the child resovler
permanent - true if the association is to be made permanent (i.e. frozen); false if this is a one-time deal
Returns:
true if all went well, false if the child could not be found or is not a resolver

removeChild

public boolean removeChild(AgentID child)
                    throws RemoteException
Removes the child (if it was a permanent child, the removal will be permanent)
Specified by:
removeChild in interface Translator
Returns:
true if the child was found and removed, false otherwise

forgetAll

public boolean forgetAll()
                  throws RemoteException
Tells the resolver to forget all of the name-thing bindings
Specified by:
forgetAll in interface Translator
Returns:
true; false if there is trouble or the process is abandoned (I will probably pop up a window to ask for confirmation so user can change his/her mind)

getAllNames

public Collection getAllNames()
                       throws RemoteException
Returns all names of all things registered with this agent
Specified by:
getAllNames in interface Translator

getAllThings

public Collection getAllThings()
                        throws RemoteException
Returns all things registered with this agent
Specified by:
getAllThings in interface Translator