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
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 ) {
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 }