00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.benchmarks.timit.util;
00032
00041 public class SecuredHierarchicalTimer extends HierarchicalTimer {
00042
00046 private static final long serialVersionUID = 4851461458559620436L;
00047
00048 private int headCounterID = -1;
00049
00050 private void checkRange(int n) {
00051 if (n < 0 || n >= this.getNbCounter()) {
00052 throw new IllegalArgumentException(
00053 "Incorrect counter id. Maybe it has be set by a wrong "
00054 + "Timed instance. If it is a stop, maybe you never start"
00055 + "this counter.");
00056 }
00057 }
00058
00059 private boolean internalIsStarted(int n) {
00060 return this.parent[0] == n || this.parent[1] == n
00061 || this.parent[2] == n;
00062 }
00063
00064 private boolean isJustStarted(int n) {
00065 return this.level >= 0 && this.parent[this.level] == n;
00066 }
00067
00068 private String getInfos(int n, int lev) {
00069 return "'" + this.getCounterName(n) + "' [id=" + n + ", level=" + lev
00070 + "]";
00071 }
00072
00079 public void resetCounter(int n) {
00080 this.checkRange(n);
00081 super.resetCounter(n);
00082 }
00083
00090 public void start(int n) {
00091 this.checkRange(n);
00092 if (this.internalIsStarted(n)) {
00093 throw new IllegalStateException("TimerCounter "
00094 + this.getInfos(n, this.level + 1) + " already started !");
00095 }
00096 if (this.headCounterID == -1) {
00097 this.headCounterID = n;
00098 }
00099 if ((this.level + 1) == 0 && n != this.headCounterID) {
00100 throw new IllegalStateException(
00101 "Bad counters placement: not hierarchical. TimerCounter "
00102 + this.getInfos(this.headCounterID, 0)
00103 + " is already the "
00104 + "counter's head and "
00105 + this.getInfos(n, 0)
00106 + " can't be set "
00107 + "as head also. Try to make a global TOTAL counter "
00108 + "which include the others.");
00109 }
00110 super.start(n);
00111 }
00112
00119 public void stop(int n) {
00120 this.checkRange(n);
00121 if (!this.isJustStarted(n)) {
00122 if (!this.internalIsStarted(n)) {
00123 throw new IllegalStateException("TimerCounter "
00124 + this.getInfos(n, this.level)
00125 + " must be started before being stopped !");
00126 } else {
00127 throw new IllegalStateException(
00128 "TimerCounter "
00129 + this.getInfos(n, this.level)
00130 + " stop misplaced. The last started counter is "
00131 + this.getCounterName(this.parent[this.level])
00132 + " and you should "
00133 + "stop this one. Maybe your start/stop are imbricated.");
00134 }
00135 } else {
00136 super.stop(n);
00137 this.parent[this.level + 1] = -1;
00138 }
00139 }
00140
00144 public int readTimer(int i, int j, int k) {
00145 this.checkRange(i);
00146 this.checkRange(j);
00147 this.checkRange(k);
00148 return super.readTimer(i, j, k);
00149 }
00150 }