1 16 package org.apache.cocoon.webservices.instrument; 17 18 import org.apache.avalon.framework.logger.AbstractLogEnabled; 19 20 import org.apache.excalibur.instrument.InstrumentManager; 21 import org.apache.excalibur.instrument.manager.DefaultInstrumentManager; 22 import org.apache.excalibur.instrument.manager.InstrumentDescriptor; 23 import org.apache.excalibur.instrument.manager.InstrumentSampleDescriptor; 24 import org.apache.excalibur.instrument.manager.InstrumentableDescriptor; 25 26 import java.util.ArrayList ; 27 import java.util.List ; 28 29 36 public final class InstrumentationServiceImpl extends AbstractLogEnabled 37 implements InstrumentationService { 38 39 private static final int[] EMPTY_INT_ARRAY = {}; 40 private static final String [] EMPTY_STRING_ARRAY = {}; 41 42 private DefaultInstrumentManager m_iManager; 44 45 50 public void setInstrumentManager(final InstrumentManager iManager) { 51 52 if (iManager == null) { 53 if (getLogger().isWarnEnabled()) 54 getLogger().warn( 55 "No instrument manager available," + 56 "please enable instrumentation in your web.xml" 57 ); 58 } 59 60 if (iManager instanceof DefaultInstrumentManager) { 62 m_iManager = (DefaultInstrumentManager) iManager; 63 } else { 64 throw new UnsupportedOperationException ( 65 "InstrumentationService only supports DefaultInstrumentManager" 66 ); 67 } 68 } 69 70 99 public int[] getSampleSnapshot(final String path) 100 throws Exception { 101 102 if (!haveInstrumentManager()) { 104 getLogger().warn( 105 "No instrument manager available," + 106 "please enable instrumentation in your web.xml" 107 ); 108 return EMPTY_INT_ARRAY; 109 } 110 111 return m_iManager.locateInstrumentSampleDescriptor(path) 113 .getSnapshot().getSamples(); 114 } 115 116 122 public String [] getSampleNames() { 123 124 if (!haveInstrumentManager()) { 126 getLogger().warn( 127 "No instrument manager available," + 128 "please enable instrumentation in your web.xml" 129 ); 130 return EMPTY_STRING_ARRAY; 131 } 132 133 final InstrumentableDescriptor[] descriptors = 135 m_iManager.getInstrumentableDescriptors(); 136 final List names = new ArrayList (); 137 138 for (int i = 0; i < descriptors.length; ++i) { 139 InstrumentDescriptor[] insts = 141 descriptors[i].getInstrumentDescriptors(); 142 143 for (int k = 0; k < insts.length; ++k) { 144 145 InstrumentSampleDescriptor[] samples = 147 insts[k].getInstrumentSampleDescriptors(); 148 149 for (int j = 0; j < samples.length; ++j) { 150 names.add(samples[j].getName()); 151 } 152 } 153 } 154 155 return (String [])names.toArray(new String []{}); 156 } 157 158 163 private boolean haveInstrumentManager() { 164 return (m_iManager != null); 165 } 166 } 167
| Popular Tags
|