metaglue
Class MetaglueAgent

java.lang.Object
  |
  +--java.rmi.server.RemoteObject
        |
        +--java.rmi.server.RemoteServer
              |
              +--java.rmi.server.UnicastRemoteObject
                    |
                    +--metaglue.AgentAgent
                          |
                          +--metaglue.MetaglueAgent
All Implemented Interfaces:
Agent, Metaglue, MetagluePrimitives, Remote, Serializable

public class MetaglueAgent
extends AgentAgent
implements Metaglue

A Metaglue Agent starts agents on the VM that it is running on. A Metaglue Agent belongs to a single society, but it can manipulate agents from any society on the VM. A Metaglue Agent uses a particular Catalog Agent to get its information about agents. Multiple Metaglue Agents can exist on a single VM. A Metaglue Agent is made unique in a particular society by its designation which includes: the host of its VM. and the Catalog Agent ID of the Catalog Agent that this Metaglue Agent gets information about agents from.

See Also:
Serialized Form

Inner classes inherited from class metaglue.AgentAgent
AgentAgent.Attribute
 
Field Summary
static String defaultSociety
          all the Metaglue Agents on the VM this list must be kept on the VM and not in a Catalog because the Metaglue Agents on the VM may all have different Catalog Agents that do not know about each other also this list provides an efficiency for having direct access to a Metaglue Agent from other agents this makes sense for Metaglue Agents because an agent's starting Metaglue Agent is always local.
static MetaglueAgent meto
          This is, when main() is called, the agent that main() produces.
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Fields inherited from interface metaglue.Agent
ALIVE, DIED, NO_METAGLUE, NOT_RUNNING, STARTING
 
Constructor Summary
MetaglueAgent(AgentID agentID)
          This is main constructor, since we normally grab catalog.
MetaglueAgent(AgentID agentID, Catalog cat)
          Creates a Metaglue Agent.
 
Method Summary
static void _addClassLoader(ChainingClassLoader cl)
           
static ChainingClassLoader _setupClassLoader()
           
static MetaglueAgent _startupMetaglue(boolean loadingCatalog, String society, InetAddress localHost, String catalog, CatalogAgent catalog_pointer, String cname_suggest)
           
static void clearStartLock()
          Clears the lock for this Metaglue Agent starting an agent Called by the process reading the start info
 byte[] fetchClassInfo(String name)
          This will fetch the data for the given class name.
protected  byte[] fetchSystemResourceData(String rsrc)
           
 Agent findAgent(AgentID agentID)
          Finds an agent with agent ID
 Agent findAgentBlockIfStarting(AgentID agentID)
           
 Agent findAgentBlocking(AgentID agentID)
          Find an agent, wait until agent shows up.
 Agent findAgentBlocking(AgentID agentID, boolean retry_if_not_found)
           
protected  Metaglue findOtherMetaglue(String soc)
          Find a metaglue agent othen than self (but of proper society) that accept agents.
 boolean getAcceptAgents()
          Returns true if this MVM will allow new agents to start there.
 Catalog getCatalog()
          Gets the Catalog that this Metaglue Agent uses
 CatalogID getCatalogID()
           
 ManagedConnection getDatabaseConnection()
          Gets the current db connection.
static MetaglueAgent getMetaglueAgent(AgentID agentID)
          Deprecated. Use getVMMetaglueAgent() with no arguments.
static StartInfo getStartInfo()
          Gets the start info for a starting agent
protected  void getStartLock()
          Sets the lock for this Metaglue Agent starting an agent It should be cleared by the process reading the start info
static MetaglueAgent getVMMetaglueAgent()
          Gets a non-remote copy of the Metaglue Agent on the VM
protected  boolean isForwardingClassFetcher()
           
static Agent loadAgent(String argString)
           
static void loadAgents(String[] args)
          Load the agents listed in the argument list.
static void main(String[] args)
          Establishes a Metalgue VM with Metaglue Agent to maintain it which in turn starts any listed agents.
 boolean pingMVM(String society, String host)
          Is any VM of given society and host alive?
 void setAcceptAgents(boolean v)
          Allows you to decide if more agents can be accepted at this MVM
 void setDatabase(boolean local_db, String dbname)
          Sets the database connection parameters.
static String[] setup(String[] args)
           
