Changeset 45


Ignore:
Timestamp:
05/14/08 18:06:26 (16 years ago)
Author:
ra33
Message:

Refactored to centralise code for messages and stats displayed for the running of agents.

Location:
trunk/src/org/expeditee/agents
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/agents/ComputeTree.java

    r19 r45  
    1010public class ComputeTree extends DefaultAgent {
    1111
    12         private Long startTime = 0L;
    13 
    14         private int frameCount = 0;
    15 
    16         private int itemCount = 0;
    17 
    18         @Override
    19         protected void finalise(Frame frame) {
    20                 Long total = System.currentTimeMillis() - startTime;
    21                 FrameGraphics.DisplayMessage("Time: " + total + "ms, frames: "
    22                                 + frameCount + ", items: " + itemCount);
    23         }
    24 
    2512        @Override
    2613        protected Frame process(Frame frame) {
    27                 frameCount = 0;
    28                 itemCount = 0;
    29 
    30                 startTime = System.currentTimeMillis();
    31 
    3214                if (computeFrame(frame) == null) {
    3315                        message("Nothing to compute!");
     
    8466
    8567                        if (value != null) {
    86                                 itemCount++;
     68                                _itemCount++;
    8769
    8870                                // the first time we find an item init result
     
    9779                if (result != null)
    9880                        AttributeUtils.setSingleValue(frame.getTitle(), result.toString());
    99                 frameCount++;
     81                _frameCount++;
    10082                FrameIO.ForceSaveFrame(frame);
    10183               
  • trunk/src/org/expeditee/agents/CopyTree.java

    r24 r45  
    103103
    104104                        }
    105 
     105                _frameCount++;
    106106                fresh.path = _framePath;
    107107                FrameIO.ForceSaveFrame(fresh);
     
    134134                message("Tree successfully copied to " + _nameTo);
    135135                FrameUtils.DisplayFrame(_nameTo + _firstNumber);
     136               
     137                super.finalise(frame);
    136138        }
    137139
  • trunk/src/org/expeditee/agents/DefaultAgent.java

    r4 r45  
    11package org.expeditee.agents;
    22
     3import org.expeditee.gui.DisplayIO;
    34import org.expeditee.gui.Frame;
    45import org.expeditee.gui.FrameGraphics;
     6import org.expeditee.gui.TimeKeeper;
    57import org.expeditee.stats.SessionStats;
    68
     
    1113 * constructor called when an agent is run with a parametre.
    1214 *
    13  * @author johnathon
     15 * @author johnathon, mike
    1416 *
    1517 */
     
    2426        protected boolean _stop = false;
    2527
     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       
    2653        /**
    2754         * Performs any pre-processing of the starting frame, which may include
     
    3158         */
    3259        public boolean initialise(Frame init) {
     60                message("Starting " + this.getClass().getSimpleName() + "...");
     61                _timer = new TimeKeeper();
    3362                return true;
    3463        }
     
    77106
    78107        /**
    79          * Performs any post-processing actions, such as displaying a completion
    80          * message to the user
    81          *
    82          * @param frame
    83          *            The starting Frame this Agent was executed on
    84          */
    85         protected abstract void finalise(Frame frame);
    86 
    87         /**
    88108         * Displays a message to the user
    89109         *
  • trunk/src/org/expeditee/agents/DisplayTree.java

    r43 r45  
    3131
    3232        private Runtime _runtime = Runtime.getRuntime();
    33        
     33
    3434        private long _timeRemaining = 0;
    35 
    36         private int _frameCount = 0;
    37 
    38         private TimeKeeper _timer;
    3935
    4036        public DisplayTree(String delay) {
     
    5248        @Override
    5349        public boolean initialise(Frame start) {
    54                 _timer = new TimeKeeper();
    5550
    5651                // push current frame on to back-stack
    5752                DisplayIO.addToBack(start);
    5853
    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);
    6464        }
    6565
     
    6767        protected void processFrame(Frame toProcess) {
    6868                long freeMemory = _runtime.freeMemory();
    69                 if(freeMemory < GARBAGE_COLLECTION_THRESHOLD){
     69                if (freeMemory < GARBAGE_COLLECTION_THRESHOLD) {
    7070                        _runtime.gc();
    7171                        FrameGraphics.DisplayMessage("Force Garbage Collection!");
    7272                }
    73                
    74                 //FrameUtils.ResponseTimer.restart();
    75                
     73
     74                // FrameUtils.ResponseTimer.restart();
     75
    7676                // ignore loops
    7777                if (toProcess != DisplayIO.getCurrentFrame())
    7878                        DisplayIO.setCurrentFrame(toProcess);
    79                         //FrameUtils.DisplayFrame(toProcess,false);
     79                // FrameUtils.DisplayFrame(toProcess,false);
    8080                // parse the frame for any pause settings
    8181                delay(toProcess);
     
    122122        }
    123123
    124         @Override
    125         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 on
    135                 if (!_stop) {
    136                         DisplayIO.Back();
    137                 } else {
    138                         msg = "Agent halted by user. ";
    139                 }
    140 
    141                 message(msg + stats);
    142         }
    143 
    144124        /**
    145125         * Pauses the execution of this Agent for the given time period (in ms.)
  • trunk/src/org/expeditee/agents/SwitchyardTree.java

    r19 r45  
    1111public class SwitchyardTree extends DefaultAgent {
    1212
    13         private Long startTime = 0L;
    14 
    15         private int frameCount = 0;
    16 
    17         private int itemCount = 0;
    18 
    19         @Override
    20         protected void finalise(Frame frame) {
    21                 Long total = System.currentTimeMillis() - startTime;
    22                 FrameGraphics.DisplayMessage("Time: " + total + "ms, frames: "
    23                                 + frameCount + ", items: " + itemCount);
    24         }
    25 
    2613        @Override
    2714        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...");
    3216
    3317                for (Text textItem : frame.getBodyTextItems(false)) {
     
    5438                                                                frame.addItem(itemCopy);
    5539                                                        }
     40                                                        _itemCount++;
    5641                                                }
    5742                                        }
     
    5944                        }
    6045                }
    61 
     46                _frameCount++;
    6247                return null;
    6348        }
  • trunk/src/org/expeditee/agents/TreeProcessor.java

    r4 r45  
    44import java.util.Stack;
    55
     6import org.expeditee.gui.DisplayIO;
    67import org.expeditee.gui.Frame;
    78import org.expeditee.gui.FrameIO;
     
    1718        // the list of frames currently being processed
    1819        private Stack<FrameCounter> _frames = new Stack<FrameCounter>();
    19 
     20       
    2021        /**
    2122         * Processes the Frame by calling processItem() for each unlinked item
     
    8788                        }
    8889                }
    89 
     90               
    9091                return null;
    9192        }
  • trunk/src/org/expeditee/agents/WriteTree.java

    r22 r45  
    66
    77import org.expeditee.actions.Actions;
     8import org.expeditee.gui.DisplayIO;
    89import org.expeditee.gui.Frame;
    910import org.expeditee.gui.FrameGraphics;
     
    5455                }
    5556        }
    56        
     57
    5758        public WriteTree(String format, String outFile) {
    5859                _format = format;
     
    147148                }
    148149
    149                 return true;
    150         }
    151 
    152         @Override
    153         protected void finalise(Frame start) {
     150                return super.initialise(start);
    154151        }
    155152
     
    159156                try {
    160157
    161                         if (_followLinks)
     158                        if (_followLinks) {
    162159                                msg = _treeWriter.writeTree(frame);
    163                         else
     160                                _frameCount = _treeWriter.getFrameCount();
     161                        } else {
    164162                                msg = _frameWriter.writeFrame(frame);
    165 
     163                                _frameCount = 1;
     164                        }
    166165                } catch (IOException e) {
    167166                        System.out.println("Caught");
Note: See TracChangeset for help on using the changeset viewer.