org/objectweb/proactive/benchmarks/timit/util/Timed.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 
00033 import java.io.Serializable;
00034 
00035 import org.objectweb.proactive.benchmarks.timit.util.observing.EventDataBag;
00036 import org.objectweb.proactive.benchmarks.timit.util.observing.RealEventObservable;
00037 import org.objectweb.proactive.benchmarks.timit.util.observing.FakeEventObservable;
00038 import org.objectweb.proactive.benchmarks.timit.util.observing.EventObservable;
00039 import org.objectweb.proactive.benchmarks.timit.util.observing.EventObserver;
00040 
00047 public class Timed implements Serializable {
00048 
00052     private static final long serialVersionUID = -5295024562082646228L;
00053 
00054     private HierarchicalTimer timer;
00055     
00056     private EventObservable delegatedObservable;
00057 
00058     private TimItReductor timitReductor;
00059 
00063     public Timed() {
00064         if ( true ) { // Here we can switch to a fake observable
00065             this.delegatedObservable = new RealEventObservable();
00066         } else {
00067             this.delegatedObservable = new FakeEventObservable();
00068         }
00069     }
00070 
00074     public void activate() {
00075         this.activate(null, null);
00076     }
00077 
00078     public void activate(TimerCounter[] counters) {
00079         this.activate(counters, null);
00080     }
00081 
00082     public void activate(EventObserver[] events) {
00083         this.activate(null, events);
00084     }
00085 
00094     public void activate(TimerCounter[] counters, EventObserver[] events) {
00095 
00096         if (counters != null) {
00097             this.timer = new HierarchicalTimer();
00098             this.timer.activateCounters(counters, this.timitReductor);
00099         }
00100         if (events != null) {
00101             for (EventObserver element : events) {
00102                 this.delegatedObservable.addObserver(element);
00103             }
00104         }
00105     }
00106 
00107     public void activateDebug(TimerCounter[] counters) {
00108         this.activateDebug(counters, null);
00109     }
00110 
00111     public void activateDebug(EventObserver[] events) {
00112         this.activateDebug(null, events);
00113     }
00114 
00124     public void activateDebug(TimerCounter[] counters, EventObserver[] events) {
00125         System.out.println("\n\n\t !! BE CARREFUL : "
00126                 + "Counters are activated with debug mode (slower) !! \n\n");
00127 
00128         if (counters != null) {
00129             this.timer = new SecuredHierarchicalTimer();
00130             this.timer.activateCounters(counters, this.timitReductor);
00131         }
00132         if (events != null) {
00133             for (EventObserver element : events) {
00134                 this.delegatedObservable.addObserver(element);
00135             }
00136         }
00137     }
00138     
00139     public EventObservable getEventObservable(){
00140         return this.delegatedObservable;
00141     }
00142 
00146     public void resetTimer() {
00147         this.timer.resetTimer();
00148     }
00149 
00154     public void setTimerReduction(TimItReductor red) {
00155         this.timitReductor = red;
00156     }
00157 
00166     public void finalizeTimed(int rank, String information) {
00167         if( this.timitReductor == null ) return;
00168         EventDataBag eventDataBag = this.delegatedObservable.getEventDataBag(rank);
00169         this.timitReductor.receiveAll(eventDataBag, this.timer, information);
00170     }
00171 }

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