long[] lastTimes = new long[frames.length];
HTTPInstrumentSampleSnapshotData[] snapshots =
new HTTPInstrumentSampleSnapshotData[frames.length];
for ( int i = 0; i < frames.length; i++ )
{
InstrumentSampleFrame frame = frames[i];
names[i] = frame.getInstrumentSampleName();
lastTimes[i] = frame.getLastSnapshotTime();
}
// Request the snapshots. Don't bother if we know we are not connected.
if ( isConnected() )
{
StringBuffer sb = new StringBuffer();
sb.append( "snapshots.xml?packed=true&compact=true" );
for ( int i = 0; i < frames.length; i++ )
{
sb.append( "&name=" );
sb.append( this.urlEncode( names[i] ) );
sb.append( "&base-time=" );
sb.append( lastTimes[i] );
}
Configuration configuration = getState( sb.toString() );
if ( configuration != null )
{
Configuration[] snapshotConfs = configuration.getChildren( "sample" );
for ( int i = 0; i < snapshotConfs.length; i++ )
{
Configuration snapshotConf = snapshotConfs[i];
String name = snapshotConf.getAttribute( "name", null );
if ( name != null )
{
boolean expired = snapshotConf.getAttributeAsBoolean( "expired", false );
if ( !expired )
{
// Look for the specified sample frame. Should always exist.
for ( int j = 0; j < frames.length; j++ )
{
if ( name.equals( names[j] ) )
{
snapshots[j] =
new HTTPInstrumentSampleSnapshotData( this, name );
snapshots[j].enableLogging( getLogger() );
try
{
snapshots[j].update( snapshotConf );
}
catch ( ConfigurationException e )
{
// Should not happen.
getLogger().info( "Snapshot update failed.", e );
getLogger().info( " URL: " + sb.toString() );
getLogger().info( " i:" + i + " j:" + j );
snapshots[j] = null;
}
break;
}
}
}
}
}
}
}
// Now we should have all available snapshots. Loop back over the frames
// and update them as is appropriate.
for ( int i = 0; i < frames.length; i++ )
{
InstrumentSampleFrame frame = frames[i];
frame.updateSnapshot( snapshots[i] );
}
}