Skip to content

Commit

Permalink
Some progress in new performance counters (via alert) of Session.
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml committed Feb 26, 2015
1 parent 8bb8bce commit 5825c16
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 39 deletions.
77 changes: 47 additions & 30 deletions src/com/frostwire/jlibtorrent/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ public final class Session {

private final session s;

private long lastStatusRequestTime;
private SessionStatus lastStatus;

private final SparseArray<ArrayList<AlertListener>> listeners;
private final SparseArray<AlertListener[]> listenerSnapshots;
private boolean running;
Expand Down Expand Up @@ -370,33 +367,6 @@ public boolean isListening() {
return s.is_listening();
}

/**
* Returns session wide-statistics and status.
* <p/>
* It is important not to call this method for each field in the status
* for performance reasons.
*
* @return
*/
public SessionStatus getStatus(boolean force) {
long now = System.currentTimeMillis();
if (force || (now - lastStatusRequestTime) >= REQUEST_STATUS_RESOLUTION_MILLIS) {
lastStatusRequestTime = now;
lastStatus = new SessionStatus(s.status());
}

return lastStatus;
}

/**
* Returns session wide-statistics and status.
*
* @return
*/
public SessionStatus getStatus() {

This comment has been minimized.

Copy link
@gubatron

gubatron Feb 26, 2015

Collaborator

how do you get all the torrent status information now?

This comment has been minimized.

Copy link
@gubatron

gubatron Feb 26, 2015

Collaborator

I was thinking of using getStatus() to show advanced information about the torrent.

This comment has been minimized.

Copy link
@gubatron

gubatron Feb 26, 2015

Collaborator

hmm, this is the session, never mind.

This comment has been minimized.

Copy link
@aldenml

aldenml Feb 26, 2015

Author Collaborator

Good question, working on it now. We need to work with the new metrics API

return this.getStatus(false);
}

/**
* Loads and saves all session settings, including dht_settings,
* encryption settings and proxy settings. ``save_state`` writes all keys
Expand Down Expand Up @@ -446,6 +416,53 @@ public void loadState(byte[] data) {
}
}

/**
* This functions instructs the session to post the state_update_alert,
* containing the status of all torrents whose state changed since the
* last time this function was called.
* <p/>
* Only torrents who has the state subscription flag set will be
* included. This flag is on by default. See add_torrent_params.
* the ``flags`` argument is the same as for torrent_handle::status().
* see torrent_handle::status_flags_t.
*
* @param flags
*/
public void postTorrentUpdates(TorrentHandle.StatusFlags flags) {
s.post_torrent_updates(flags.getSwig());
}

/**
* This functions instructs the session to post the state_update_alert,
* containing the status of all torrents whose state changed since the
* last time this function was called.
* <p/>
* Only torrents who has the state subscription flag set will be
* included.
*/
public void postTorrentUpdates() {
s.post_torrent_updates();
}

/**
* This function will post a session_stats_alert object, containing a
* snapshot of the performance counters from the internals of libtorrent.
* To interpret these counters, query the session via
* session_stats_metrics().
* <p/>
* For more information, see the session-statistics_ section.
*/
public void postSessionStats() {
s.post_session_stats();
}

/**
* This will cause a dht_stats_alert to be posted.
*/
public void postDHTStats() {
s.post_dht_stats();
}

/**
* Looks for a torrent with the given info-hash. In
* case there is such a torrent in the session, a torrent_handle to that
Expand Down
81 changes: 72 additions & 9 deletions src/com/frostwire/jlibtorrent/TorrentHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -1036,21 +1036,58 @@ public String getName() {
}

/**
* flags to be passed in {} file_progress().
* Flags to pass in to status() to specify which properties of the
* torrent to query for. By default all flags are set.
*/
public enum FileProgressFlags {
public enum StatusFlags {

DEFAULT(0),
/**
* calculates ``distributed_copies``, ``distributed_full_copies`` and
* ``distributed_fraction``.
*/
QUERY_DISTRIBUTED_COPIES(status_flags_t.query_distributed_copies.swigValue()),

/**
* only calculate file progress at piece granularity. This makes
* the file_progress() call cheaper and also only takes bytes that
* have passed the hash check into account, so progress cannot
* regress in this mode.
* includes partial downloaded blocks in ``total_done`` and
* ``total_wanted_done``.
*/
PIECE_GRANULARITY(torrent_handle.file_progress_flags_t.piece_granularity.swigValue());
QUERY_ACCURATE_DOWNLOAD_COUNTERS(status_flags_t.query_accurate_download_counters.swigValue()),

private FileProgressFlags(int swigValue) {
/**
* includes ``last_seen_complete``.
*/
QUERY_LAST_SEEN_COMPLETE(status_flags_t.query_last_seen_complete.swigValue()),

/**
* includes ``pieces``.
*/
QUERY_PIECES(status_flags_t.query_pieces.swigValue()),

/**
* includes ``verified_pieces`` (only applies to torrents in *seed mode*).
*/
QUERY_VERIFIED_PIECES(status_flags_t.query_verified_pieces.swigValue()),

/**
* includes ``torrent_file``, which is all the static information from the .torrent file.
*/
QUERY_TORRENT_FILE(status_flags_t.query_torrent_file.swigValue()),

/**
* includes ``name``, the name of the torrent. This is either derived
* from the .torrent file, or from the ``&dn=`` magnet link argument
* or possibly some other source. If the name of the torrent is not
* known, this is an empty string.
*/
QUERY_NAME(status_flags_t.query_name.swigValue()),

/**
* includes ``save_path``, the path to the directory the files of the
* torrent are saved to.
*/
QUERY_SAVE_PATH(status_flags_t.query_save_path.swigValue());

private StatusFlags(int swigValue) {
this.swigValue = swigValue;
}

Expand Down Expand Up @@ -1078,4 +1115,30 @@ public int getSwig() {
return swigValue;
}
}

/**
* Flags to be passed in {@link #getFileProgress(com.frostwire.jlibtorrent.TorrentHandle.FileProgressFlags)}.
*/
public enum FileProgressFlags {

DEFAULT(0),

/**
* only calculate file progress at piece granularity. This makes
* the file_progress() call cheaper and also only takes bytes that
* have passed the hash check into account, so progress cannot
* regress in this mode.
*/
PIECE_GRANULARITY(torrent_handle.file_progress_flags_t.piece_granularity.swigValue());

private FileProgressFlags(int swigValue) {
this.swigValue = swigValue;
}

private final int swigValue;

public int getSwig() {
return swigValue;
}
}
}

0 comments on commit 5825c16

Please sign in to comment.