Coverage report

  %line %branch
net.sf.infrared.base.model.OperationStatistics
80% 
89% 

 1  
 /* 
 2  
  * Copyright 2005 Tavant Technologies and Contributors
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License")
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  * 
 16  
  *
 17  
  *
 18  
  * Original Author:  binil.thomas (Tavant Technologies)
 19  
  * Contributor(s):   -;
 20  
  *
 21  
  */
 22  
 package net.sf.infrared.base.model;
 23  
 
 24  
 import java.util.Collections;
 25  
 import java.util.List;
 26  
 import java.util.Map;
 27  
 import java.util.Set;
 28  
 
 29  
 import net.sf.infrared.base.util.Tree;
 30  
 
 31  
 /**
 32  
  * Represents the statistics collected for a given operation. An operation represents a single 
 33  
  * request that executes in one thread.
 34  
  * 
 35  
  * @author binil.thomas
 36  
  */
 37  
 public class OperationStatistics extends AbstractStatistics {
 38  
     // tree of executions for this operation. Each value of a TreeNode in the tree
 39  
     // is an instance of a ExecutiomTimer object (captured only if call tree statistics
 40  
     // is enabled)
 41  
     private Tree operationTree;
 42  
 
 43  
     // map of heirarchical layer name -> list of ExecutionTimer objects
 44  
     // this map identifies the various executions that happened in each layer heirarchy
 45  
     private Map executions;
 46  
 
 47  
     // map of heirarchical layer name -> LayerTime objects
 48  
     // this map identifies the time taken in various layers
 49  
     private Map layers;
 50  
     
 51  
     // system time when the operation started
 52  11
     private long startTime = -1;
 53  
     
 54  
     // system time when the operation ended
 55  11
     private long endTime = -1;
 56  
     
 57  11
     private int numOfExecsTracked = 0;
 58  
     
 59  11
     private int numOfExecsIgnored = 0;
 60  
     
 61  
     public OperationStatistics(String application, String instance) {
 62  11
         super(application, instance);
 63  11
     }
 64  
 
 65  
     public Tree getOperationTree() {
 66  3
         return operationTree;
 67  
     }
 68  
 
 69  
     public void setOperationTree(Tree tree) {
 70  2
         if (operationTree != null) {
 71  1
             throw new IllegalStateException("operation tree is already set; can't set it again");
 72  
         }
 73  1
         this.operationTree = tree;
 74  1
     }
 75  
     
 76  
     public void setLayerTimes(Map layerTimes) {
 77  
 //        if (this.layers != null) {
 78  
 //            throw new IllegalStateException("layer times are already set; can't set it again");
 79  
 //        }
 80  
 //        
 81  
 //        if (this.executions != null) {
 82  
 //            Set layerNamesAsPerLayersMap = layerTimes.keySet();
 83  
 //            Set layerNamesAsPerExecutionsMap = this.executions.keySet();
 84  
 //            
 85  
 //            if (! layerNamesAsPerLayersMap.equals( layerNamesAsPerExecutionsMap )) {
 86  
 //                throw new IllegalArgumentException("execution timings set earlier has a" +
 87  
 //                        " different set of layers[" + layerNamesAsPerExecutionsMap + "]" +
 88  
 //                        " which does not match the layers of this layer timings " +
 89  
 //                        "[" + layerNamesAsPerLayersMap + "]");
 90  
 //            }
 91  
 //        }
 92  4
         this.layers = layerTimes;
 93  4
     }
 94  
     
 95  
     public void setExecutionTimes(Map executionTimes) {
 96  
 //        if (this.executions != null) {
 97  
 //            throw new IllegalStateException("execution times are already set; can't set again");
 98  
 //        }
 99  
 //        
 100  
 //        if (this.layers != null) {
 101  
 //            Set layerNamesAsPerLayersMap = this.layers.keySet();
 102  
 //            Set layerNamesAsPerExecutionsMap = executionTimes.keySet();
 103  
 //            
 104  
 //            if (! layerNamesAsPerLayersMap.equals( layerNamesAsPerExecutionsMap )) {
 105  
 //                throw new IllegalArgumentException("layer timings set earlier has a different" +
 106  
 //                        " set of layers[" + layerNamesAsPerLayersMap + "] which does not match" +
 107  
 //                        " the layers of this execution timings " +
 108  
 //                        "[" + layerNamesAsPerExecutionsMap + "]");
 109  
 //            }
 110  
 //        }
 111  3
         this.executions = executionTimes;
 112  3
     }
 113  
     
 114  
     public void setNumOfExecutions(int tracked, class="keyword">int ignored) {
 115  0
         numOfExecsTracked = tracked;
 116  0
         numOfExecsIgnored = ignored;
 117  0
     }
 118  
 
 119  
     public long getEndTime() {
 120  3
         return endTime;
 121  
     }
 122  
     
 123  
     public void setEndTime(long time) {
 124  2
         if (this.endTime != -1) {
 125  1
             throw new IllegalStateException("end time is already set; can't set again");
 126  
         }
 127  1
         this.endTime = time;
 128  1
     }
 129  
 
 130  
     public long getStartTime() {
 131  3
         return startTime;
 132  
     }
 133  
     
 134  
     public void setStartTime(long time) {
 135  2
         if (this.startTime != -1) {
 136  1
             throw new IllegalStateException("start time is already set; can't set again");
 137  
         }
 138  1
         this.startTime = time;
 139  1
     }
 140  
     
 141  
     public String[] getLayers() {
 142  5
         if (layers == null) {
 143  3
             return new String[0];
 144  
         }
 145  2
         return  (String[]) layers.keySet().toArray(new String[0]);
 146  
     }
 147  
     
 148  
     public long getTimeInLayer(String layerName) {
 149  0
         LayerTime lt = (LayerTime) layers.get(layerName);
 150  0
         if (lt == null) {
 151  0
             return -1;
 152  
         } else {
 153  0
             return lt.getTime();
 154  
         }
 155  
     }
 156  
     
 157  
     public ExecutionTimer[] getExecutions(String layerName) {
 158  1
         List l =  (List) executions.get(layerName);
 159  1
         if (l == null) {
 160  0
             return new ExecutionTimer[0];
 161  
         }
 162  1
         return (ExecutionTimer[]) l.toArray(new ExecutionTimer[0]);
 163  
     }
 164  
 
 165  
     public String toString() {
 166  2
         return "OperationStatistics[" + getApplicationName() + " on " +getInstanceId()
 167  
                 + "] started at " + getStartTime() + ", ended at " + getEndTime() 
 168  
                 + "; captured " + numOfExecsTracked + " executions; ignored " + numOfExecsIgnored
 169  
                 + "ignored";
 170  
     }
 171  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.