static String[] setup(String[] args, boolean acceptAgents)
           
 void shutdownAgent(AgentID agentID)
          Shuts down the agent by removing it from the Catalog
 void startAgent(AgentID agentID, Object[] parameters)
          Starts an agent on the VM maintained by this Metaglue Agent
static void startLocalLogManager(String society, InetAddress localHost)
           
static void startThreadWatcher()
           
 
Methods inherited from class metaglue.AgentAgent
addMonitor, alive, buildEHAFor, defrost, defrostAll, defrostBoolean, defrostInt, defrostString, fixAttribute, fixAttribute, freeze, freeze, freeze, freezeAll, freezeVar, getAgentID, getAttribute, getDesignation, getFrozenVariables, getLogLevel, getMetaglueAgent, getMetaglueAgentID, getOccupation, getOldLogs, getProperties, getProxyHandlerClass, getSociety, installAPH, log, log, log, lookupClass, reliesOn, reliesOn, 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 metaglue.Agent
addMonitor, alive, getAgentID, getMetaglueAgentID, getOldLogs, shutdown, startup, whereAreYou
 

Field Detail

meto

public static MetaglueAgent meto
This is, when main() is called, the agent that main() produces. This allows for writing wrapper startup programs that do things like take arguments in a different way or something.

defaultSociety

public static String defaultSociety
all the Metaglue Agents on the VM this list must be kept on the VM and not in a Catalog because the Metaglue Agents on the VM may all have different Catalog Agents that do not know about each other also this list provides an efficiency for having direct access to a Metaglue Agent from other agents this makes sense for Metaglue Agents because an agent's starting Metaglue Agent is always local.
Constructor Detail

MetaglueAgent

public MetaglueAgent(AgentID agentID,
                     Catalog cat)
              throws RemoteException,
                     AgentAlreadyStartedException,
                     FindAgentException,
                     MissingCatalogException
Creates a Metaglue Agent. There may be multiple Metaglue Agents on a single VM. For bootstrapping purposes, Metaglue Agents must be given their Agent IDs. Ensures that even if such a Metaglue Agent already exists on the VM, that the existing Metaglue Agent is registered with the Catalog Agent
Parameters:
agentID - agent ID of this Metaglue Agent
Throws:
AgentAlreadyStartedException - living Metaglue agent already exists on this VM or agent with same agent ID appears in Catalog
FindAgentException - problem finding Catalog Agent (entry found but not actually Catalog Agent, named host for Catalog Agent missing, remote problems connecting with Catalog Agent)
MissingCatalogException - Catalog Agent found but inacccessible
MetaglueSystemError - the URL created to find the Catalog Agent is bad
NullPointerException - (runtime) agentID is null
IllegalArgumentException - (runtime) agentID does not have designation of type MetaglueAgentID

MetaglueAgent

public MetaglueAgent(AgentID agentID)
              throws RemoteException,
                     AgentAlreadyStartedException,
                     FindAgentException,
                     MissingCatalogException
This is main constructor, since we normally grab catalog.
Method Detail

startThreadWatcher

public static void startThreadWatcher()

getMetaglueAgent

public static MetaglueAgent getMetaglueAgent(AgentID agentID)
Deprecated. Use getVMMetaglueAgent() with no arguments.


getVMMetaglueAgent

public static MetaglueAgent getVMMetaglueAgent()
Gets a non-remote copy of the Metaglue Agent on the VM
Returns:
the Metaglue Agent on the local VM.

getCatalogID

public CatalogID getCatalogID()
                       throws RemoteException
Overrides:
getCatalogID in class AgentAgent

getCatalog

public Catalog getCatalog()
Gets the Catalog that this Metaglue Agent uses
Overrides:
getCatalog in class AgentAgent
Returns:
Catalog that this Metaglue Agent uses

findAgent

public Agent findAgent(AgentID agentID)
                throws AgentNotFoundException,
                       AgentStartingException,
                       FindAgentException
Finds an agent with agent ID
Parameters:
agentID - agent ID of agent to find
Returns:
agent stub for agent with agent ID
Throws:
AgentNotFoundException - Agent with agent ID not found in Catalog
FindAgentException - problem finding Agent (remote problems finding Agent in Catalog)

findAgentBlockIfStarting

public Agent findAgentBlockIfStarting(AgentID agentID)
                               throws AgentNotFoundException,
                                      FindAgentException

findAgentBlocking

public Agent findAgentBlocking(AgentID agentID)
                        throws FindAgentException
Find an agent, wait until agent shows up. Never give up, never surrender.

