Save This Page
Home » openjdk-7 » net.hivecell » hive » agent » [javadoc | source]
net.hivecell.hive.agent
abstract public class: AgentImpl [javadoc | source]
java.lang.Object
   java.rmi.server.RemoteObject
      java.rmi.server.RemoteServer
         java.rmi.server.UnicastRemoteObject
            net.hivecell.hive.agent.AgentImpl

All Implemented Interfaces:
    Agent, Serializable, Describable, Remote

Direct Known Subclasses:
    EventSendingAgentImpl, CreditsAgentImpl, CameraDemoAgentImpl, GenericFilterAgentImpl, MovingAverageAgentImpl, BaseAWTGUIAgentImpl, StringSendingAgentImpl, AudioClipAgentImpl, AgentMessagingShadowAgentImpl, LocustToLocationTranslatingAgentImpl, BaseSwingGUIAgentImpl, MotionColorFilterAgentImpl, AutoMonitoringAgentImpl, PocketServerAgentImpl, CameraFinderAgentImpl, LocustShadowAgentImpl, ImageTakingDisplayingAgentImpl, LocationServiceRequestAgent, GenericResourceFinderAgentImpl, CellControlAgentImpl, AgentMonitoringAgentImpl, RandomDotAgentImpl, BaseGUIAgentImpl, CricketToLocationTranslatingAgentImpl, ClickAgentImpl, ThroughputTestingAgentImpl, CreditsControllingHuntingAgentImpl, IconicUIAgentImpl, EventTransceivingAgentImpl, CellListAgentImpl, EchoAgentImpl, ImageDisplayAgentImpl, RunningGraphAgentImpl, HTTPAccessTranslatingAgentImpl, MetronomeAgentImpl, AutoUIAgentImpl, SpokeCellEventAgentImpl, FileGrowthInfoAgentImpl, SpokeAgentImpl, WheresBradAgentImpl, EventTranslatingAgentImpl, EventReceivingAgentImpl, ContrastFilterAgentImpl, BaseUIAgentImpl, ImageSourceAgentImpl, CricketAgentImpl, EventNumberTranslatingAgentImpl, CreditsHuntingAgentImpl, HoneyIShrunkTheCDs, TreeUIAgentImpl, MusicUIAgentImpl, StringDisplayAgentImpl, CameraAgentImpl, WebImageAgentImpl, GenericSignalPassthroughAgentImpl, ChatGroupServerAgentImpl, FakeCameraAgentImpl, TwoWayConnectionAgentImpl, CricketShadowAgentImpl, MotionDetectorAgentImpl, FlashingDotAgentImpl, ExternalInterfaceAgentImpl, GrayscaleFilterAgentImpl, DJFinderAgentImpl, LatencyTestingAgentImpl, ChatAgentImpl, ThroughputCalculatingAgentImpl, ImageCreationAgentImpl, DJAgentImpl, SignalPassthrough

Base class for Hive agent implementations. An agent has a life cycle.
  1. Once in its lifetime, the agent is constructed by the no argument constructor.
  2. The agent arrives on a server; its doLocalSetup() method is called. This happens whenever it first comes to a server, whether created by Cell.createNewAgent(Class) or when it moves to the server.
  3. The agent's doBehavior() method is called. This method is the agent's main loop, where it's behavior is implemented. The agent is free to do what it wants, but should respect timeToStop. The agent sould never exit this method, a convienience method waitUntilDeath is provided for this purpose.
  4. When an agent is being killed, the notification onDying method is called. The onMoving is called for the notification for moving
  5. onLocalCleanup is called to ask the agent to free all its local resources. The reason for agent death can be discovered by looking at the value of stopCode if cleanup is dependant on the "type" of agent death
