org/objectweb/proactive/benchmarks/timit/util/SecuredHierarchicalTimer.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
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 }

Generated on Mon Jan 22 15:16:04 2007 for ProActive by  doxygen 1.5.1