findAgentBlocking

public Agent findAgentBlocking(AgentID agentID,
                               boolean retry_if_not_found)
                        throws FindAgentException,
                               AgentNotFoundException

pingMVM

public boolean pingMVM(String society,
                       String host)
Is any VM of given society and host alive?

startAgent

public void startAgent(AgentID agentID,
                       Object[] parameters)
                throws AgentNotDefinedException,
                       NativityException,
                       AgentAlreadyStartedException,
                       SpreadException,
                       StartAgentException,
                       RemoteException
Starts an agent on the VM maintained by this Metaglue Agent
Specified by:
startAgent in interface Metaglue
Parameters:
agentID - agent ID of agent to start
parameters - list of arguments to constructor of agent
Throws:
AgentNotDefinedException - no such agent with required constructor or its stub/skel files has not been created
StartAgentException - null agentID or remote problems talking to Catalog
NativityException - problem instantiating agent
AgentAlreadyStartedException - a living agent with agentID found in Catalog
SpreadException - agent could not spread

clearStartLock

public static void clearStartLock()
Clears the lock for this Metaglue Agent starting an agent Called by the process reading the start info

getStartInfo

public static StartInfo getStartInfo()
Gets the start info for a starting agent
Returns:
current start info

shutdownAgent

public void shutdownAgent(AgentID agentID)
                   throws RemoteException
Shuts down the agent by removing it from the Catalog
Specified by:
shutdownAgent in interface Metaglue
Parameters:
agentID - Agent ID of the agent to shut down

setDatabase

public void setDatabase(boolean local_db,
                        String dbname)
Sets the database connection parameters. This also creates the ManagedConnection, although MetaglueAgent doesn't currently use it.
Parameters:
local_db - Specifies whether to use a local database
dbname - Specifies a different local database name, if given. Uses the default name `metaglue' if null.

getDatabaseConnection

public ManagedConnection getDatabaseConnection()
Gets the current db connection. If the connection was closed, it reopens it.

_startupMetaglue

public static MetaglueAgent _startupMetaglue(boolean loadingCatalog,
                                             String society,
                                             InetAddress localHost,
                                             String catalog,
                                             CatalogAgent catalog_pointer,
                                             String cname_suggest)

_setupClassLoader

public static ChainingClassLoader _setupClassLoader()

_addClassLoader

public static void _addClassLoader(ChainingClassLoader cl)

startLocalLogManager

public static void startLocalLogManager(String society,
                                        InetAddress localHost)

loadAgents

public static void loadAgents(String[] args)
Load the agents listed in the argument list. NOTE that arg 0 and arg 1 are assumed to be catalog and society and thus skipped.

loadAgent

public static Agent loadAgent(String argString)

getAcceptAgents

public boolean getAcceptAgents()
Returns true if this MVM will allow new agents to start there. False otherwise
Specified by:
getAcceptAgents in interface Metaglue

setAcceptAgents

public void setAcceptAgents(boolean v)
Allows you to decide if more agents can be accepted at this MVM

setup

public static String[] setup(String[] args)

setup

public static String[] setup(String[] args,
                             boolean acceptAgents)
Parameters:
acceptAgents - does this metaglue agent start other agents?
Returns:
the args list with all used arguments removed.

fetchClassInfo

public byte[] fetchClassInfo(String name)
                      throws ClassNotFoundException
This will fetch the data for the given class name. It does so by checking for a resource with the given name, and then passing the data back to the caller if it finds it. It should be noted that Stephen P. is cool.
Specified by:
fetchClassInfo in interface Metaglue
Parameters:
name - the name of the class to fetch
Returns:
the byte array representing the data for the class

main

public static void main(String[] args)
Establishes a Metalgue VM with Metaglue Agent to maintain it which in turn starts any listed agents. A Catalog Agent is started if necessary.
Parameters:
args - {society catalog-host [agents...]}

findOtherMetaglue

protected Metaglue findOtherMetaglue(String soc)
                              throws RemoteException
Find a metaglue agent othen than self (but of proper society) that accept agents. Throw exception if there is none.

fetchSystemResourceData

protected byte[] fetchSystemResourceData(String rsrc)
                                  throws ClassNotFoundException

isForwardingClassFetcher

protected boolean isForwardingClassFetcher()

getStartLock

protected void getStartLock()
Sets the lock for this Metaglue Agent starting an agent It should be cleared by the process reading the start info