BaseTimelineThread.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.traceviewer.timeline;
00002 
00003 import java.util.Queue;
00004 import java.util.concurrent.Callable;
00005 import java.util.concurrent.atomic.AtomicInteger;
00006 
00007 import org.eclipse.core.runtime.IProgressMonitor;
00008 
00009 import edu.rice.cs.hpc.traceviewer.data.db.DataPreparation;
00010 import edu.rice.cs.hpc.traceviewer.data.db.TimelineDataSet;
00011 import edu.rice.cs.hpc.traceviewer.data.graph.ColorTable;
00012 import edu.rice.cs.hpc.traceviewer.data.timeline.ProcessTimeline;
00013 import edu.rice.cs.hpc.traceviewer.spaceTimeData.SpaceTimeDataController;
00014 
00015 /*****************************************************************************
00016  * 
00017  * Abstract class for handling data collection
00018  * The class is based on Java Callable, and returns the number of
00019  * traces the thread has been processed
00020  *
00021  * @author Michael Franco 
00022  *  modified by Laksono and Philip
00023  *****************************************************************************/
00024 public abstract class BaseTimelineThread implements Callable<Integer> {
00025 
00027     final static byte MIN_HEIGHT_FOR_SEPARATOR_LINES = 15;
00028 
00030     final protected SpaceTimeDataController stData;
00031     
00033     final private double scaleY;    
00034     final protected boolean usingMidpoint;
00035     final private Queue<TimelineDataSet> queue;
00036     final private AtomicInteger numTimelines;
00037     final private IProgressMonitor monitor;
00038 
00039     public BaseTimelineThread(SpaceTimeDataController stData,
00040             double scaleY, Queue<TimelineDataSet> queue, 
00041             AtomicInteger numTimelines, boolean usingMidpoint, IProgressMonitor monitor)
00042     {
00043         this.stData        = stData;
00044         this.scaleY        = scaleY;
00045         this.usingMidpoint = usingMidpoint;
00046         this.queue         = queue;
00047         this.numTimelines  = numTimelines;
00048         this.monitor       = monitor;
00049     }
00050     
00051     @Override
00052     /*
00053      * (non-Javadoc)
00054      * @see java.util.concurrent.Callable#call()
00055      */
00056     public Integer call() throws Exception {
00057 
00058         ProcessTimeline trace = getNextTrace();
00059         Integer numTraces = 0;
00060         final double pixelLength = (stData.getAttributes().getTimeInterval())/(double)stData.getPixelHorizontal();
00061         final long timeBegin = stData.getAttributes().getTimeBegin();
00062 
00063         while (trace != null)
00064         {
00065             // ---------------------------------
00066             // begin collecting the data if needed
00067             // ---------------------------------
00068             if (init(trace))
00069             {               
00070                 int h1 = (int) Math.round(scaleY*trace.line());
00071                 int h2 = (int) Math.round(scaleY*(trace.line()+1)) ;            
00072                 int imageHeight = h2 - h1;
00073                 
00074                 if (scaleY > MIN_HEIGHT_FOR_SEPARATOR_LINES)
00075                     imageHeight--;
00076                 else
00077                     imageHeight++;
00078 
00079                 // ---------------------------------
00080                 // do the data preparation
00081                 // ---------------------------------
00082 
00083                 final DataPreparation data = getData(stData.getColorTable(),
00084                         trace, timeBegin, trace.line(),
00085                         imageHeight, pixelLength, usingMidpoint);
00086                 
00087                 data.collect();
00088                 
00089                 final TimelineDataSet dataSet = data.getList();
00090                 queue.add(dataSet);             
00091             }
00092             numTimelines.decrementAndGet();
00093             if (!monitor.isCanceled())
00094                 monitor.worked(1);
00095             
00096             trace = getNextTrace();
00097             numTraces++;
00098             
00099             // ---------------------------------
00100             // finalize
00101             // ---------------------------------
00102             finalize();
00103             monitor.done();
00104         }
00105         return numTraces;
00106     }
00107 
00108     /****
00109      * Retrieve the next available trace, null if no more trace available 
00110      * 
00111      * @return
00112      ****/
00113     abstract protected ProcessTimeline getNextTrace();
00114     
00115     abstract protected boolean init(ProcessTimeline trace);
00116     
00117     abstract protected void finalize();
00118     
00119     abstract protected DataPreparation getData(ColorTable colorTable, ProcessTimeline timeline,
00120             long timeBegin, int linenum,
00121             int height, double pixelLength, boolean midPoint);
00122 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1