edu.sc.ants
Class Environment.RunningThing

java.lang.Object
  |
  +--edu.sc.ants.Environment.RunningThing

public class Environment.RunningThing
extends java.lang.Object

This class embodies one running thing (i.e. agent). Its methods are all synchronized because we do not want the environment to be reading and writing at the same time to one of the variables. That is, since each agent can call the Environment from its own thread it is possible that two agent threads could try to modify the one RunningThing at the same time. Specifically, one agent could try to send a message to a second one at the same time that the second one is trying to read it, or some third agent might be also be trying to send a message to the second agent.


Field Summary
(package private)  int bufferSize
           
(package private)  int headMessage
          the one that is returned.
(package private)  Observation location
          The real position of this agent
(package private)  Message[] messages
          The agent's mailbox of messages.
(package private)  int tailMessage
          add new message here
(package private)  Thing thing
          The thing we refer to
(package private)  java.lang.Thread thread
          The thread on which it runs
 
Constructor Summary
Environment.RunningThing(Thing t)
          Add a new thing.
 
Method Summary
 void addMessage(Message v)
          Appends the given message to the mailbox
 Observation getLocation()
          Get the value of location.
 Observation getLocationCopy()
          Return a copy of the current location.
 Message getMessage()
          Get the next message
 Thing getThing()
          Get the value of thing.
 java.lang.Thread getThread()
          Get the value of thread.
 void setLocation(Observation v)
          Set the value of location.
 void setThing(Thing v)
          Set the value of thing.
 void setThread(java.lang.Thread v)
          Set the value of thread.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

thing

Thing thing
The thing we refer to

thread

java.lang.Thread thread
The thread on which it runs

messages

Message[] messages
The agent's mailbox of messages. Perhaps these should expire after some time.

headMessage

int headMessage
the one that is returned. if head=tail there are no messages

tailMessage

int tailMessage
add new message here

bufferSize

int bufferSize

location

Observation location
The real position of this agent
Constructor Detail

Environment.RunningThing

public Environment.RunningThing(Thing t)
Add a new thing. Give it its current position and heading. Give it a thread and start it running.
Method Detail

getThing

public Thing getThing()
Get the value of thing.
Returns:
Value of thing.

setThing

public void setThing(Thing v)
Set the value of thing.
Parameters:
v - Value to assign to thing.

getThread

public java.lang.Thread getThread()
Get the value of thread.
Returns:
Value of thread.

setThread

public void setThread(java.lang.Thread v)
Set the value of thread.
Parameters:
v - Value to assign to thread.

getMessage

public Message getMessage()
Get the next message
Returns:
Value of message.

addMessage

public void addMessage(Message v)
Appends the given message to the mailbox
Parameters:
v - Value to assign to message.

getLocation

public Observation getLocation()
Get the value of location.
Returns:
Value of location.

getLocationCopy

public Observation getLocationCopy()
Return a copy of the current location.
Returns:
Value of location.

setLocation

public void setLocation(Observation v)
Set the value of location.
Parameters:
v - Value to assign to location.