Package org.klomp.snark
Class Piece
java.lang.Object
org.klomp.snark.Piece
- All Implemented Interfaces:
Comparable<Piece>
class Piece extends Object implements Comparable<Piece>
This class is used solely by PeerCoordinator.
Caller must synchronize on many of these methods.
-
Constructor Summary
Constructors Constructor Description Piece(int id) -
Method Summary
Modifier and Type Method Description booleanaddPeer(Peer peer)caller must synchronizevoidclear()Clear all knowledge of peers Caller must synchronizeintcompareTo(Piece op)Highest priority first, then rarest firstbooleanequals(Object o)intgetId()intgetPeerCount()How many peers have this piece? Caller must synchronizeintgetPriority()intgetRequestCount()How many peers are requesting this piece? Caller must synchronizeinthashCode()booleanisDisabled()booleanisRequested()caller must synchronizebooleanisRequestedBy(Peer peer)Is peer requesting this piece? Caller must synchronizebooleanremovePeer(Peer peer)Caller must synchronize.voidsetDisabled()voidsetPriority(int p)voidsetRequested(Peer peer, boolean requested)Since 0.8.3, keep track of who is requesting here, to avoid deadlocks from querying each peer.StringtoString()
-
Constructor Details
-
Piece
public Piece(int id)
-
-
Method Details
-
compareTo
Highest priority first, then rarest first- Specified by:
compareToin interfaceComparable<Piece>
-
equals
-
hashCode
public int hashCode() -
getId
public int getId() -
addPeer
caller must synchronize -
removePeer
Caller must synchronize.- Returns:
- true if removed
-
getPeerCount
public int getPeerCount()How many peers have this piece? Caller must synchronize- Since:
- 0.9.1
-
isRequested
public boolean isRequested()caller must synchronize -
setRequested
Since 0.8.3, keep track of who is requesting here, to avoid deadlocks from querying each peer. Caller must synchronize -
isRequestedBy
Is peer requesting this piece? Caller must synchronize- Since:
- 0.8.3
-
getRequestCount
public int getRequestCount()How many peers are requesting this piece? Caller must synchronize- Since:
- 0.8.3
-
clear
public void clear()Clear all knowledge of peers Caller must synchronize- Since:
- 0.9.3
-
getPriority
public int getPriority()- Returns:
- default 0 @since 0.8.1
-
setPriority
public void setPriority(int p)- Since:
- 0.8.1
-
isDisabled
public boolean isDisabled()- Since:
- 0.8.1
-
setDisabled
public void setDisabled()- Since:
- 0.8.1
-
toString
-