Enum Class TorrentStats.SeriesMetric

java.lang.Object
java.lang.Enum<TorrentStats.SeriesMetric>
com.frostwire.jlibtorrent.TorrentStats.SeriesMetric
All Implemented Interfaces:
Serializable, Comparable<TorrentStats.SeriesMetric>, Constable
Enclosing class:
TorrentStats

public static enum TorrentStats.SeriesMetric extends Enum<TorrentStats.SeriesMetric>
Time-series metrics available in TorrentStats.

SeriesMetric identifies which time-series data to retrieve from a TorrentStats instance. Each metric maintains a rolling window of samples collected at regular intervals (approximately every second).

Available Metrics:

  • TIME: Timestamps of each sample (seconds since epoch)
  • DOWNLOAD_RATE: Instantaneous download speed in bytes/second
  • UPLOAD_RATE: Instantaneous upload speed in bytes/second

Accessing Time Series Data:

 TorrentStats stats = ...; // From SessionManager or TorrentHandle

 // Get the download rate series (sliding window of samples)
 IntSeries downloadRates = stats.series(TorrentStats.SeriesMetric.DOWNLOAD_RATE);

 // Get most recent sample
 long latestDownloadRate = downloadRates.last();
 System.out.println(\"Current speed: \" + latestDownloadRate + \" B/s\");

 // Get all samples in the window
 for (int i = 0; i < downloadRates.size(); i++) {
     long rate = downloadRates.get(i);
     System.out.println(\"Sample \" + i + \": \" + rate + \" B/s\");
 }
 

Calculating Statistics from Series:

 IntSeries uploadRates = stats.series(TorrentStats.SeriesMetric.UPLOAD_RATE);

 // Calculate average speed over time window
 long total = 0;
 for (int i = 0; i < uploadRates.size(); i++) {
     total += uploadRates.get(i);
 }
 long avgSpeed = uploadRates.size() > 0 ? total / uploadRates.size() : 0;
 System.out.println(\"Average upload speed: \" + avgSpeed + \" B/s\");

 // Get maximum and minimum speeds
 long maxSpeed = 0, minSpeed = Long.MAX_VALUE;
 for (int i = 0; i < uploadRates.size(); i++) {
     long rate = uploadRates.get(i);
     maxSpeed = Math.max(maxSpeed, rate);
     minSpeed = Math.min(minSpeed, rate);
 }
 System.out.println(\"Max upload: \" + maxSpeed + \" B/s\");
 System.out.println(\"Min upload: \" + (minSpeed == Long.MAX_VALUE ? 0 : minSpeed) + \" B/s\");
 

Time Series Window:

The series maintains a fixed-size circular buffer (typically 60 samples). Once the buffer fills, new samples overwrite the oldest data. The actual time span depends on the sampling interval and buffer size.

Using TIME Metric:

 // Correlate speed samples with timestamps
 IntSeries times = stats.series(TorrentStats.SeriesMetric.TIME);
 IntSeries downloadRates = stats.series(TorrentStats.SeriesMetric.DOWNLOAD_RATE);

 for (int i = 0; i < times.size(); i++) {
     long timestamp = times.get(i);
     long speed = downloadRates.get(i);
     System.out.println(\"At \" + new Date(timestamp * 1000) + \": \" + speed + \" B/s\");
 }
 

Performance Notes:

  • Series data is sampled approximately once per second
  • Buffer size is fixed; new samples overwrite oldest data
  • Access is O(1) for random and sequential access
  • No synchronization; read from same thread as sampling thread if possible
  • Enum Constant Details

    • TIME

      public static final TorrentStats.SeriesMetric TIME
      Timestamp series - when each sample was collected (UNIX time in seconds).
    • DOWNLOAD_RATE

      public static final TorrentStats.SeriesMetric DOWNLOAD_RATE
      Download rate series - instantaneous download speed in bytes per second. This is total downloaded data, including protocol overhead.
    • UPLOAD_RATE

      public static final TorrentStats.SeriesMetric UPLOAD_RATE
      Upload rate series - instantaneous upload speed in bytes per second. This is total uploaded data, including protocol overhead.
  • Method Details

    • values

      public static TorrentStats.SeriesMetric[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static TorrentStats.SeriesMetric valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null