Changeset 3f91e44


Ignore:
Timestamp:
Nov 4, 2015 9:41:33 PM (5 years ago)
Author:
zab2 <zab2@…>
Branches:
master
Children:
9baeedb
Parents:
b10b8581
Message:

Add serialization methods to StatManager?, FrequencyStat? and Frequency
for easier collection

Location:
core/java/src/net/i2p/stat
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/stat/Frequency.java

    rb10b8581 r3f91e44  
    151151        return System.currentTimeMillis();
    152152    }
     153   
     154    /**
     155     * Appends the data of this frequency to the specified StringBuilder
     156     * @param dest to append data to
     157     * @since 0.9.23
     158     */
     159    synchronized void store(StringBuilder dest) {
     160        dest.append("avgInterval:").append(_avgInterval).append(',');
     161        dest.append("minAverageInterval").append(_minAverageInterval).append(',');
     162        dest.append("lastEvent").append(_lastEvent).append(",");
     163        dest.append("count").append(_count);
     164    }
    153165}
  • core/java/src/net/i2p/stat/FrequencyStat.java

    rb10b8581 r3f91e44  
    11package net.i2p.stat;
     2
     3import java.io.IOException;
     4import java.io.OutputStream;
     5
     6import net.i2p.data.DataHelper;
    27
    38/** coordinate an event frequency over various periods */
     
    9398        return _statName.equals(((FrequencyStat)obj)._statName);
    9499    }
     100   
     101    private final static String NL = System.getProperty("line.separator");
     102   
     103    /**
     104     * Serializes this FrequencyStat to the provided OutputStream
     105     * @param out to write to
     106     * @param prefix to prepend to the stat
     107     * @throws IOException if something goes wrong
     108     * @since 0.9.23
     109     */
     110    public void store(OutputStream out, String prefix) throws IOException {
     111        StringBuilder buf = new StringBuilder(1024);
     112        buf.append(NL);
     113        buf.append("################################################################################").append(NL);
     114        buf.append("# Frequency: ").append(_groupName).append(": ").append(_statName).append(NL);
     115        buf.append("# ").append(_description).append(NL);
     116        buf.append("# ").append(NL).append(NL);
     117        out.write(buf.toString().getBytes("UTF-8"));
     118        buf.setLength(0);
     119        for (Frequency r: _frequencies){
     120            buf.append("#######").append(NL);
     121            buf.append("# Period : ").append(DataHelper.formatDuration(r.getPeriod())).append(" for rate ")
     122                .append(_groupName).append(" - ").append(_statName).append(NL);
     123            buf.append(NL);
     124            r.store(buf);
     125            out.write(buf.toString().getBytes("UTF-8"));
     126            buf.setLength(0);
     127        }
     128    }
    95129
    96130}
  • core/java/src/net/i2p/stat/StatManager.java

    rb10b8581 r3f91e44  
    11package net.i2p.stat;
    22
     3import java.io.IOException;
     4import java.io.OutputStream;
    35import java.text.Collator;
    46import java.util.HashMap;
     
    248250        return _context.isRouterContext() && !_context.getBooleanProperty(PROP_STAT_FULL);
    249251    }
     252   
     253    /**
     254     * Serializes all Frequencies and Rates to the provided OutputStream
     255     * @param out to write to
     256     * @param prefix to use when serializing
     257     * @throws IOException if something goes wrong
     258     * @since 0.9.23
     259     */
     260    public void store(OutputStream out, String prefix) throws IOException {
     261        for (FrequencyStat fs : _frequencyStats.values())
     262            fs.store(out, prefix);
     263        for (RateStat rs : _rateStats.values())
     264            rs.store(out,prefix);
     265    }
    250266}
Note: See TracChangeset for help on using the changeset viewer.