Changeset cf0d219


Ignore:
Timestamp:
Mar 18, 2011 3:49:58 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
ddddc68
Parents:
79358f4
Message:
  • Persistent option on GUI
  • Fix HTML errors
  • Refresh improvements
  • Fix Rate.equals() bug
  • More cleanups
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/GraphHelper.java

    r79358f4 rcf0d219  
    1818    private int _height;
    1919    private int _refreshDelaySeconds;
     20    private boolean _persistent;
    2021
    2122    private static final String PROP_X = "routerconsole.graphX";
     
    4041        _periodCount = _context.getProperty(PROP_PERIODS, DEFAULT_PERIODS);
    4142        _refreshDelaySeconds = _context.getProperty(PROP_REFRESH, DEFAULT_REFRESH);
    42         _showEvents = Boolean.valueOf(_context.getProperty(PROP_EVENTS)).booleanValue();
     43        _showEvents = _context.getBooleanProperty(PROP_EVENTS);
    4344    }
    4445   
     46    /**
     47     *  This must be output in the jsp since <meta> must be in the <head>
     48     *  @since 0.8.6
     49     */
     50    public String getRefreshMeta() {
     51        if (_refreshDelaySeconds <= 8 ||
     52            ConfigRestartBean.getRestartTimeRemaining() < (1000 * (_refreshDelaySeconds + 30)))
     53            return "";
     54        // shorten the refresh by 3 seconds so we beat the iframe
     55        return "<meta http-equiv=\"refresh\" content=\"" + (_refreshDelaySeconds - 3) + "\">";
     56    }
     57
    4558    /**
    4659     *  This was a HelperBase but now it's a FormHandler
     
    5265        try { _periodCount = Integer.parseInt(str); } catch (NumberFormatException nfe) {}
    5366    }
     67
    5468    public void setShowEvents(boolean b) { _showEvents = b; }
     69
    5570    public void setHeight(String str) {
    5671        try { _height = Math.min(Integer.parseInt(str), MAX_Y); } catch (NumberFormatException nfe) {}
    5772    }
     73
    5874    public void setWidth(String str) {
    5975        try { _width = Math.min(Integer.parseInt(str), MAX_X); } catch (NumberFormatException nfe) {}
    6076    }
     77
    6178    public void setRefreshDelay(String str) {
    6279        try {
     
    6885        } catch (NumberFormatException nfe) {}
    6986    }
     87
     88    /** @since 0.8.6 */
     89    public void setPersistent(String foo) { _persistent = true; }
    7090   
    7191    public String getImages() {
     
    124144                           + "\" title=\"" + title + "\"></a>\n");
    125145            }
    126             // FIXME <meta> not allowed inside <div>, move to the .jsp
    127             if (_refreshDelaySeconds > 0)
    128                 // shorten the refresh by 3 seconds so we beat the iframe
    129                 _out.write("<meta http-equiv=\"refresh\" content=\"" + (_refreshDelaySeconds - 3) + "\">\n");
    130146
    131147            // FIXME jrobin doesn't support setting the timezone, will have to mod TimeAxis.java
    132             _out.write("<p<i>" + _("All times are UTC.") + "</i></p>\n");
     148            _out.write("<p><i>" + _("All times are UTC.") + "</i></p>\n");
    133149        } catch (IOException ioe) {
    134150            ioe.printStackTrace();
     
    149165                       "<input type=\"hidden\" name=\"action\" value=\"foo\">\n" +
    150166                       "<input type=\"hidden\" name=\"nonce\" value=\"" + nonce + "\" >\n");
    151             _out.write(_("Periods") + ": <input size=\"3\" type=\"text\" name=\"periodCount\" value=\"" + _periodCount + "\"><br>\n");
     167            _out.write(_("Periods") + ": <input size=\"5\" style=\"text-align: right;\" type=\"text\" name=\"periodCount\" value=\"" + _periodCount + "\"><br>\n");
    152168            _out.write(_("Plot averages") + ": <input type=\"radio\" class=\"optbox\" name=\"showEvents\" value=\"false\" " + (_showEvents ? "" : "checked=\"true\" ") + "> ");
    153169            _out.write(_("or")+ " " +_("plot events") + ": <input type=\"radio\" class=\"optbox\" name=\"showEvents\" value=\"true\" "+ (_showEvents ? "checked=\"true\" " : "") + "><br>\n");
    154             _out.write(_("Image sizes") + ": " + _("width") + ": <input size=\"4\" type=\"text\" name=\"width\" value=\"" + _width
    155                        + "\"> " + _("pixels") + ", " + _("height") + ": <input size=\"4\" type=\"text\" name=\"height\" value=\"" + _height 
     170            _out.write(_("Image sizes") + ": " + _("width") + ": <input size=\"4\" style=\"text-align: right;\" type=\"text\" name=\"width\" value=\"" + _width
     171                       + "\"> " + _("pixels") + ", " + _("height") + ": <input size=\"4\" style=\"text-align: right;\" type=\"text\" name=\"height\" value=\"" + _height 
    156172                       + "\"> " + _("pixels") + "<br>\n");
    157173            _out.write(_("Refresh delay") + ": <select name=\"refreshDelay\">");
     
    170186            }
    171187            _out.write("</select><br>\n" +
    172                        "<hr><div class=\"formaction\"><input type=\"submit\" value=\"" + _("Redraw") + "\"></div></form>");
     188                       _("Store graph data on disk?") +
     189                       " <input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"persistent\"");
     190            boolean persistent = _context.getBooleanPropertyDefaultTrue(SummaryListener.PROP_PERSISTENT);
     191            if (persistent)
     192                _out.write(" checked=\"true\"");
     193            _out.write(">" +
     194                       "<hr><div class=\"formaction\"><input type=\"submit\" value=\"" + _("Save settings and redraw graphs") + "\"></div></form>");
    173195        } catch (IOException ioe) {
    174196            ioe.printStackTrace();
     
    195217            _periodCount != _context.getProperty(PROP_PERIODS, DEFAULT_PERIODS) ||
    196218            _refreshDelaySeconds != _context.getProperty(PROP_REFRESH, DEFAULT_REFRESH) ||
    197             _showEvents != Boolean.valueOf(_context.getProperty(PROP_EVENTS)).booleanValue()) {
     219            _showEvents != _context.getBooleanProperty(PROP_EVENTS) ||
     220            _persistent != _context.getBooleanPropertyDefaultTrue(SummaryListener.PROP_PERSISTENT)) {
    198221            _context.router().setConfigSetting(PROP_X, "" + _width);
    199222            _context.router().setConfigSetting(PROP_Y, "" + _height);
     
    201224            _context.router().setConfigSetting(PROP_REFRESH, "" + _refreshDelaySeconds);
    202225            _context.router().setConfigSetting(PROP_EVENTS, "" + _showEvents);
     226            _context.router().setConfigSetting(SummaryListener.PROP_PERSISTENT, "" + _persistent);
    203227            _context.router().saveConfig();
    204228            addFormNotice(_("Graph settings saved"));
     
    206230    }
    207231
    208 /** inner class, don't bother reindenting */
    209 private static class AlphaComparator implements Comparator {
    210     public int compare(Object lhs, Object rhs) {
    211         SummaryListener l = (SummaryListener)lhs;
    212         SummaryListener r = (SummaryListener)rhs;
    213         String lName = l.getRate().getRateStat().getName() + "." + l.getRate().getPeriod();
    214         String rName = r.getRate().getRateStat().getName() + "." + r.getRate().getPeriod();
    215         return lName.compareTo(rName);
     232    private static class AlphaComparator implements Comparator<SummaryListener> {
     233        public int compare(SummaryListener l, SummaryListener r) {
     234            String lName = l.getRate().getRateStat().getName();
     235            String rName = r.getRate().getRateStat().getName();
     236            int rv = lName.compareTo(rName);
     237            if (rv != 0)
     238                return rv;
     239            return (int) (l.getRate().getPeriod() - r.getRate().getPeriod());
     240        }
    216241    }
    217242}
    218 
    219 }
  • apps/routerconsole/java/src/net/i2p/router/web/StatSummarizer.java

    r79358f4 rcf0d219  
    44import java.awt.Graphics;
    55import java.awt.image.BufferedImage;
     6import java.io.File;
    67import java.io.IOException;
    78import java.io.OutputStream;
     
    1920import net.i2p.stat.Rate;
    2021import net.i2p.stat.RateStat;
     22import net.i2p.util.FileUtil;
    2123import net.i2p.util.Log;
    2224
     
    6163   
    6264    public void run() {
     65        boolean isPersistent = _context.getBooleanPropertyDefaultTrue(SummaryListener.PROP_PERSISTENT);
     66        if (!isPersistent)
     67            deleteOldRRDs();
    6368        _thread = Thread.currentThread();
    6469        String specs = "";
     
    127132   
    128133    private void removeDb(Rate r) {
    129         for (int i = 0; i < _listeners.size(); i++) {
    130             SummaryListener lsnr = _listeners.get(i);
     134        for (SummaryListener lsnr : _listeners) {
    131135            if (lsnr.getRate().equals(r)) {
    132                 _listeners.remove(i);
     136                // no iter.remove() in COWAL
     137                _listeners.remove(lsnr);
    133138                lsnr.stopListening();
    134139                return;
     
    179184        else if (height <= 0)
    180185            height = GraphHelper.DEFAULT_Y;
    181         for (int i = 0; i < _listeners.size(); i++) {
    182             SummaryListener lsnr = _listeners.get(i);
     186        for (SummaryListener lsnr : _listeners) {
    183187            if (lsnr.getRate().equals(rate)) {
    184188                lsnr.renderPng(out, width, height, hideLegend, hideGrid, hideTitle, showEvents, periodCount, showCredit);
     
    207211
    208212    private boolean locked_getXML(Rate rate, OutputStream out) throws IOException {
    209         for (int i = 0; i < _listeners.size(); i++) {
    210             SummaryListener lsnr = _listeners.get(i);
     213        for (SummaryListener lsnr : _listeners) {
    211214            if (lsnr.getRate().equals(rate)) {
    212215                lsnr.getData().exportXml(out);
     
    275278            def.setMinValue(0d);
    276279            def.setBase(1024);
    277             // Note to translators: all runtime zh translation disabled in this file, no font available in RRD
    278280            String title = _("Bandwidth usage");
    279281            if (!hideTitle)
     
    366368    }
    367369
     370    /**
     371     *  Delete the old rrd dir if we are no longer persistent
     372     *  @since 0.8.6
     373     */
     374    private void deleteOldRRDs() {
     375        File rrdDir = new File(_context.getRouterDir(), SummaryListener.RRD_DIR);
     376        FileUtil.rmdir(rrdDir, false);
     377    }
     378
    368379    /** translate a string */
    369380    private String _(String s) {
  • apps/routerconsole/java/src/net/i2p/router/web/SummaryListener.java

    r79358f4 rcf0d219  
    3333 */
    3434class SummaryListener implements RateSummaryListener {
    35     private static final String PROP_PERSISTENT = "routerconsole.graphPersistent";
     35    static final String PROP_PERSISTENT = "routerconsole.graphPersistent";
    3636    /** note that .jrb files are NOT compatible with .rrd files */
    37     private static final String RRD_DIR = "rrd";
     37    static final String RRD_DIR = "rrd";
    3838    private static final String RRD_PREFIX = "rrd-";
    3939    private static final String RRD_SUFFIX = ".jrb";
     
    6363        _rate = r;
    6464        _log = _context.logManager().getLog(SummaryListener.class);
    65         _isPersistent = _context.getBooleanProperty(PROP_PERSISTENT);
     65        _isPersistent = _context.getBooleanPropertyDefaultTrue(PROP_PERSISTENT);
    6666    }
    6767   
  • apps/routerconsole/java/src/net/i2p/router/web/SummaryRenderer.java

    r79358f4 rcf0d219  
    102102                String p;
    103103                // we want the formatting and translation of formatDuration2(), except not zh, and not the &nbsp;
    104                 if ("zh".equals(Messages.getLanguage(_context)))
    105                     p = DataHelper.formatDuration(_listener.getRate().getPeriod());
    106                 else
     104                //if ("zh".equals(Messages.getLanguage(_context)))
     105                //    p = DataHelper.formatDuration(_listener.getRate().getPeriod());
     106                //else
    107107                    p = DataHelper.formatDuration2(_listener.getRate().getPeriod()).replace("&nbsp;", " ");
    108108                if (showEvents)
    109                     // Note to translators: all runtime zh translation disabled in this file, no font available in RRD
    110109                    title = name + ' ' + _("events in {0}", p);
    111110                else
     
    134133                def.vrule(started / 1000, Color.BLACK, _("Restart"), 4.0f);
    135134            def.datasource(plotName, path, plotName, SummaryListener.CF, _listener.getBackendName());
    136             def.area(plotName, Color.BLUE, descr + "\\r");
     135            if (descr.length() > 0)
     136                def.area(plotName, Color.BLUE, descr + "\\r");
     137            else
     138                def.area(plotName, Color.BLUE);
    137139            if (!hideLegend) {
    138140                def.gprint(plotName, SummaryListener.CF, _("avg") + ": %.2f %s");
  • apps/routerconsole/jsp/graphs.jsp

    r79358f4 rcf0d219  
    66<%@include file="css.jsi" %>
    77<%=intl.title("graphs")%>
     8 <jsp:useBean class="net.i2p.router.web.GraphHelper" id="graphHelper" scope="request" />
     9 <% graphHelper.storeMethod(request.getMethod()); %>
     10 <jsp:setProperty name="graphHelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
     11<% /* GraphHelper sets the defaults in setContextId, so setting the properties must be after the context */ %>
     12 <jsp:setProperty name="graphHelper" property="*" />
     13<%
     14    graphHelper.storeWriter(out);
     15    graphHelper.storeMethod(request.getMethod());
     16    // meta must be inside the head
     17    boolean allowRefresh = intl.allowIFrame(request.getHeader("User-Agent"));
     18    if (allowRefresh) {
     19        out.print(graphHelper.getRefreshMeta());
     20    }
     21%>
    822</head><body>
    9 
    1023<%@include file="summary.jsi" %>
    1124<h1><%=intl._("I2P Performance Graphs")%></h1>
     
    1326 <div class="graphspanel">
    1427 <div class="widepanel">
    15  <jsp:useBean class="net.i2p.router.web.GraphHelper" id="graphHelper" scope="request" />
    16  <% graphHelper.storeMethod(request.getMethod()); %>
    17  <jsp:setProperty name="graphHelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
    18 <% /* GraphHelper sets the defaults in setContextId, so setting the properties must be after the context */ %>
    19  <jsp:setProperty name="graphHelper" property="*" />
    20  <% graphHelper.storeWriter(out); %>
    2128 <jsp:getProperty name="graphHelper" property="allMessages" />
    2229 <jsp:getProperty name="graphHelper" property="images" />
  • core/java/src/net/i2p/stat/Rate.java

    r79358f4 rcf0d219  
    44import java.util.Properties;
    55
     6import net.i2p.data.DataHelper;
    67import net.i2p.util.Log;
    78
     
    472473    }
    473474
     475    /**
     476     * This is used in StatSummarizer and SummaryListener.
     477     * We base it on the stat we are tracking, not the stored data.
     478     */
    474479    @Override
    475480    public boolean equals(Object obj) {
     
    478483        Rate r = (Rate) obj;
    479484        return _period == r.getPeriod() && _creationDate == r.getCreationDate() &&
    480         //_lastCoalesceDate == r.getLastCoalesceDate() &&
    481                _currentTotalValue == r.getCurrentTotalValue() && _currentEventCount == r.getCurrentEventCount()
    482                && _currentTotalEventTime == r.getCurrentTotalEventTime() && _lastTotalValue == r.getLastTotalValue()
    483                && _lastEventCount == r.getLastEventCount() && _lastTotalEventTime == r.getLastTotalEventTime()
    484                && _extremeTotalValue == r.getExtremeTotalValue() && _extremeEventCount == r.getExtremeEventCount()
    485                && _extremeTotalEventTime == r.getExtremeTotalEventTime()
    486                && _lifetimeTotalValue == r.getLifetimeTotalValue() && _lifetimeEventCount == r.getLifetimeEventCount()
    487                && _lifetimeTotalEventTime == r.getLifetimeTotalEventTime();
     485               // do this the easy way to avoid NPEs.
     486               // Alternative: compare name and group name (very carefully to avoid NPEs)
     487               _stat == r._stat;
    488488    }
    489489
     
    491491     * It doesn't appear that Rates are ever stored in a Set or Map
    492492     * (RateStat stores in an array) so let's make this easy.
    493      * We can always make something faster if it's actually used.
    494493     */
    495494    @Override
    496495    public int hashCode() {
    497 /*****
    498         int hash = 5;
    499         hash = 67 * hash + (int)(Double.doubleToLongBits(this._currentTotalValue) ^ (Double.doubleToLongBits(this._currentTotalValue) >>> 32));
    500         hash = 67 * hash + (int)(this._currentEventCount ^ (this._currentEventCount >>> 32));
    501         hash = 67 * hash + (int)(this._currentTotalEventTime ^ (this._currentTotalEventTime >>> 32));
    502         hash = 67 * hash + (int)(Double.doubleToLongBits(this._lastTotalValue) ^ (Double.doubleToLongBits(this._lastTotalValue) >>> 32));
    503         hash = 67 * hash + (int)(this._lastEventCount ^ (this._lastEventCount >>> 32));
    504         hash = 67 * hash + (int)(this._lastTotalEventTime ^ (this._lastTotalEventTime >>> 32));
    505         hash = 67 * hash + (int)(Double.doubleToLongBits(this._extremeTotalValue) ^ (Double.doubleToLongBits(this._extremeTotalValue) >>> 32));
    506         hash = 67 * hash + (int)(this._extremeEventCount ^ (this._extremeEventCount >>> 32));
    507         hash = 67 * hash + (int)(this._extremeTotalEventTime ^ (this._extremeTotalEventTime >>> 32));
    508         hash = 67 * hash + (int)(Double.doubleToLongBits(this._lifetimeTotalValue) ^ (Double.doubleToLongBits(this._lifetimeTotalValue) >>> 32));
    509         hash = 67 * hash + (int)(this._lifetimeEventCount ^ (this._lifetimeEventCount >>> 32));
    510         hash = 67 * hash + (int)(this._lifetimeTotalEventTime ^ (this._lifetimeTotalEventTime >>> 32));
    511         hash = 67 * hash + (int)(this._creationDate ^ (this._creationDate >>> 32));
    512         hash = 67 * hash + (int)(this._period ^ (this._period >>> 32));
    513         return hash;
    514 ******/
    515         return toString().hashCode();
     496        return DataHelper.hashCode(_stat) ^ ((int)_period) ^ ((int) _creationDate);
    516497    }
    517498
Note: See TracChangeset for help on using the changeset viewer.