Package com.frostwire.jlibtorrent
Enum Class Priority
- All Implemented Interfaces:
Serializable,Comparable<Priority>,Constable
Priority levels for downloading pieces and files in a torrent.
When downloading a multi-file torrent, you can specify per-file priorities to control which files are downloaded and in what order. Priorities affect the download scheduler's piece selection algorithm - higher priority pieces are requested more frequently.
Understanding Availability: The availability of a piece is the number of peers that have it. Pieces with lower availability (rarer pieces) are more valuable since they're at risk of becoming unavailable if peers disconnect. The scheduling algorithm balances rarity with priority:
- Rare pieces (low availability) are usually prioritized regardless of file priority
- Common pieces (high availability) follow the file priority settings
Priority Levels (0-7):
IGNORE (0) - Don't download this file/piece at all (skip it) NORMAL (1) - Normal priority, balanced rarity vs progress TWO (2) - Slightly higher than normal THREE (3) - Equal priority as partial pieces FOUR (4) - Preferred over partial pieces FIVE (5) - Same as FOUR (reserved for future use) SIX (6) - As likely as pieces with 1 available copy SEVEN (7) - Maximum priority, ignore availability
Setting File Priorities:
// Download only specific files
TorrentInfo ti = new TorrentInfo(torrentFile);
Priority[] priorities = new Priority[ti.numFiles()];
// Skip all files by default
for (int i = 0; i < priorities.length; i++) {
priorities[i] = Priority.IGNORE;
}
// Download only files 0 and 2
priorities[0] = Priority.NORMAL;
priorities[2] = Priority.NORMAL;
sm.download(ti, saveDir, null, priorities, null, new torrent_flags_t());
// Or on an existing torrent handle
torrentHandle.prioritizeFiles(priorities);
Selective Download Strategy:
// Download files in order of importance
Priority[] priorities = new Priority[ti.numFiles()];
for (int i = 0; i < priorities.length; i++) {
if (i < 2) {
priorities[i] = Priority.SEVEN; // Critical: max priority
} else if (i < 5) {
priorities[i] = Priority.NORMAL; // Important: balanced
} else {
priorities[i] = Priority.IGNORE; // Not needed: skip
}
}
torrentHandle.prioritizeFiles(priorities);
Utility Methods:
// Create array with same priority for all files Priority[] allNormal = Priority.array(Priority.NORMAL, 5); // 5 files, all NORMAL // Convert to/from native values Priority p = Priority.fromSwig(1); // NORMAL int nativeValue = p.swig(); // 1
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescription*currently the same as 4*pieces are preferred over partial pieces, but not over pieces with lower availabilitypiece or file is not downloaded at allnormal priority.maximum priority, availability is disregarded, the piece is preferred over any other piece with lower prioritypiece is as likely to be picked as any piece with availability 1pieces are as likely to be picked as partial pieces.higher than normal priority. -
Method Summary
Modifier and TypeMethodDescriptionstatic Priority[]static PriorityfromSwig(int swigValue) intswig()static PriorityReturns the enum constant of this class with the specified name.static Priority[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
IGNORE
piece or file is not downloaded at all -
NORMAL
normal priority. Download order is dependent on availability -
TWO
higher than normal priority. Pieces are preferred over pieces with the same availability, but not over pieces with lower availability -
THREE
pieces are as likely to be picked as partial pieces. -
FOUR
pieces are preferred over partial pieces, but not over pieces with lower availability -
FIVE
*currently the same as 4* -
SIX
piece is as likely to be picked as any piece with availability 1 -
SEVEN
maximum priority, availability is disregarded, the piece is preferred over any other piece with lower priority
-
-
Method Details
-
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
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 nameNullPointerException- if the argument is null
-
swig
public int swig()- Returns:
- the native value
-
fromSwig
- Parameters:
swigValue- the native value- Returns:
- the enum corresponding value
-
array
-