An agent might travel to another server, either by moving itself or being moved by someone authorized. The moveTo() method initiates the move: when the agent arrives at the remote server, arriveAt() and doBehaviour() will be called again. All agents have a notion of a list of "connections", which agents they talk to. It is up to the agent to define the semantics of what a connect means. Agents also have an icon that represents them: by default this icon is loaded from icons/AgentClassName.ppm. Agents contain something similar to "popup menus" called ActionCommands. These can be rendered by a UI if so wished, but this is also so things can issue a string comamnd to the agent and it will perform the command. this is just another way to ask the agent to perform an action
Field Summary
protected transient  Cell myCell    Pointer to the server I am currently on. 
protected transient  CellAddress myAddress    the address this agent is currently sitting at 
protected transient  ThreadGroup agentThreadGroup    Pointer to the thread group for this agent -- ell behaved agents, if they need to spawn separate threads, will make those threads members of this agents thread group. There is no way, unfortunately, for Hive to enforce this though 
protected  Description description    Pointer to my XML description. 
protected transient  boolean readyFlag    Just describing whether or not this agent is ready for operation or not 
protected transient  boolean timeToStop    Variable indicating this agent should die soon. This is set asynchronously, typically by the server. Agents should inspect this in their main loop. 
protected transient  int stopCode    Variable describing the reason why an agent was asked to stop 
public static final  int AGENTKILLED    the stop code which means the agent is being killed 
public static final  int AGENTMOVED    the stop code which means the agent is being moved 
protected  SerializableImage icon    The icon that represents this agent. Should be loaded at create time. 
protected  String iconName    the name of the icon file 
protected  Hashtable commands    Hashtable and list for the popup menu items or their non-graphical equivalents. 
protected  Vector commandList    Hashtable of CommandObjects 
Fields inherited from java.rmi.server.RemoteObject:
ref
Constructor:
 public AgentImpl() throws RemoteException 
    Basic constructor for agents. This only gets called once in an agent's lifetime, when it is first created. It is not called when the agent arrives at a new host.
    Also see:
    doLocalSetup Note - because of Java syntax rules, all subclasses must explicitly declare a constructor, even if all it does is call the superclass constructor.
Method from net.hivecell.hive.agent.AgentImpl Summary:
addActionCommand,   blockUntilReady,   configure,   connectTo,   diePlease,   disconnectFrom,   disconnectFromAll,   doBehavior,   doLocalCleanup,   doLocalSetup,   getActionCommands,   getAddress,   getCell,   getComponentManagerShadow,   getDescription,   getIcon,   getIconName,   getName,   getThreadGroup,   invokeActionCommand,   isReady,   isTimeToStop,   listAllIncomingConnections,   listAllOutgoingConnections,   loadIcon,   moveTo,   onDying,   onMoving,   setCell,   setDescription,   setIconName,   setIsReady,   setThreadGroup,   setTimeToStop,   waitUntilDeath
Methods from java.rmi.server.UnicastRemoteObject:
clone,   exportObject,   exportObject,   exportObject,   unexportObject
Methods from java.rmi.server.RemoteServer:
getClientHost,   getLog,   setLog
Methods from java.rmi.server.RemoteObject:
equals,   getRef,   hashCode,   toString,   toStub
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from net.hivecell.hive.agent.AgentImpl Detail:
 public  void addActionCommand(ActionCommand com) 
    Add a popup menu item or non-graphical equivalent to the agent's behavior.
 public  void blockUntilReady() 
    this method should block until the agent is ready -- it just sits in the wait method until it gets notified from the setIsReady method
 public  void configure(Object o,
    Description desc) 
    Override this function to let an agent configure itself from a Description. This method is called by Hive if the agent was created through The user's Global.CellDescription file. If you want to load a configuration by hand, see Global.getConfigAsXMLDocument().
 public boolean connectTo(Agent otherAgent) 
    Tell this agent to connect to some other agent. It is up to the agent to define the semantics of what this means. By default, AgentImpl just prints an error message and returns false.
 public  void diePlease() 
    Ask the agent to politely die -- by default, the agent just relays the call to the server and asks it tkill itself
 public  void disconnectFrom(Agent otherAgent) 
    Disconnects this agent from the specified other agent. It is up to the agent to define the semantics of what this means. By default, AgentImpl just prints an error message and returns false.
 public  void disconnectFromAll() 
    Disconnects this agent from all agents. It is up to the agent to define the semantics of what this means. By default, AgentImpl just prints an error message and returns false.
 abstract public  void doBehavior()
    Do the basic behavior for an agent, the agent's main loop. Override this to provide your particular agent's behavior. Note: the doBehavior loop should not exit. Please call waitUntilDeath() at the end of this method, this will prevent the Cell from believing this agent prematurely exited.
 public  void doLocalCleanup() 
    Command the agent to free its local resources here. It may or may not equal what happens when the agent is supposed to die -- but here would be the appropriate place to free File descriptors, and stop threads, but do not do anything related to the agent community -- do not notify them that this agent is about to die. When this method terminates, this agent should be ready to be killed
 public  void doLocalSetup() throws AgentInitializationException 
    Handle the setup when an agent arrives on a host -- it is appropriate to allocate system resources (file descriptors, etc) here and even to locate other agents that this agent needs to communicate with.
 public Vector getActionCommands() 
    Get the names of the ActionCommands this agent uses in the order in which they were entered.
 public CellAddress getAddress() 
    return the address that i'm at
 public RemoteCell getCell() 
    Return the cell I'm living on.
 public ComponentManagerShadow getComponentManagerShadow() throws ShadowNotFoundException 
    A convenience method to return the ComponentManagerShadow or throws an exception if one is not present.
 public Description getDescription() 
    Return the semantic description of this agent.
 public SerializableImage getIcon() 
    Return the SerializableImage object that is the agent's icon.
 public String getIconName() 
    Get the value of iconName.
 public String getName() 
    get a "name" for this agent -- if the description contains a nickname, then we should return that, else we return the short string of the name
 public ThreadGroup getThreadGroup() 
    Return the thread group that we are in
 public boolean invokeActionCommand(String com) 
    Invoke an action command by name. Currently, this will only be called in a baseUICanvas or its non-graphical equivalent.
 public boolean isReady() 
    this flag tells another object whether this agent is ready to do its stuff. the semantics of being ready are left up to the agent's author, however the only restriction is that the agent should -not- report that it is ready until the server calls setIsReady( true ) on this agent
 public boolean isTimeToStop() 
    Tell if the agent been told to stop.
 public Vector listAllIncomingConnections() 
    Return a vector of all the agents that are connected to me. It is up to the agent to define the semantics of what this means. By default, AgentImpl just prints an error message and returns false.
 public Vector listAllOutgoingConnections() 
    Return a vector of all that agents that i am connected to. It is up to the agent to define the semantics of what this means. By default, AgentImpl just prints an error message and returns false.
 protected  void loadIcon() 
    Load the icon for an agent off of disk. If the agent is class net.hivecell.hive.FooAgent then this looks for net.hivecell.hive/icons/FooAgent.ppm in the class path or Jar file. If that doesn't exist, then a default is substituted.
 public  void moveTo(CellAddress address) throws AgentDeliveryException 
    Move this agent to a new host. this basically moves the call up to the cell who handles it
 public  void onDying() 
    Used to notify the agent that it is about to be killed
 public  void onMoving() 
    Used to notify the agent that it is about to be moved
 public  void setCell(Cell c) 
    Set the cell flag on the agent. Normally user code should not call this - creation code in the cell should handle this
 public  void setDescription(Description desc) 
    Set the semantic deescription of this agent. we take the xml description, rip it apart and make sure the description of the xml description is the right thing
 public  void setIconName(String v) 
    Set the value of iconName.
 public final  void setIsReady(boolean flag) 
    This method tells the world that this agent is ready for operation. Deciding when an agent is ready is up to the agent's author, however the agent should -not- report that it is ready until it can be connected to, receive and send events, and perform any other special duties it needs to. setIsReady(true) is called automatically when the agent's doLocalSetup is done in Cell.java runAgentThread().
 public  void setThreadGroup(ThreadGroup tg) 
    Set the thread group of this agent. Normally user code should not call this -- the creation methods in the server will set this properly
 public final  void setTimeToStop(int flag) 
    Sets the time to stop flag
 protected  void waitUntilDeath() 
    Used at the end of the doBehavior method. Simply wait until the timeToStop flag has been set and the notify method has been called so we can exit properly, This should be done, otherwise the agnet will fall out of its doBehavior loop, and the Cell will "clean" the agnet up