org/objectweb/proactive/benchmarks/timit/util/TimItStore.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.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 //        System.err.println("proactive.timit.activation = " + Arrays.toString(this.activation));
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 }

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