Class ThreadWatcher
- java.lang.Object
-
- org.jets3t.service.multi.ThreadWatcher
-
- Direct Known Subclasses:
ThreadWatcher
public class ThreadWatcher extends Object
A thread watcher is associated with a multi-threaded operation and contains information about the progress of the operation.As a minimum, this object will contain a count of the total number of threads involved in the operation (via
getThreadCount()
) and the count of threads that have already finished (viagetCompletedThreads()
).For operations involving data transfer, such as uploads or downloads, this object may also include a count of the total bytes being transferred (via
getBytesTotal()
) and a count of how many bytes have already been transferred (viagetBytesTransferred()
). The availability of this information is indicated by the result ofisBytesTransferredInfoAvailable()
.Further data tranfer information may be also available, such as the current transfer rate (via
getBytesPerSecond()
) and an estimate of the time remaining until the transfer is completed (viagetTimeRemaining()
). The availability of this information is indicated by the result ofisTimeRemainingAvailable()
.It is possible to cancel some operations. If an operation may be cancelled, this object will include a
CancelEventTrigger
(available fromgetCancelEventListener()
) which can be used to trigger a cancellation. Whether the operation can be cancelled is indicated byisCancelTaskSupported()
.- Author:
- James Murty
-
-
Constructor Summary
Constructors Constructor Description ThreadWatcher(long threadCount)
ThreadWatcher(BytesProgressWatcher[] progressWatchers)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancelTask()
Convenience method to trigger an event cancellation viaCancelEventTrigger.cancelTask(java.lang.Object)
if this thread watcher is associated with an operation that can be cancelled.long
getBytesPerSecond()
long
getBytesTotal()
long
getBytesTransferred()
CancelEventTrigger
getCancelEventListener()
long
getCompletedThreads()
long
getThreadCount()
long
getTimeRemaining()
boolean
isBytesTransferredInfoAvailable()
If this method returns true, the methodsgetBytesTotal()
andgetBytesTransferred()
will contain information about the amount of data being transferred by the watched threads.boolean
isCancelTaskSupported()
boolean
isTimeRemainingAvailable()
If this method returns true, the methodgetTimeRemaining()
will contain an estimate of the completion time for the data transfer.void
updateThreadsCompletedCount(long completedThreads)
Sets information about the number of threads completed and the total number of threads.void
updateThreadsCompletedCount(long completedThreads, CancelEventTrigger cancelEventListener)
Sets information about the number of threads completed and the total number of threads, as well as setting the cancellation listener that will be notified if the event is cancelled.
-
-
-
Constructor Detail
-
ThreadWatcher
public ThreadWatcher(BytesProgressWatcher[] progressWatchers)
-
ThreadWatcher
public ThreadWatcher(long threadCount)
-
-
Method Detail
-
updateThreadsCompletedCount
public void updateThreadsCompletedCount(long completedThreads)
Sets information about the number of threads completed and the total number of threads.- Parameters:
completedThreads
- the number of threads that have completed.
-
updateThreadsCompletedCount
public void updateThreadsCompletedCount(long completedThreads, CancelEventTrigger cancelEventListener)
Sets information about the number of threads completed and the total number of threads, as well as setting the cancellation listener that will be notified if the event is cancelled.- Parameters:
completedThreads
- the number of threads that have completed.cancelEventListener
- the listener to notify of cancellation events.
-
getCompletedThreads
public long getCompletedThreads()
- Returns:
- the number of threads that have completed.
-
getThreadCount
public long getThreadCount()
- Returns:
- the total number of threads involved in an operation.
-
isBytesTransferredInfoAvailable
public boolean isBytesTransferredInfoAvailable()
If this method returns true, the methodsgetBytesTotal()
andgetBytesTransferred()
will contain information about the amount of data being transferred by the watched threads.- Returns:
- true if this watcher contains information about the bytes transferred by the threads it is watching.
-
getBytesTotal
public long getBytesTotal() throws IllegalStateException
- Returns:
- the expected total of bytes that will be transferred by the watched threads.
- Throws:
IllegalStateException
- if the bytes transferred information is not available - check this availability with theisBytesTransferredInfoAvailable()
method.
-
getBytesTransferred
public long getBytesTransferred()
- Returns:
- the count of bytes that have been transferred by the watched threads.
- Throws:
IllegalStateException
- if the bytes transferred information is not available - check this availability with theisBytesTransferredInfoAvailable()
method.
-
getBytesPerSecond
public long getBytesPerSecond()
- Returns:
- an estimate of the recent rate of bytes/second transfer speed.
-
isTimeRemainingAvailable
public boolean isTimeRemainingAvailable()
If this method returns true, the methodgetTimeRemaining()
will contain an estimate of the completion time for the data transfer.- Returns:
- true if this watcher contains an estimate of the completion time for the data transfer.
-
getTimeRemaining
public long getTimeRemaining()
- Returns:
- an estimate of the how many seconds until the data transfer completes, based on the overall byte rate of the transmission.
- Throws:
IllegalStateException
- if the time remaining estimave is not available - check this availability with theisTimeRemainingAvailable()
method.
-
isCancelTaskSupported
public boolean isCancelTaskSupported()
- Returns:
- true if the operation this object is associated with can be cancelled, and a
CancelEventTrigger
is available.
-
cancelTask
public void cancelTask()
Convenience method to trigger an event cancellation viaCancelEventTrigger.cancelTask(java.lang.Object)
if this thread watcher is associated with an operation that can be cancelled.
-
getCancelEventListener
public CancelEventTrigger getCancelEventListener()
- Returns:
- the cancel event trigger associated with an operation, if any.
-
-