2006-03-19 00:23:23 +00:00
package net.i2p.router.web ;
import java.io.IOException ;
2014-06-15 16:14:13 +00:00
import java.io.Serializable ;
2010-11-21 20:46:48 +00:00
import java.io.Writer ;
2008-07-16 13:42:54 +00:00
import java.util.Comparator ;
2012-01-18 01:54:34 +00:00
import java.util.HashMap ;
2008-07-16 13:42:54 +00:00
import java.util.List ;
2012-01-18 01:54:34 +00:00
import java.util.Map ;
2013-10-28 21:48:02 +00:00
import java.util.Set ;
2008-07-16 13:42:54 +00:00
import java.util.TreeSet ;
2006-03-19 00:23:23 +00:00
import net.i2p.data.DataHelper ;
2008-07-16 13:42:54 +00:00
import net.i2p.stat.Rate ;
2006-03-19 00:23:23 +00:00
2014-07-03 13:08:24 +00:00
/ * *
* / graphs . jsp , including form , and / graph . jsp
* /
2010-11-21 20:46:48 +00:00
public class GraphHelper extends FormHandler {
protected Writer _out ;
2006-03-19 00:23:23 +00:00
private int _periodCount ;
private boolean _showEvents ;
private int _width ;
private int _height ;
private int _refreshDelaySeconds ;
2011-03-18 15:49:58 +00:00
private boolean _persistent ;
2012-02-26 17:34:22 +00:00
private String _stat ;
private int _end ;
2010-01-18 17:39:12 +00:00
private static final String PROP_X = " routerconsole.graphX " ;
private static final String PROP_Y = " routerconsole.graphY " ;
private static final String PROP_REFRESH = " routerconsole.graphRefresh " ;
private static final String PROP_PERIODS = " routerconsole.graphPeriods " ;
private static final String PROP_EVENTS = " routerconsole.graphEvents " ;
2017-01-07 18:28:55 +00:00
public static final int DEFAULT_X = 400 ;
2011-03-17 02:07:08 +00:00
public static final int DEFAULT_Y = 100 ;
2014-07-03 13:08:24 +00:00
private static final int DEFAULT_REFRESH = 5 * 60 ;
2010-01-18 17:39:12 +00:00
private static final int DEFAULT_PERIODS = 60 ;
2010-01-24 02:11:55 +00:00
static final int MAX_X = 2048 ;
static final int MAX_Y = 1024 ;
2012-02-26 17:34:22 +00:00
private static final int MIN_X = 200 ;
private static final int MIN_Y = 60 ;
private static final int MIN_C = 20 ;
private static final int MAX_C = SummaryListener . MAX_ROWS ;
2010-01-24 02:11:55 +00:00
private static final int MIN_REFRESH = 15 ;
2006-03-19 00:23:23 +00:00
2010-01-18 17:39:12 +00:00
/** set the defaults after we have a context */
@Override
public void setContextId ( String contextId ) {
super . setContextId ( contextId ) ;
_width = _context . getProperty ( PROP_X , DEFAULT_X ) ;
_height = _context . getProperty ( PROP_Y , DEFAULT_Y ) ;
_periodCount = _context . getProperty ( PROP_PERIODS , DEFAULT_PERIODS ) ;
_refreshDelaySeconds = _context . getProperty ( PROP_REFRESH , DEFAULT_REFRESH ) ;
2011-03-18 15:49:58 +00:00
_showEvents = _context . getBooleanProperty ( PROP_EVENTS ) ;
2006-03-19 00:23:23 +00:00
}
2011-03-18 15:49:58 +00:00
/ * *
2017-01-27 03:14:34 +00:00
* This must be output in the jsp since * lt ; meta & gt ; must be in the & lt ; head & gt ;
2011-05-23 19:22:33 +00:00
* @since 0 . 8 . 7
2011-03-18 15:49:58 +00:00
* /
public String getRefreshMeta ( ) {
if ( _refreshDelaySeconds < = 8 | |
ConfigRestartBean . getRestartTimeRemaining ( ) < ( 1000 * ( _refreshDelaySeconds + 30 ) ) )
return " " ;
// shorten the refresh by 3 seconds so we beat the iframe
return " <meta http-equiv= \" refresh \" content= \" " + ( _refreshDelaySeconds - 3 ) + " \" > " ;
}
2010-11-21 20:46:48 +00:00
/ * *
* This was a HelperBase but now it ' s a FormHandler
* @since 0 . 8 . 2
* /
public void storeWriter ( Writer out ) { _out = out ; }
2006-03-19 00:23:23 +00:00
public void setPeriodCount ( String str ) {
2012-02-26 17:34:22 +00:00
setC ( str ) ;
2006-03-19 00:23:23 +00:00
}
2011-03-18 15:49:58 +00:00
2012-02-26 17:34:22 +00:00
/** @since 0.9 */
public void setE ( String str ) {
try {
_end = Math . max ( 0 , Integer . parseInt ( str ) ) ;
} catch ( NumberFormatException nfe ) { }
}
/** @since 0.9 shorter parameter */
public void setC ( String str ) {
try {
_periodCount = Math . max ( MIN_C , Math . min ( Integer . parseInt ( str ) , MAX_C ) ) ;
} catch ( NumberFormatException nfe ) { }
}
public void setShowEvents ( String b ) { _showEvents = ! " false " . equals ( b ) ; }
2011-03-18 15:49:58 +00:00
2006-03-19 00:23:23 +00:00
public void setHeight ( String str ) {
2012-02-26 17:34:22 +00:00
setH ( str ) ;
}
/** @since 0.9 shorter parameter */
public void setH ( String str ) {
try {
_height = Math . max ( MIN_Y , Math . min ( Integer . parseInt ( str ) , MAX_Y ) ) ;
} catch ( NumberFormatException nfe ) { }
2006-03-19 00:23:23 +00:00
}
2011-03-18 15:49:58 +00:00
2006-03-19 00:23:23 +00:00
public void setWidth ( String str ) {
2012-02-26 17:34:22 +00:00
setW ( str ) ;
}
/** @since 0.9 shorter parameter */
public void setW ( String str ) {
try {
_width = Math . max ( MIN_X , Math . min ( Integer . parseInt ( str ) , MAX_X ) ) ;
} catch ( NumberFormatException nfe ) { }
2006-03-19 00:23:23 +00:00
}
2011-03-18 15:49:58 +00:00
2006-03-19 00:23:23 +00:00
public void setRefreshDelay ( String str ) {
2010-12-12 22:04:06 +00:00
try {
int rds = Integer . parseInt ( str ) ;
if ( rds > 0 )
_refreshDelaySeconds = Math . max ( rds , MIN_REFRESH ) ;
else
_refreshDelaySeconds = - 1 ;
} catch ( NumberFormatException nfe ) { }
2006-03-19 00:23:23 +00:00
}
2011-03-18 15:49:58 +00:00
2011-05-23 19:22:33 +00:00
/** @since 0.8.7 */
2011-03-18 15:49:58 +00:00
public void setPersistent ( String foo ) { _persistent = true ; }
2012-02-26 17:34:22 +00:00
/ * *
* For single stat page
* @since 0 . 9
* /
public void setStat ( String stat ) {
_stat = stat ;
}
2006-03-19 00:23:23 +00:00
public String getImages ( ) {
2011-05-23 19:22:33 +00:00
if ( StatSummarizer . isDisabled ( ) )
2011-03-22 01:59:52 +00:00
return " " ;
2006-03-19 00:23:23 +00:00
try {
2013-11-21 11:31:50 +00:00
List < SummaryListener > listeners = StatSummarizer . instance ( ) . getListeners ( ) ;
TreeSet < SummaryListener > ordered = new TreeSet < SummaryListener > ( new AlphaComparator ( ) ) ;
2007-07-16 20:47:57 +00:00
ordered . addAll ( listeners ) ;
// go to some trouble to see if we have the data for the combined bw graph
boolean hasTx = false ;
boolean hasRx = false ;
2013-11-28 11:10:57 +00:00
for ( SummaryListener lsnr : ordered ) {
2007-07-16 20:47:57 +00:00
String title = lsnr . getRate ( ) . getRateStat ( ) . getName ( ) ;
if ( title . equals ( " bw.sendRate " ) ) hasTx = true ;
else if ( title . equals ( " bw.recvRate " ) ) hasRx = true ;
}
2008-06-10 13:17:28 +00:00
if ( hasTx & & hasRx & & ! _showEvents ) {
2013-04-13 12:13:55 +00:00
_out . write ( " <a href= \" graph?stat=bw.combined "
+ " &c= " + ( 3 * _periodCount )
+ " &w= " + ( 3 * _width )
+ " &h= " + ( 3 * _height )
2012-02-26 17:34:22 +00:00
+ " \" > " ) ;
2015-09-25 19:55:36 +00:00
String title = _t ( " Combined bandwidth graph " ) ;
2011-03-17 02:07:08 +00:00
_out . write ( " <img class= \" statimage \" "
+ " src= \" viewstat.jsp?stat=bw.combined "
2006-04-10 05:37:28 +00:00
+ " &periodCount= " + _periodCount
+ " &width= " + _width
2011-03-17 02:07:08 +00:00
+ " &height= " + ( _height - 13 )
2010-06-02 18:16:43 +00:00
+ " \" alt= \" " + title + " \" title= \" " + title + " \" ></a> \ n " ) ;
2008-06-10 13:17:28 +00:00
}
2006-04-10 05:37:28 +00:00
2013-11-28 11:10:57 +00:00
for ( SummaryListener lsnr : ordered ) {
2006-03-19 00:23:23 +00:00
Rate r = lsnr . getRate ( ) ;
2010-06-02 18:16:43 +00:00
// e.g. "statname for 60m"
2015-09-25 19:55:36 +00:00
String title = _t ( " {0} for {1} " , r . getRateStat ( ) . getName ( ) , DataHelper . formatDuration2 ( _periodCount * r . getPeriod ( ) ) ) ;
2012-02-26 17:34:22 +00:00
_out . write ( " <a href= \" graph?stat= "
2008-02-13 11:49:24 +00:00
+ r . getRateStat ( ) . getName ( )
2012-02-26 17:34:22 +00:00
+ '.' + r . getPeriod ( )
+ " &c= " + ( 3 * _periodCount )
+ " &w= " + ( 3 * _width )
+ " &h= " + ( 3 * _height )
+ ( _showEvents ? " &showEvents=1 " : " " )
+ " \" > " ) ;
2011-03-17 02:07:08 +00:00
_out . write ( " <img class= \" statimage \" border= \" 0 \" "
+ " src= \" viewstat.jsp?stat= "
2007-07-14 18:44:11 +00:00
+ r . getRateStat ( ) . getName ( )
2006-03-19 00:23:23 +00:00
+ " &showEvents= " + _showEvents
+ " &period= " + r . getPeriod ( )
+ " &periodCount= " + _periodCount
+ " &width= " + _width
+ " &height= " + _height
2009-08-17 20:17:30 +00:00
+ " \" alt= \" " + title
+ " \" title= \" " + title + " \" ></a> \ n " ) ;
2006-03-19 00:23:23 +00:00
}
2011-03-18 00:47:14 +00:00
// FIXME jrobin doesn't support setting the timezone, will have to mod TimeAxis.java
2012-06-08 12:58:50 +00:00
// 0.9.1 - all graphs currently state UTC on them, so this text blurb is unnecessary,
2015-09-25 19:55:36 +00:00
//_out.write("<p><i>" + _t("All times are UTC.") + "</i></p>\n");
2006-03-19 00:23:23 +00:00
} catch ( IOException ioe ) {
ioe . printStackTrace ( ) ;
}
return " " ;
}
2010-01-18 17:39:12 +00:00
2012-02-26 17:34:22 +00:00
/ * *
2013-04-13 12:13:55 +00:00
* For single stat page ;
* stat = " bw.combined " treated specially
*
2012-02-26 17:34:22 +00:00
* @since 0 . 9
* /
public String getSingleStat ( ) {
try {
if ( StatSummarizer . isDisabled ( ) )
return " " ;
if ( _stat = = null ) {
2013-04-13 12:13:55 +00:00
_out . write ( " No stat specified " ) ;
2012-02-26 17:34:22 +00:00
return " " ;
}
2013-04-13 12:13:55 +00:00
long period ;
String name , displayName ;
if ( _stat . equals ( " bw.combined " ) ) {
period = 60000 ;
name = _stat ;
2015-09-25 19:55:36 +00:00
displayName = _t ( " Bandwidth usage " ) ;
2013-04-13 12:13:55 +00:00
} else {
2013-10-28 21:48:02 +00:00
Set < Rate > rates = StatSummarizer . instance ( ) . parseSpecs ( _stat ) ;
2013-04-13 12:13:55 +00:00
if ( rates . size ( ) ! = 1 ) {
_out . write ( " Graphs not enabled for " + _stat ) ;
return " " ;
}
2013-10-28 21:48:02 +00:00
Rate r = rates . iterator ( ) . next ( ) ;
2013-04-13 12:13:55 +00:00
period = r . getPeriod ( ) ;
name = r . getRateStat ( ) . getName ( ) ;
displayName = name ;
2012-02-26 17:34:22 +00:00
}
2016-04-18 04:12:15 +00:00
_out . write ( " <h3 id= \" graphinfo \" > " ) ;
2015-09-25 19:55:36 +00:00
_out . write ( _t ( " {0} for {1} " , displayName , DataHelper . formatDuration2 ( _periodCount * period ) ) ) ;
2012-02-26 17:34:22 +00:00
if ( _end > 0 )
2015-09-25 19:55:36 +00:00
_out . write ( ' ' + _t ( " ending {0} ago " , DataHelper . formatDuration2 ( _end * period ) ) ) ;
2012-02-26 17:34:22 +00:00
2016-05-30 04:56:20 +00:00
_out . write ( " <a href= \" graphs \" >[ " + _t ( " Return to main graphs page " ) + " ]</a></h3> \ n "
+ " <div class= \" graphspanel \" ><img class= \" statimage \" border= \" 0 \" "
2012-02-26 17:34:22 +00:00
+ " src= \" viewstat.jsp?stat= "
2013-04-13 12:13:55 +00:00
+ name
2012-02-26 17:34:22 +00:00
+ " &showEvents= " + _showEvents
2013-04-13 12:13:55 +00:00
+ " &period= " + period
2012-02-26 17:34:22 +00:00
+ " &periodCount= " + _periodCount
+ " &end= " + _end
+ " &width= " + _width
+ " &height= " + _height
2016-04-18 04:12:15 +00:00
+ " \" ></div><p id= \" graphopts \" > \ n " ) ;
2012-02-26 17:34:22 +00:00
if ( _width < MAX_X & & _height < MAX_Y ) {
_out . write ( link ( _stat , _showEvents , _periodCount , _end , _width * 3 / 2 , _height * 3 / 2 ) ) ;
2015-09-25 19:55:36 +00:00
_out . write ( _t ( " Larger " ) ) ;
2012-02-26 17:34:22 +00:00
_out . write ( " </a> - " ) ;
}
if ( _width > MIN_X & & _height > MIN_Y ) {
_out . write ( link ( _stat , _showEvents , _periodCount , _end , _width * 2 / 3 , _height * 2 / 3 ) ) ;
2015-09-25 19:55:36 +00:00
_out . write ( _t ( " Smaller " ) ) ;
2012-02-26 17:34:22 +00:00
_out . write ( " </a> - " ) ;
}
if ( _height < MAX_Y ) {
_out . write ( link ( _stat , _showEvents , _periodCount , _end , _width , _height * 3 / 2 ) ) ;
2015-09-25 19:55:36 +00:00
_out . write ( _t ( " Taller " ) ) ;
2012-02-26 17:34:22 +00:00
_out . write ( " </a> - " ) ;
}
if ( _height > MIN_Y ) {
_out . write ( link ( _stat , _showEvents , _periodCount , _end , _width , _height * 2 / 3 ) ) ;
2015-09-25 19:55:36 +00:00
_out . write ( _t ( " Shorter " ) ) ;
2012-02-26 17:34:22 +00:00
_out . write ( " </a> - " ) ;
}
if ( _width < MAX_X ) {
_out . write ( link ( _stat , _showEvents , _periodCount , _end , _width * 3 / 2 , _height ) ) ;
2015-09-25 19:55:36 +00:00
_out . write ( _t ( " Wider " ) ) ;
2012-02-26 17:34:22 +00:00
_out . write ( " </a> - " ) ;
}
if ( _width > MIN_X ) {
_out . write ( link ( _stat , _showEvents , _periodCount , _end , _width * 2 / 3 , _height ) ) ;
2015-09-25 19:55:36 +00:00
_out . write ( _t ( " Narrower " ) ) ;
2012-02-26 17:34:22 +00:00
_out . write ( " </a> " ) ;
}
_out . write ( " <br> " ) ;
if ( _periodCount < MAX_C ) {
_out . write ( link ( _stat , _showEvents , _periodCount * 2 , _end , _width , _height ) ) ;
2015-09-25 19:55:36 +00:00
_out . write ( _t ( " Larger interval " ) ) ;
2012-02-26 17:34:22 +00:00
_out . write ( " </a> - " ) ;
}
if ( _periodCount > MIN_C ) {
_out . write ( link ( _stat , _showEvents , _periodCount / 2 , _end , _width , _height ) ) ;
2015-09-25 19:55:36 +00:00
_out . write ( _t ( " Smaller interval " ) ) ;
2012-02-26 17:34:22 +00:00
_out . write ( " </a> " ) ;
}
_out . write ( " <br> " ) ;
if ( _periodCount < MAX_C ) {
_out . write ( link ( _stat , _showEvents , _periodCount , _end + _periodCount , _width , _height ) ) ;
2015-09-25 19:55:36 +00:00
_out . write ( _t ( " Previous interval " ) ) ;
2012-02-26 17:34:22 +00:00
_out . write ( " </a> " ) ;
}
if ( _end > 0 ) {
int end = _end - _periodCount ;
if ( end < = 0 )
end = 0 ;
if ( _periodCount < MAX_C )
_out . write ( " - " ) ;
_out . write ( link ( _stat , _showEvents , _periodCount , end , _width , _height ) ) ;
2015-09-25 19:55:36 +00:00
_out . write ( _t ( " Next interval " ) ) ;
2012-02-26 17:34:22 +00:00
_out . write ( " </a> " ) ;
}
_out . write ( " <br> " ) ;
_out . write ( link ( _stat , ! _showEvents , _periodCount , _end , _width , _height ) ) ;
2013-04-13 12:13:55 +00:00
if ( ! _stat . equals ( " bw.combined " ) )
2015-09-25 19:55:36 +00:00
_out . write ( _showEvents ? _t ( " Plot averages " ) : _t ( " plot events " ) ) ;
2012-02-26 17:34:22 +00:00
_out . write ( " </a> " ) ;
2015-09-25 19:55:36 +00:00
_out . write ( " </p><p><i> " + _t ( " All times are UTC. " ) + " </i></p> \ n " ) ;
2012-02-26 17:34:22 +00:00
} catch ( IOException ioe ) {
ioe . printStackTrace ( ) ;
}
return " " ;
}
/** @since 0.9 */
private static String link ( String stat , boolean showEvents ,
int periodCount , int end ,
int width , int height ) {
return
" <a href= \" graph?stat= "
+ stat
+ " &c= " + periodCount
+ " &w= " + width
+ " &h= " + height
+ ( end > 0 ? " &e= " + end : " " )
+ ( showEvents ? " &showEvents=1 " : " " )
+ " \" > " ;
}
2017-01-07 18:28:55 +00:00
private static final int [ ] times = { 15 , 30 , 60 , 2 * 60 , 5 * 60 , 10 * 60 , 30 * 60 , 60 * 60 , - 1 } ;
2010-12-12 22:04:06 +00:00
2006-03-19 00:23:23 +00:00
public String getForm ( ) {
2011-05-23 19:22:33 +00:00
if ( StatSummarizer . isDisabled ( ) )
2011-03-22 01:59:52 +00:00
return " " ;
2013-03-03 20:32:02 +00:00
// too hard to use the standard formhandler.jsi / FormHandler.java session nonces
// since graphs.jsp needs the refresh value in its <head>.
// So just use the "shared/console nonce".
String nonce = CSSHelper . getNonce ( ) ;
2006-03-19 00:23:23 +00:00
try {
2016-05-23 11:02:10 +00:00
_out . write ( " <br><h3 id= \" graphdisplay \" > " + _t ( " Configure Graph Display " ) + " <a href= \" configstats \" >[ " + _t ( " Select Stats " ) + " ]</a></h3> " ) ;
2010-11-21 20:46:48 +00:00
_out . write ( " <form action= \" graphs \" method= \" POST \" > \ n " +
2017-01-07 18:28:55 +00:00
" <table><tr><td><input type= \" hidden \" name= \" action \" value= \" save \" > \ n " +
2010-11-21 20:46:48 +00:00
" <input type= \" hidden \" name= \" nonce \" value= \" " + nonce + " \" > \ n " ) ;
2017-01-07 18:28:55 +00:00
_out . write ( _t ( " Display period " ) + " :</td><td colspan= \" 2 \" ><input size= \" 5 \" style= \" text-align: right; \" type= \" text \" name= \" periodCount \" value= \" " + _periodCount + " \" > " + _t ( " minutes " ) + " </td></tr><tr><td> \ n " ) ;
_out . write ( _t ( " Plot type " ) + " :</td><td colspan= \" 2 \" > " ) ;
2017-05-14 05:30:13 +00:00
_out . write ( " <label><input type= \" radio \" class= \" optbox \" name= \" showEvents \" value= \" false \" " + ( _showEvents ? " " : HelperBase . CHECKED ) + " > " + _t ( " Averages " ) + " </label> " ) ;
_out . write ( " <label><input type= \" radio \" class= \" optbox \" name= \" showEvents \" value= \" true \" " + ( _showEvents ? HelperBase . CHECKED : " " ) + " > " + _t ( " Events " ) + " </label></td></tr><tr><td> \ n " ) ;
2017-01-07 18:28:55 +00:00
_out . write ( _t ( " Graph size " ) + " :</td><td><input size= \" 4 \" style= \" text-align: right; \" type= \" text \" name= \" width \" value= \" " + _width
+ " \" > " + _t ( " pixels wide " ) + " <input size= \" 4 \" style= \" text-align: right; \" type= \" text \" name= \" height \" value= \" " + _height
+ " \" > " + _t ( " pixels high " ) + " </td><td class= \" infohelp \" > " + _t ( " Note: Dimensions are for graph only (excludes title, labels and legend). " ) + " </td></tr><tr><td> \ n " ) ;
_out . write ( _t ( " Refresh delay " ) + " :</td><td colspan= \" 2 \" ><select name= \" refreshDelay \" > " ) ;
2010-12-12 22:04:06 +00:00
for ( int i = 0 ; i < times . length ; i + + ) {
_out . write ( " <option value= \" " ) ;
_out . write ( Integer . toString ( times [ i ] ) ) ;
_out . write ( " \" " ) ;
if ( times [ i ] = = _refreshDelaySeconds )
2012-03-02 18:46:34 +00:00
_out . write ( " selected= \" selected \" " ) ;
2010-12-12 22:04:06 +00:00
_out . write ( " > " ) ;
if ( times [ i ] > 0 )
_out . write ( DataHelper . formatDuration2 ( times [ i ] * 1000 ) ) ;
else
2015-09-25 19:55:36 +00:00
_out . write ( _t ( " Never " ) ) ;
2010-12-12 22:04:06 +00:00
_out . write ( " </option> \ n " ) ;
}
2017-01-07 18:28:55 +00:00
_out . write ( " </select></td></tr><tr><td> \ n " + _t ( " Persistence " ) +
2017-05-14 05:30:13 +00:00
" :</td><td colspan= \" 2 \" ><label><input type= \" checkbox \" class= \" optbox \" value= \" true \" name= \" persistent \" " ) ;
2011-03-18 15:49:58 +00:00
boolean persistent = _context . getBooleanPropertyDefaultTrue ( SummaryListener . PROP_PERSISTENT ) ;
if ( persistent )
2015-12-18 14:43:31 +00:00
_out . write ( HelperBase . CHECKED ) ;
2017-05-14 05:30:13 +00:00
_out . write ( " > " + _t ( " Store graph data on disk " ) + " </label></td></tr></table> " +
2016-04-18 04:12:15 +00:00
" <hr><div class= \" formaction \" id= \" graphing \" ><input type= \" submit \" class= \" accept \" value= \" " + _t ( " Save settings and redraw graphs " ) + " \" ></div></form> " ) ;
2006-03-19 00:23:23 +00:00
} catch ( IOException ioe ) {
ioe . printStackTrace ( ) ;
}
return " " ;
}
2006-04-19 17:46:51 +00:00
2011-03-22 01:59:52 +00:00
/ * *
* We have to do this here because processForm ( ) isn ' t called unless the nonces are good
2011-05-23 19:22:33 +00:00
* @since 0 . 8 . 7
2011-03-22 01:59:52 +00:00
* /
@Override
public String getAllMessages ( ) {
2011-05-23 19:22:33 +00:00
if ( StatSummarizer . isDisabled ( ) ) {
2011-03-22 01:59:52 +00:00
addFormError ( " Graphing not supported with this JVM: " +
System . getProperty ( " java.vendor " ) + ' ' +
System . getProperty ( " java.version " ) + " ( " +
System . getProperty ( " java.runtime.name " ) + ' ' +
System . getProperty ( " java.runtime.version " ) + ')' ) ;
if ( _context . getProperty ( PROP_REFRESH , 0 ) > = 0 ) {
// force no refresh, save silently
2012-01-18 01:54:34 +00:00
_context . router ( ) . saveConfig ( PROP_REFRESH , " -1 " ) ;
2011-03-22 01:59:52 +00:00
}
}
return super . getAllMessages ( ) ;
}
2010-11-21 20:46:48 +00:00
/ * *
* This was a HelperBase but now it ' s a FormHandler
* @since 0 . 8 . 2
* /
@Override
protected void processForm ( ) {
2014-02-10 14:22:43 +00:00
if ( " save " . equals ( _action ) )
saveSettings ( ) ;
2010-11-21 20:46:48 +00:00
}
2010-01-18 17:39:12 +00:00
/ * *
* Silently save settings if changed , no indication of success or failure
* @since 0 . 7 . 10
* /
private void saveSettings ( ) {
if ( _width ! = _context . getProperty ( PROP_X , DEFAULT_X ) | |
_height ! = _context . getProperty ( PROP_Y , DEFAULT_Y ) | |
_periodCount ! = _context . getProperty ( PROP_PERIODS , DEFAULT_PERIODS ) | |
_refreshDelaySeconds ! = _context . getProperty ( PROP_REFRESH , DEFAULT_REFRESH ) | |
2011-03-18 15:49:58 +00:00
_showEvents ! = _context . getBooleanProperty ( PROP_EVENTS ) | |
_persistent ! = _context . getBooleanPropertyDefaultTrue ( SummaryListener . PROP_PERSISTENT ) ) {
2013-11-21 11:31:50 +00:00
Map < String , String > changes = new HashMap < String , String > ( ) ;
2012-01-18 01:54:34 +00:00
changes . put ( PROP_X , " " + _width ) ;
changes . put ( PROP_Y , " " + _height ) ;
changes . put ( PROP_PERIODS , " " + _periodCount ) ;
changes . put ( PROP_REFRESH , " " + _refreshDelaySeconds ) ;
changes . put ( PROP_EVENTS , " " + _showEvents ) ;
changes . put ( SummaryListener . PROP_PERSISTENT , " " + _persistent ) ;
_context . router ( ) . saveConfig ( changes , null ) ;
2015-09-25 19:55:36 +00:00
addFormNotice ( _t ( " Graph settings saved " ) ) ;
2010-01-18 17:39:12 +00:00
}
}
2014-06-15 16:14:13 +00:00
private static class AlphaComparator implements Comparator < SummaryListener > , Serializable {
2011-03-18 15:49:58 +00:00
public int compare ( SummaryListener l , SummaryListener r ) {
String lName = l . getRate ( ) . getRateStat ( ) . getName ( ) ;
String rName = r . getRate ( ) . getRateStat ( ) . getName ( ) ;
int rv = lName . compareTo ( rName ) ;
if ( rv ! = 0 )
return rv ;
return ( int ) ( l . getRate ( ) . getPeriod ( ) - r . getRate ( ) . getPeriod ( ) ) ;
}
2006-04-19 17:46:51 +00:00
}
2007-07-14 18:44:11 +00:00
}