KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tcsimulator > listener > StatsListenerObject


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tcsimulator.listener;
5
6 import com.tc.simulator.listener.StatsListener;
7
8 import java.util.Iterator JavaDoc;
9 import java.util.Map JavaDoc;
10 import java.util.Properties JavaDoc;
11 import java.util.Map.Entry;
12
13 import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
14
15 public final class StatsListenerObject implements StatsListener {
16   private static final String JavaDoc TOKEN = "<app-perf>";
17   private final LinkedQueue outputQueue;
18
19   private final String JavaDoc label;
20
21   public StatsListenerObject(Properties JavaDoc properties, LinkedQueue outputQueue) {
22     StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
23     for (Iterator JavaDoc i = properties.entrySet().iterator(); i.hasNext();) {
24       Map.Entry JavaDoc entry = (Entry) i.next();
25       buf.append(entry.getKey() + "=" + entry.getValue());
26       if (i.hasNext()) {
27         buf.append(",");
28       }
29     }
30     this.label = buf.toString();
31     this.outputQueue = outputQueue;
32   }
33
34   public void sample(long sampleValue, String JavaDoc desc) {
35     if(desc == null) desc = "";
36     try {
37       outputQueue.put(TOKEN + label + desc + ": " + sampleValue);
38     } catch (InterruptedException JavaDoc e) {
39       throw new RuntimeException JavaDoc(e);
40     }
41   }
42
43 }
Popular Tags