1 19 20 package org.apache.excalibur.instrument.client.http; 21 22 import java.util.StringTokenizer ; 23 24 import org.apache.excalibur.instrument.client.Data; 25 import org.apache.excalibur.instrument.client.InstrumentSampleSnapshotData; 26 27 import org.apache.avalon.framework.configuration.Configuration; 28 import org.apache.avalon.framework.configuration.ConfigurationException; 29 30 class HTTPInstrumentSampleSnapshotData 31 extends AbstractHTTPInstrumentSampleElementData 32 implements InstrumentSampleSnapshotData 33 { 34 35 private int[] m_samples; 36 37 40 46 HTTPInstrumentSampleSnapshotData( HTTPInstrumentManagerConnection connection, 47 String name ) 48 { 49 super( connection, null, name ); 50 } 51 52 55 60 public Data getParent() 61 { 62 throw new IllegalStateException ( "getParent() can not be called for snapshots." ); 63 } 64 65 72 protected void update( Configuration configuration ) 73 throws ConfigurationException 74 { 75 super.update( configuration ); 76 77 if ( getLogger().isDebugEnabled() ) 78 { 79 getLogger().debug( "Updated Instrument Sample snapshot '" + getName() + "' " 80 + "to version " + getStateVersion() ); 81 } 82 83 int count = configuration.getAttributeAsInteger( "count", getSize() ); 85 86 m_samples = new int[count]; 87 88 String rawSamples = configuration.getChild( "values" ).getValue( "" ); 89 StringTokenizer st = new StringTokenizer ( rawSamples, ", " ); 90 91 int i = 0; 94 while ( st.hasMoreTokens() && ( i < m_samples.length ) ) 95 { 96 int value; 97 try 98 { 99 value = Integer.parseInt( st.nextToken() ); 100 } 101 catch ( NumberFormatException e ) 102 { 103 value = 0; 104 } 105 m_samples[i] = value; 106 i++; 107 } 108 } 109 110 116 public boolean update() 117 { 118 HTTPInstrumentManagerConnection connection = 119 (HTTPInstrumentManagerConnection)getConnection(); 120 121 Configuration configuration = connection.getState( 122 "snapshot.xml?packed=true&name=" + urlEncode( getName() ) + "&compact=true" ); 123 if ( configuration != null ) 124 { 125 try 126 { 127 update( configuration ); 128 129 return true; 130 } 131 catch ( ConfigurationException e ) 132 { 133 getLogger().debug( "Unable to update.", e ); 134 } 135 } 136 137 return false; 138 } 139 140 143 148 public int[] getSamples() 149 { 150 return m_samples; 151 } 152 153 156 } | Popular Tags |