leif 2004/02/05 07:28:09
Modified: instrument-manager/src/java/org/apache/excalibur/instrument/manager/http
HTMLSampleHandler.java
Log:
Fix a problem where a machine suspended for a few hours while viewing a
sample page with auto refresh enabled was causing several thousand requests
for sample images when it was resumed. This was due to the javascript involved
making use of the setInterval function which was trying to catch up. We now use
setTimeout which is always relative to when it is set.
Revision Changes Path
1.2 +30 -8
avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/HTMLSampleHandler.java
Index: HTMLSampleHandler.java
===================================================================
RCS file:
/home/cvs/avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/http/HTMLSampleHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HTMLSampleHandler.java 9 Nov 2003 16:36:33 -0000 1.1
+++ HTMLSampleHandler.java 5 Feb 2004 15:28:09 -0000 1.2
@@ -210,21 +210,43 @@
out.println( "<h2>Data Samples (<a href='sample.html?name="
+ urlEncode( desc.getName() ) + "'>Plain</a>)</h2>" );
+ // Originally, the JavaScript timer in the page made use of the
setInterval
+ // function to build a simple timer. This worked fine under normal
+ // operation. But if a browser was suspended for 1 hour with a timer
+ // running at 1 second intervals, the timer would try to catch up when
+ // the machine was resumed. This would result in the timer firing 3600
+ // times over the course of a few seconds. The sudden burst of
requests
+ // was swamping the server.
+ // The current scripts below now always reset the timer each time it is
+ // fired. If the timer ever falls behind it will recover smoothly
+ // without trying to catch up. While not quite as accurate it is
+ // sufficient for our purposes.
+
out.println( "<SCRIPT LANGUAGE=\"JavaScript\">" );
- out.println( "var intervalId;" );
+ out.println( "var timerId = 0;" );
+ out.println( "var timerInterval = 5000;" );
out.println( "function refreshChart() {" );
+ //out.println( " alert(\"in refreshChart()\");" );
out.println( " document.chart.src=\"sample-chart.jpg?name=" +
urlEncode( desc.getName() ) + "&time=\" + new Date().getTime();" );
out.println( "}" );
+ out.println( "function timerFired() {" );
+ //out.println( " alert(\"in timerFired()\");" );
+ out.println( " if (timerId) {" );
+ out.println( " clearTimeout(timerId);" );
+ out.println( " }" );
+ out.println( " timerId = setTimeout(\"timerFired()\", timerInterval)"
);
+ out.println( " refreshChart();" );
+ out.println( "}" );
out.println( "function setRefresh(refresh) {" );
- out.println( " clearInterval(intervalId);" );
- out.println( " intervalId = setInterval(\"refreshChart()\", refresh);"
);
+ //out.println( " alert(\"in setRefresh(\" + refresh + \")\");" );
+ out.println( " timerInterval = refresh;" );
+ out.println( " timerFired();" );
out.println( "}" );
out.println( "function chartError() {" );
- out.println( " clearInterval(intervalId);" );
+ //out.println( " alert(\"in chartError()\");" );
+ out.println( " clearTimeout(timerId);" );
out.println( " document.location=\"instrument.html?name=" + urlEncode(
desc.getInstrumentDescriptor().getName() ) + "\";" );
out.println( "}" );
- // No auto refresh by default.
- //out.println( "setRefresh(5000);" );
out.println( "</SCRIPT>" );
out.println( "<form>" );
@@ -232,7 +254,7 @@
tableCell( out, "<img name='chart' src='sample-chart.jpg?name=" +
urlEncode( desc.getName() ) + "' onError='javascript:chartError()'>" );
endTable( out );
out.println( "Refresh rate:" );
- out.println( "<input type='button' value='No Refresh'
onClick='javascript:clearInterval(intervalId)'>" );
+ out.println( "<input type='button' value='No Refresh'
onClick='javascript:clearTimeout(timerId)'>" );
out.println( "<input type='button' value='1 Second'
onClick='javascript:setRefresh(1000)'>" );
out.println( "<input type='button' value='5 Seconds'
onClick='javascript:setRefresh(5000)'>" );
out.println( "<input type='button' value='10 Seconds'
onClick='javascript:setRefresh(10000)'>" );
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]