|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.SwingWorker<java.lang.String,java.lang.String>
com.avian.birds.basebirds.AbstractBasicBird
com.avian.birds.basebirds.StdBird
public class StdBird
Concrete implementation of the AbstractBasicBird. The StdBird eats (gets) and stores (puts) every food packet (tuple) in a TupleTree (tuple space) so it is very Linda-like. The details of retrieving a food packet are contained in the eatFood method. The food packet is processed in the digest method. The food packet is put back into the TupleTree using the storeFood method. After storing the food, the bird needs a nap. This same cycle repeats (eating, digesting, storing, and napping) in the run method until it is told to stopNow, either because it's lifeTime has been exceeded or it has exceeded the length of time that it can live without eating, at which time it Returns to Egg (death being so ugly and final). One can also use the setStopNow method to terminate when desired the next time the run method gets to the statement where it test to see if it should continue running.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.SwingWorker |
---|
javax.swing.SwingWorker.StateValue |
Field Summary | |
---|---|
protected StdFood |
foodFromTree
The StdBird always eats some kind of Manna from a TupleTree. |
protected java.lang.String |
healthStatus
Initialized by the xxStartButton or xxContinueButton methods in the Aviary. |
protected javax.swing.JButton |
jbRefStart
Initialized by the xxStartButton or xxContinueButton methods in the Aviary. |
protected javax.swing.JLabel |
jlRefLastAte
Initialized by the xxStartButton or xxContinueButton methods in the Aviary. |
protected javax.swing.JTextArea |
jtaRefHistory
Initialized by the xxStartButton or xxContinueButton methods in the Aviary. |
protected javax.swing.JTextField |
jtfRefHealth
Initialized by the xxStartButton or xxContinueButton methods in the Aviary. |
protected MilliTimeString |
mts
Utility object that knows how to convert a millisecond time (as a long) into a String object. |
protected BasicTupleTree |
myTupleTree
This is a Google Collections ArrayListMultimap object that saves and retrieves key-value pairs, even when there are duplicate keys. |
protected NanoTimeString |
nts
Utility object that knows how to convert a nanosecond time (as a long) into a String object. |
java.lang.String |
sampleXmv
Externally managed variables (Xmv) work like command line parameters but for the GUI env. |
protected java.lang.String |
startButtonText
Initialized by the xxStartButton or xxContinueButton methods in the Aviary. |
Fields inherited from class com.avian.birds.basebirds.AbstractBasicBird |
---|
bhf, bif, birdDesc, birdHistory, birdName, bof, eatsFood, hatchTime, historyFileName, inputFileName, lastAte, levelOfInfo, lifeTime, napLength, outputFileName, stamina, stopNow, storesFood |
Constructor Summary | |
---|---|
StdBird()
Constructor of StdBirds, using the default constructor of AbstractBasicBird It's internal tree isn't set to point to the BasicTupleTree so that must be done separately |
|
StdBird(BasicTupleTree elm)
Constructor of StdBirds, using the default constructor of AbstractBasicBird and then setting it's internal tree to the BasicTupleTree that was created when the GUI was initialized. |
Method Summary | |
---|---|
protected void |
checkAge()
Verifies the age of a Basic Bird and if it has exceeded its lifeTime, sets stopNow to true so that the run method will terminate. |
void |
digest()
Provides the processing functionality for this StdBird. |
protected void |
done()
Performs various clean up activities when this bird has gotten old and RTE's or has received the stopNow(true) message. |
void |
eatFood()
Every Bird must eat food to stay alive and this method provides the instructions that the Basic Bird will follow to eat. |
void |
setHealthRef(javax.swing.JTextField jtf)
Text field that holds a human-readable message describing the current status of this bird. |
void |
setHealthStatus(java.lang.String healthDesc)
Allows the different objects and methods to update the healthDesc string that is displayed whenever the HealthRef field is updated. |
void |
setHistoryAreaRef(javax.swing.JTextArea jta)
The on-screen display of the personal history of this bird. |
void |
setJlRefLastAte(javax.swing.JLabel refLastAte)
The on-screen field that displays the last time that this bird ate. |
void |
setStartButtonRef(javax.swing.JButton jb)
The Start button that was pressed by the user that created this bird. |
void |
setStartButtonText(java.lang.String buttonText)
The text String that was on the Start button when the user pressed the button. |
void |
setTupleTree(BasicTupleTree tt)
Sets the local TupleTree reference so this bird knows where to put objects and where to get objects. |
void |
storeFood()
Puts the digested food out for other Birds to eat. |
Methods inherited from class com.avian.birds.basebirds.AbstractBasicBird |
---|
addToBirdHistory, doInBackground, getAuxFood, getBirdDescription, getBirdHistory, getBirdName, getEatsFood, getHatchTime, getHistoryFileName, getInputFileName, getLastAte, getLevelOfInfo, getLifeTime, getNameOfFoodToStore, getNapLength, getOutputFileName, getStamina, isStopNow, setBhf, setBif, setBirdDesc, setBirdHistory, setBirdName, setBof, setEatsFood, setHatchTime, setHistoryFileName, setInputFileName, setLevelOfInfo, setLevelOfInfo, setLifeTime, setNapLength, setOutputFileName, setStamina, setStopNow, setStoresFood |
Methods inherited from class javax.swing.SwingWorker |
---|
addPropertyChangeListener, cancel, execute, firePropertyChange, get, get, getProgress, getPropertyChangeSupport, getState, isCancelled, isDone, process, publish, removePropertyChangeListener, run, setProgress |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected BasicTupleTree myTupleTree
protected StdFood foodFromTree
protected javax.swing.JTextArea jtaRefHistory
protected javax.swing.JButton jbRefStart
protected java.lang.String startButtonText
protected javax.swing.JLabel jlRefLastAte
protected javax.swing.JTextField jtfRefHealth
protected java.lang.String healthStatus
protected MilliTimeString mts
protected NanoTimeString nts
public java.lang.String sampleXmv
Constructor Detail |
---|
public StdBird()
public StdBird(BasicTupleTree elm)
elm
- BasicTupleTree object that manages the key-value pairs Method Detail |
---|
public void setHistoryAreaRef(javax.swing.JTextArea jta)
jta
- JTextArea object that displays on-screen the history of the events that this
bird encountered.public void setStartButtonRef(javax.swing.JButton jb)
jb
- JButton object that was pressed by the user that started this bird running.public void setStartButtonText(java.lang.String buttonText)
buttonText
- String that was on the Start button when the user started
the bird running.public void setHealthRef(javax.swing.JTextField jtf)
jtf
- JTextField object that holds the human-readable message that describe
the status of this bird (Egg, Running, etc)public void setHealthStatus(java.lang.String healthDesc)
healthDesc
- String that represents the current status of this bird.public void setJlRefLastAte(javax.swing.JLabel refLastAte)
refLastAte
- JLable that displays the last time the bird ate - this label
is only updated when the done method is called.public void setTupleTree(BasicTupleTree tt)
tt
- BasicTupleTree reference that allows this bird to get and put
objects in the TupleTreepublic void eatFood()
In the Linda world of tuples and tuplespaces, the eatFood method is a get operation, where the Basic Bird retrieves a work packet. The name of the food defined for this Basic Bird is the key value that is used to retrieve its tuple. Any tuple which matches the eat food name may be retrieved, with no order expected or implied. If there is some special need for a type or a sequence, then it probably needs to be a different kind of Basic Bird that eats a different food name.
Typically, eating involves getting food from a TupleTree. Right now, the TupleTree is implemented using Google Collections ArrayListMultimap because it allows multiple objects with the same key to be stored and retrieved, but there is no requirement that this be used. The eatFood method is defined as abstract in AbstractBasic Bird so that users can define whatever method they desire to retrieve the next packet to work on, such as SQL queries or X-path look ups.
public void storeFood()
The name for the digested food comes from the storeFood variable,
which is the "key" that will be used to store the work packet (object). This
object is the "value" in a
In the real world, one bird will store (cache) some food for later eating (such as when a woodpecker puts a nut or a bug in a hole in the tree). Sometimes, however, a different bird will actually eat it.
In the Linda world, storeFood is the equivalent of the put operation. The StdBird is implemented using the TupleTree which is based on the Google Collections ArrayListMultimap because it allows multiple values to be stored using the same key, but there is no requirement that users do the same - they can implement any way of saving the info that they desire in the TupleTree of their own device.
public void digest()
Every different kind of Bird can be expected to digest differently. That is the whole reason for making different Birds and having them eat different foods, to handle different situations outside of code logic. For example, consider a situation where you have a special condition that involves a lot of convoluted logic to correctly handle that special condition. Instead of coding it, store it as a different kind of food and then add a Bird that will eat just that special kind of food. Set that Bird's stamina high because it won't eat often, but when it does it, it handles the special condition without a lot of complicated logic or deeply nested if statements.
protected void checkAge()
protected void done()
done
in class javax.swing.SwingWorker<java.lang.String,java.lang.String>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |