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.util.ArrayList;
00034 import java.util.HashMap;
00035 import java.util.Arrays;
00036
00037 import org.objectweb.proactive.Body;
00038 import org.objectweb.proactive.ProActive;
00039 import org.objectweb.proactive.benchmarks.timit.util.observing.EventObserver;
00040
00047 public class TimItStore {
00048
00049 private static TimItStore vmInstance;
00050 private static HashMap<Body, TimItStore> timerStoreMap =
00051 new HashMap<Body, TimItStore>();
00052
00053 private String[] activation;
00054 private Timed timed;
00055 private ArrayList<TimerCounter> tcList;
00056
00060 private TimItStore( Timed timed ) {
00061 String prop = System.getProperty("proactive.timit.activation");
00062 if( prop == null ) {
00063 this.activation = new String[0];
00064 } else {
00065 this.activation = prop.split(",");
00066 }
00067 Arrays.sort(this.activation);
00068
00069 this.tcList = new ArrayList<TimerCounter>();
00070 this.timed = timed;
00071 }
00072
00079 synchronized public static TimItStore getInstance( Timed timed ) {
00080 Body body = ProActive.getBodyOnThis();
00081
00082 if (body == null) {
00083 if (vmInstance == null) {
00084 vmInstance = new TimItStore(timed);
00085 }
00086 return vmInstance;
00087 }
00088 TimItStore ts = TimItStore.timerStoreMap.get(body);
00089 if (ts == null) {
00090 ts = new TimItStore(timed);
00091 TimItStore.timerStoreMap.put(body, ts);
00092 }
00093 return ts;
00094 }
00095
00096 public TimerCounter addTimerCounter( TimerCounter tc ) {
00097 if( Arrays.binarySearch(this.activation, tc.getName()) >= 0 ) {
00098 this.tcList.add(tc);
00099 }
00100 return tc;
00101 }
00102
00103 public EventObserver addEventObserver( EventObserver eo ) {
00104 if( Arrays.binarySearch(this.activation, eo.getName()) > 0 ) {
00105 this.timed.getEventObservable().addObserver(eo);
00106 }
00107 return eo;
00108 }
00109
00110 public void activation() {
00111 TimerCounter[] tcActivate = this.tcList.toArray(new TimerCounter[0]);
00112 this.timed.activate(tcActivate);
00113 }
00114 }