|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
jBittorrentAPI.DownloadTask
public class DownloadTask
Class representing a task that downloads pieces from a remote peer
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
static int |
BAD_HANDSHAKE
|
byte[] |
bitfield
|
static int |
CONNECTION_REFUSED
|
private long |
creationTime
|
private long |
downloaded
|
private static int |
DOWNLOADING
|
private Piece |
downloadPiece
|
private byte[] |
fileID
|
private static int |
IDLE
|
private boolean |
initiate
|
private java.io.InputStream |
is
|
private boolean |
isDownloading
|
private boolean |
isUploading
|
private javax.swing.event.EventListenerList |
listeners
|
private LogManager |
lm
|
private long |
lmrt
|
static int |
MALFORMED_MESSAGE
|
MessageReceiver |
mr
|
MessageSender |
ms
|
private byte[] |
myID
|
private int |
offset
|
private java.io.OutputStream |
os
|
Peer |
peer
|
private java.net.Socket |
peerConnection
|
private java.util.LinkedList<java.lang.Integer> |
pendingRequest
|
private static int |
READY_2_DL
|
private boolean |
run
|
private int |
state
|
static int |
TASK_COMPLETED
|
static int |
TIMEOUT
|
static int |
UNKNOWN_HOST
|
private long |
updateTime
|
private long |
uploaded
|
private static int |
WAIT_BFORHAVE
|
private static int |
WAIT_BLOCK
|
private static int |
WAIT_HS
|
private static int |
WAIT_UNCHOKE
|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
DownloadTask(Peer peer,
byte[] fileID,
byte[] myID,
boolean init,
byte[] bitfield)
Start the downloading process from the remote peer in parameter |
|
DownloadTask(Peer peer,
byte[] fileID,
byte[] myID,
boolean init,
byte[] bitfield,
java.net.Socket s)
Start the downloading process from the remote peer in parameter |
Method Summary | |
---|---|
void |
addDTListener(DTListener listener)
|
private void |
changeState(int newState)
Change the state of the task. |
int |
checkDownloaded()
Returns the total amount of bytes downloaded by this task so far |
private void |
clear()
Clear the piece currently downloading |
void |
connectionClosed()
Fired when the connection to the remote peer has been closed. |
void |
end()
Stops this thread by setting the 'run' variable to false and closing the communication thread (Message receiver and sender). |
protected void |
finalize()
|
private void |
fireAddActiveTask(java.lang.String id,
DownloadTask dt)
Fired to inform that this task has completed the handshake and is now ready to communicate with the remote peer |
private void |
firePeerAvailability(java.lang.String id,
java.util.BitSet hasPiece)
Fired to inform that the availability of this peer has changed |
private void |
firePeerReady(java.lang.String id)
Fired to inform that this task is ready to download |
private void |
firePeerRequest(java.lang.String peerID,
int piece,
int begin,
int length)
Fired to inform that the peer requests a piece block |
private void |
firePieceCompleted(int piece,
boolean complete)
Fired to inform that the given piece has been completed or not |
private void |
firePieceRequested(int piece,
boolean requested)
Fired to inform if the given piece is requested or not... |
private void |
fireTaskCompleted(java.lang.String id,
int reason)
Fired to inform that the task is finished for a certain reason |
DTListener[] |
getDTListeners()
|
Peer |
getPeer()
Returns this peer object |
private void |
initConnection()
Inits the connection to the remote peer. |
void |
keepAliveSent()
Fired when a keep-alive message has been sent by the MessageSender. |
void |
messageReceived(Message m)
According to the message type, change the state of the task (peer) and take the necessary actions |
void |
removeDTListener(DTListener listener)
|
void |
requestPiece(Piece p)
Request a peer to the peer |
void |
run()
|
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int BAD_HANDSHAKE
public byte[] bitfield
public static final int CONNECTION_REFUSED
private long creationTime
private long downloaded
private static final int DOWNLOADING
private Piece downloadPiece
private byte[] fileID
private static final int IDLE
private final boolean initiate
private java.io.InputStream is
private boolean isDownloading
private boolean isUploading
private final javax.swing.event.EventListenerList listeners
private LogManager lm
private long lmrt
public static final int MALFORMED_MESSAGE
public MessageReceiver mr
public MessageSender ms
private byte[] myID
private int offset
private java.io.OutputStream os
public Peer peer
private java.net.Socket peerConnection
private java.util.LinkedList<java.lang.Integer> pendingRequest
private static final int READY_2_DL
private boolean run
private int state
public static final int TASK_COMPLETED
public static final int TIMEOUT
public static final int UNKNOWN_HOST
private long updateTime
private long uploaded
private static final int WAIT_BFORHAVE
private static final int WAIT_BLOCK
private static final int WAIT_HS
private static final int WAIT_UNCHOKE
Constructor Detail |
---|
public DownloadTask(Peer peer, byte[] fileID, byte[] myID, boolean init, byte[] bitfield)
peer
- The peer to connect tofileID
- The file to be downloadedmyID
- The id of the current clientinit
- True if this client initiate the connection, false otherwisebitfield
- The pieces currently owned by this clientpublic DownloadTask(Peer peer, byte[] fileID, byte[] myID, boolean init, byte[] bitfield, java.net.Socket s)
peer
- The peer to connect tofileID
- The file to be downloadedmyID
- The id of the current clientinit
- True if this client initiate the connection, false otherwises
- Only set if this client receive a connection request from the remote peerbitfield
- The piece currently ownend by this clientMethod Detail |
---|
public void addDTListener(DTListener listener)
private void changeState(int newState)
newState
- The new state of the download taskpublic int checkDownloaded()
private void clear()
public void connectionClosed()
connectionClosed
in interface OutgoingListener
public void end()
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
private void fireAddActiveTask(java.lang.String id, DownloadTask dt)
id
- Stringdt
- DownloadTaskprivate void firePeerAvailability(java.lang.String id, java.util.BitSet hasPiece)
id
- StringhasPiece
- BitSetprivate void firePeerReady(java.lang.String id)
id
- Stringprivate void firePeerRequest(java.lang.String peerID, int piece, int begin, int length)
peerID
- Stringpiece
- intbegin
- intlength
- intprivate void firePieceCompleted(int piece, boolean complete)
piece
- intcomplete
- booleanprivate void firePieceRequested(int piece, boolean requested)
piece
- intrequested
- booleanprivate void fireTaskCompleted(java.lang.String id, int reason)
id
- Stringreason
- Reason why the task endedpublic DTListener[] getDTListeners()
public Peer getPeer()
private void initConnection() throws java.net.UnknownHostException, java.io.IOException
java.net.UnknownHostException
- If the remote peer is unknown
java.io.IOException
- If the connection to the remote peer fails (reset, ...)public void keepAliveSent()
keepAliveSent
in interface OutgoingListener
public void messageReceived(Message m)
messageReceived
in interface IncomingListener
m
- Messagepublic void removeDTListener(DTListener listener)
public void requestPiece(Piece p)
p
- The piece to be requested to the peerpublic void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |