Changeset 45
- Timestamp:
- 05/14/08 18:06:26 (16 years ago)
- Location:
- trunk/src/org/expeditee/agents
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/agents/ComputeTree.java
r19 r45 10 10 public class ComputeTree extends DefaultAgent { 11 11 12 private Long startTime = 0L;13 14 private int frameCount = 0;15 16 private int itemCount = 0;17 18 @Override19 protected void finalise(Frame frame) {20 Long total = System.currentTimeMillis() - startTime;21 FrameGraphics.DisplayMessage("Time: " + total + "ms, frames: "22 + frameCount + ", items: " + itemCount);23 }24 25 12 @Override 26 13 protected Frame process(Frame frame) { 27 frameCount = 0;28 itemCount = 0;29 30 startTime = System.currentTimeMillis();31 32 14 if (computeFrame(frame) == null) { 33 15 message("Nothing to compute!"); … … 84 66 85 67 if (value != null) { 86 itemCount++;68 _itemCount++; 87 69 88 70 // the first time we find an item init result … … 97 79 if (result != null) 98 80 AttributeUtils.setSingleValue(frame.getTitle(), result.toString()); 99 frameCount++;81 _frameCount++; 100 82 FrameIO.ForceSaveFrame(frame); 101 83 -
trunk/src/org/expeditee/agents/CopyTree.java
r24 r45 103 103 104 104 } 105 105 _frameCount++; 106 106 fresh.path = _framePath; 107 107 FrameIO.ForceSaveFrame(fresh); … … 134 134 message("Tree successfully copied to " + _nameTo); 135 135 FrameUtils.DisplayFrame(_nameTo + _firstNumber); 136 137 super.finalise(frame); 136 138 } 137 139 -
trunk/src/org/expeditee/agents/DefaultAgent.java
r4 r45 1 1 package org.expeditee.agents; 2 2 3 import org.expeditee.gui.DisplayIO; 3 4 import org.expeditee.gui.Frame; 4 5 import org.expeditee.gui.FrameGraphics; 6 import org.expeditee.gui.TimeKeeper; 5 7 import org.expeditee.stats.SessionStats; 6 8 … … 11 13 * constructor called when an agent is run with a parametre. 12 14 * 13 * @author johnathon 15 * @author johnathon, mike 14 16 * 15 17 */ … … 24 26 protected boolean _stop = false; 25 27 28 protected int _frameCount = 0; 29 protected int _itemCount = 0; 30 31 protected TimeKeeper _timer; 32 33 /** 34 * Performs any post-processing actions, such as displaying a completion 35 * message to the user 36 * 37 * @param frame 38 * The starting Frame this Agent was executed on 39 */ 40 protected void finalise(Frame start) { 41 if (_frameCount == 0) 42 _frameCount++; 43 44 int framesPerSecond = (int) (_frameCount / (_timer.getElapsedMillis() / 1000.0)); 45 String stats = (_itemCount > 0 ? ("Items: " + _itemCount + ", ") : "") + 46 "Frames: " + _frameCount + ", Time: " 47 + _timer.getElapsedStringSeconds() + ", FPS: " + framesPerSecond; 48 String msg = this.getClass().getSimpleName() + " stats- "; 49 50 message(msg + stats); 51 } 52 26 53 /** 27 54 * Performs any pre-processing of the starting frame, which may include … … 31 58 */ 32 59 public boolean initialise(Frame init) { 60 message("Starting " + this.getClass().getSimpleName() + "..."); 61 _timer = new TimeKeeper(); 33 62 return true; 34 63 } … … 77 106 78 107 /** 79 * Performs any post-processing actions, such as displaying a completion80 * message to the user81 *82 * @param frame83 * The starting Frame this Agent was executed on84 */85 protected abstract void finalise(Frame frame);86 87 /**88 108 * Displays a message to the user 89 109 * -
trunk/src/org/expeditee/agents/DisplayTree.java
r43 r45 31 31 32 32 private Runtime _runtime = Runtime.getRuntime(); 33 33 34 34 private long _timeRemaining = 0; 35 36 private int _frameCount = 0;37 38 private TimeKeeper _timer;39 35 40 36 public DisplayTree(String delay) { … … 52 48 @Override 53 49 public boolean initialise(Frame start) { 54 _timer = new TimeKeeper();55 50 56 51 // push current frame on to back-stack 57 52 DisplayIO.addToBack(start); 58 53 59 // MIKE: Doesnt think the line below is needed 60 // update the delays (if necessary) 61 // delay(start); 62 63 return true; 54 return super.initialise(start); 55 } 56 57 @Override 58 protected void finalise(Frame start) { 59 // return the user to the Frame they started on 60 if (!_stop) { 61 DisplayIO.Back(); 62 } 63 super.finalise(start); 64 64 } 65 65 … … 67 67 protected void processFrame(Frame toProcess) { 68 68 long freeMemory = _runtime.freeMemory(); 69 if (freeMemory < GARBAGE_COLLECTION_THRESHOLD){69 if (freeMemory < GARBAGE_COLLECTION_THRESHOLD) { 70 70 _runtime.gc(); 71 71 FrameGraphics.DisplayMessage("Force Garbage Collection!"); 72 72 } 73 74 // FrameUtils.ResponseTimer.restart();75 73 74 // FrameUtils.ResponseTimer.restart(); 75 76 76 // ignore loops 77 77 if (toProcess != DisplayIO.getCurrentFrame()) 78 78 DisplayIO.setCurrentFrame(toProcess); 79 //FrameUtils.DisplayFrame(toProcess,false);79 // FrameUtils.DisplayFrame(toProcess,false); 80 80 // parse the frame for any pause settings 81 81 delay(toProcess); … … 122 122 } 123 123 124 @Override125 protected void finalise(Frame start) {126 if (_frameCount == 0)127 _frameCount++;128 129 long avg = _timer.getElapsedMillis() / _frameCount;130 String stats = "Frames: " + _frameCount + ", Time: "131 + _timer.getElapsedStringMillis() + ", Average: " + avg;132 String msg = "Tree successfully displayed. ";133 134 // return the user to the Frame they started on135 if (!_stop) {136 DisplayIO.Back();137 } else {138 msg = "Agent halted by user. ";139 }140 141 message(msg + stats);142 }143 144 124 /** 145 125 * Pauses the execution of this Agent for the given time period (in ms.) -
trunk/src/org/expeditee/agents/SwitchyardTree.java
r19 r45 11 11 public class SwitchyardTree extends DefaultAgent { 12 12 13 private Long startTime = 0L;14 15 private int frameCount = 0;16 17 private int itemCount = 0;18 19 @Override20 protected void finalise(Frame frame) {21 Long total = System.currentTimeMillis() - startTime;22 FrameGraphics.DisplayMessage("Time: " + total + "ms, frames: "23 + frameCount + ", items: " + itemCount);24 }25 26 13 @Override 27 14 protected Frame process(Frame frame) { 28 frameCount = 0; 29 itemCount = 0; 30 FrameGraphics.DisplayMessage("Running switchyard tree..."); 31 startTime = System.currentTimeMillis(); 15 //FrameGraphics.DisplayMessage("Running switchyard tree..."); 32 16 33 17 for (Text textItem : frame.getBodyTextItems(false)) { … … 54 38 frame.addItem(itemCopy); 55 39 } 40 _itemCount++; 56 41 } 57 42 } … … 59 44 } 60 45 } 61 46 _frameCount++; 62 47 return null; 63 48 } -
trunk/src/org/expeditee/agents/TreeProcessor.java
r4 r45 4 4 import java.util.Stack; 5 5 6 import org.expeditee.gui.DisplayIO; 6 7 import org.expeditee.gui.Frame; 7 8 import org.expeditee.gui.FrameIO; … … 17 18 // the list of frames currently being processed 18 19 private Stack<FrameCounter> _frames = new Stack<FrameCounter>(); 19 20 20 21 /** 21 22 * Processes the Frame by calling processItem() for each unlinked item … … 87 88 } 88 89 } 89 90 90 91 return null; 91 92 } -
trunk/src/org/expeditee/agents/WriteTree.java
r22 r45 6 6 7 7 import org.expeditee.actions.Actions; 8 import org.expeditee.gui.DisplayIO; 8 9 import org.expeditee.gui.Frame; 9 10 import org.expeditee.gui.FrameGraphics; … … 54 55 } 55 56 } 56 57 57 58 public WriteTree(String format, String outFile) { 58 59 _format = format; … … 147 148 } 148 149 149 return true; 150 } 151 152 @Override 153 protected void finalise(Frame start) { 150 return super.initialise(start); 154 151 } 155 152 … … 159 156 try { 160 157 161 if (_followLinks) 158 if (_followLinks) { 162 159 msg = _treeWriter.writeTree(frame); 163 else 160 _frameCount = _treeWriter.getFrameCount(); 161 } else { 164 162 msg = _frameWriter.writeFrame(frame); 165 163 _frameCount = 1; 164 } 166 165 } catch (IOException e) { 167 166 System.out.println("Caught");
Note:
See TracChangeset
for help on using the changeset viewer.