1 16 package org.apache.cocoon.components.profiler; 17 18 import org.apache.avalon.framework.configuration.Configurable; 19 import org.apache.avalon.framework.configuration.Configuration; 20 import org.apache.avalon.framework.configuration.ConfigurationException; 21 import org.apache.avalon.framework.logger.AbstractLogEnabled; 22 import org.apache.avalon.framework.thread.ThreadSafe; 23 24 import java.util.Collection ; 25 import java.util.HashMap ; 26 import java.util.Map ; 27 28 36 public class ProfilerImpl extends AbstractLogEnabled 37 implements Profiler, ThreadSafe, Configurable { 38 39 private int results_count = 10; 41 42 private Map results; 43 44 public ProfilerImpl() 45 { 46 results = new HashMap (); 47 } 48 49 55 public void configure(Configuration configuration) 56 throws ConfigurationException { 57 58 this.results_count = configuration.getAttributeAsInteger("results", 10); 59 } 60 61 64 public void clearResults() 65 { 66 results.clear(); 67 } 68 69 72 public void clearResult(Object key) 73 { 74 results.remove(key); 75 } 76 77 82 public Collection getResultKeys() 83 { 84 return results.keySet(); 85 } 86 87 92 public Collection getResults() 93 { 94 return results.values(); 95 } 96 97 103 public ProfilerResult getResult(Object key) 104 { 105 return (ProfilerResult)results.get(key); 106 } 107 108 114 public void addResult(String uri, ProfilerData data) 115 { 116 Long key = new Long (data.getKey(uri)); 117 ProfilerResult result = (ProfilerResult)results.get(key); 118 if(result == null){ 119 synchronized(results){ 120 if((result = (ProfilerResult)results.get(key)) == null) 121 results.put(key, result = new ProfilerResult(uri, results_count)); 122 } 123 } 124 125 result.addData(data); 126 } 127 } 128 | Popular Tags |