1 19 20 package org.apache.excalibur.instrument.client.http; 21 22 import java.util.ArrayList ; 23 import java.util.HashMap ; 24 import java.util.List ; 25 import java.util.Map ; 26 27 import org.apache.avalon.framework.configuration.Configuration; 28 import org.apache.avalon.framework.configuration.ConfigurationException; 29 30 import org.apache.excalibur.instrument.client.InstrumentableData; 31 import org.apache.excalibur.instrument.client.InstrumentData; 32 33 class HTTPInstrumentableData 34 extends AbstractHTTPElementData 35 implements InstrumentableData 36 { 37 38 private boolean m_registered; 39 40 private List m_instrumentables = new ArrayList (); 41 private HTTPInstrumentableData[] m_instrumentableAry; 42 private Map m_instrumentableMap = new HashMap (); 43 44 private List m_instruments = new ArrayList (); 45 private HTTPInstrumentData[] m_instrumentAry; 46 private Map m_instrumentMap = new HashMap (); 47 48 51 54 HTTPInstrumentableData( AbstractHTTPData parent, 55 String name ) 56 { 57 super( (HTTPInstrumentManagerConnection)parent.getConnection(), parent, name ); 58 59 m_registered = false; 60 } 61 62 65 74 protected void update( Configuration configuration, boolean recurse ) 75 throws ConfigurationException 76 { 77 super.update( configuration ); 78 79 if ( getLogger().isDebugEnabled() ) 80 { 81 getLogger().debug( 82 "Updated Instrumentable '" + getName() + "' to version " + getStateVersion() ); 83 } 84 85 m_registered = configuration.getAttributeAsBoolean( "registered" ); 86 87 Configuration[] instrumentableConfs = configuration.getChildren( "instrumentable" ); 88 for ( int i = 0; i < instrumentableConfs.length; i++ ) 89 { 90 Configuration iaConf = instrumentableConfs[i]; 91 String iaName = iaConf.getAttribute( "name" ); 92 int iaStateVersion = iaConf.getAttributeAsInteger( "state-version" ); 93 94 HTTPInstrumentableData iaData; 95 synchronized( m_instrumentables ) 96 { 97 iaData = (HTTPInstrumentableData)m_instrumentableMap.get( iaName ); 98 if ( iaData == null ) 99 { 100 iaData = new HTTPInstrumentableData( this, iaName ); 102 iaData.enableLogging( getLogger().getChildLogger( iaName ) ); 103 m_instrumentables.add( iaData ); 104 m_instrumentableAry = null; 105 m_instrumentableMap.put( iaName, iaData ); 106 } 107 } 108 109 if ( recurse ) 110 { 111 iaData.update( iaConf, recurse ); 112 } 113 else 114 { 115 if ( iaStateVersion != iaData.getStateVersion() ) 116 { 117 iaData.update(); 119 } 120 } 121 } 122 123 Configuration[] instrumentConfs = configuration.getChildren( "instrument" ); 124 for ( int i = 0; i < instrumentConfs.length; i++ ) 125 { 126 Configuration iConf = instrumentConfs[i]; 127 String iName = iConf.getAttribute( "name" ); 128 int iStateVersion = iConf.getAttributeAsInteger( "state-version" ); 129 130 HTTPInstrumentData iData; 131 synchronized( m_instruments ) 132 { 133 iData = (HTTPInstrumentData)m_instrumentMap.get( iName ); 134 if ( iData == null ) 135 { 136 iData = new HTTPInstrumentData( this, iName ); 138 iData.enableLogging( getLogger().getChildLogger( iName ) ); 139 m_instruments.add( iData ); 140 m_instrumentAry = null; 141 m_instrumentMap.put( iName, iData ); 142 } 143 } 144 145 if ( recurse ) 146 { 147 iData.update( iConf, recurse ); 148 } 149 else 150 { 151 if ( iStateVersion != iData.getStateVersion() ) 152 { 153 iData.update(); 155 } 156 } 157 } 158 } 159 160 166 public boolean update() 167 { 168 HTTPInstrumentManagerConnection connection = 169 (HTTPInstrumentManagerConnection)getConnection(); 170 171 Configuration configuration = connection.getState( 172 "instrumentable.xml?packed=true&name=" + urlEncode( getName() ) ); 173 if ( configuration != null ) 174 { 175 try 176 { 177 update( configuration, false ); 178 return true; 179 } 180 catch ( ConfigurationException e ) 181 { 182 getLogger().debug( "Unable to update.", e ); 183 } 184 } 185 186 return false; 187 } 188 189 192 197 public boolean isRegistered() 198 { 199 return m_registered; 200 } 201 202 207 public InstrumentableData[] getInstrumentables() 208 { 209 HTTPInstrumentableData[] instrumentables = m_instrumentableAry; 210 if ( instrumentables == null ) 211 { 212 synchronized ( m_instrumentables ) 213 { 214 m_instrumentableAry = new HTTPInstrumentableData[m_instrumentables.size()]; 215 m_instrumentables.toArray( m_instrumentableAry ); 216 instrumentables = m_instrumentableAry; 217 } 218 } 219 return instrumentables; 220 } 221 222 227 public InstrumentData[] getInstruments() 228 { 229 HTTPInstrumentData[] instruments = m_instrumentAry; 230 if ( instruments == null ) 231 { 232 synchronized ( m_instruments ) 233 { 234 m_instrumentAry = new HTTPInstrumentData[m_instruments.size()]; 235 m_instruments.toArray( m_instrumentAry ); 236 instruments = m_instrumentAry; 237 } 238 } 239 return instruments; 240 } 241 242 245 } | Popular Tags |