Enum Class Priority

java.lang.Object
java.lang.Enum<Priority>
com.frostwire.jlibtorrent.Priority
All Implemented Interfaces:
Serializable, Comparable<Priority>, Constable

public enum Priority extends Enum<Priority>
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:
  • Enum Constant Details

    • IGNORE

      public static final Priority IGNORE
      piece or file is not downloaded at all
    • NORMAL

      public static final Priority NORMAL
      normal priority. Download order is dependent on availability
    • TWO

      public static final Priority TWO
      higher than normal priority. Pieces are preferred over pieces with the same availability, but not over pieces with lower availability
    • THREE

      public static final Priority THREE
      pieces are as likely to be picked as partial pieces.
    • FOUR

      public static final Priority FOUR
      pieces are preferred over partial pieces, but not over pieces with lower availability
    • FIVE

      public static final Priority FIVE
      *currently the same as 4*
    • SIX

      public static final Priority SIX
      piece is as likely to be picked as any piece with availability 1
    • SEVEN

      public static final Priority SEVEN
      maximum priority, availability is disregarded, the piece is preferred over any other piece with lower priority
  • Method Details

    • values

      public static Priority[] 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 Priority 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
    • swig

      public int swig()
      Returns:
      the native value
    • fromSwig

      public static Priority fromSwig(int swigValue)
      Parameters:
      swigValue - the native value
      Returns:
      the enum corresponding value
    • array

      public static Priority[] array(Priority value, int size)