1 4 package com.tcsimulator.listener; 5 6 import com.tc.simulator.listener.StatsListener; 7 8 import java.util.Iterator ; 9 import java.util.Map ; 10 import java.util.Properties ; 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 TOKEN = "<app-perf>"; 17 private final LinkedQueue outputQueue; 18 19 private final String label; 20 21 public StatsListenerObject(Properties properties, LinkedQueue outputQueue) { 22 StringBuffer buf = new StringBuffer (); 23 for (Iterator i = properties.entrySet().iterator(); i.hasNext();) { 24 Map.Entry 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 desc) { 35 if(desc == null) desc = ""; 36 try { 37 outputQueue.put(TOKEN + label + desc + ": " + sampleValue); 38 } catch (InterruptedException e) { 39 throw new RuntimeException (e); 40 } 41 } 42 43 } | Popular Tags |