Package org.jets3t.service.io
Class BytesProgressWatcher
java.lang.Object
org.jets3t.service.io.BytesProgressWatcher
Utility class that tracks the number of bytes transferred from a source, and uses this
information to calculate transfer rates and estimate end times. The watcher stores the
number of bytes that will be transferred, the number of bytes that have been transferred
in the current session and the time this has taken, and the number of bytes and time taken
overal (eg for transfers that have been restarted).
- Author:
- James Murty
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The number of seconds worth of historical byte transfer information that will be stored and used to calculate the recent transfer rate. -
Constructor Summary
ConstructorsConstructorDescriptionBytesProgressWatcher
(long bytesToTransfer) Construct a watcher for a transfer that will involve a given number of bytes. -
Method Summary
Modifier and TypeMethodDescriptionstatic double
calculateOverallBytesPerSecond
(BytesProgressWatcher[] progressWatchers) static long
calculateRecentByteRatePerSecond
(BytesProgressWatcher[] progressWatchers) static long
calculateRemainingTime
(BytesProgressWatcher[] progressWatchers) long
long
long
double
long
void
Resets the byte count and timer variables for a watcher.static long
sumBytesToTransfer
(BytesProgressWatcher[] progressWatchers) static long
sumBytesTransferred
(BytesProgressWatcher[] progressWatchers) void
updateBytesTransferred
(long byteCount) Notifies this watcher that bytes have been transferred.
-
Field Details
-
SECONDS_OF_HISTORY
public static final int SECONDS_OF_HISTORYThe number of seconds worth of historical byte transfer information that will be stored and used to calculate the recent transfer rate.- See Also:
-
-
Constructor Details
-
BytesProgressWatcher
public BytesProgressWatcher(long bytesToTransfer) Construct a watcher for a transfer that will involve a given number of bytes.- Parameters:
bytesToTransfer
- the number of bytes that will be transferred, eg the size of a file being uploaded.
-
-
Method Details
-
getBytesToTransfer
public long getBytesToTransfer()- Returns:
- the count of bytes that will be transferred by the object watched by this class.
-
resetWatcher
public void resetWatcher()Resets the byte count and timer variables for a watcher. This method is called automatically when a transfer is started (ie the first bytes are registered in the methodupdateBytesTransferred(long)
), or when a transfer is restarted (eg due to transmission errors). -
updateBytesTransferred
public void updateBytesTransferred(long byteCount) Notifies this watcher that bytes have been transferred.- Parameters:
byteCount
- the number of bytes that have been transferred.
-
getBytesTransferred
public long getBytesTransferred()- Returns:
- the number of bytes that have so far been transferred in the most recent transfer session.
-
getBytesRemaining
public long getBytesRemaining()- Returns:
- the number of bytes that are remaining to be transferred.
-
getRemainingTime
public long getRemainingTime()- Returns:
- an estimate of the time (in seconds) it will take for the transfer to completed, based on the number of bytes remaining to transfer and the overall bytes/second rate.
-
getRecentByteRatePerSecond
public double getRecentByteRatePerSecond()- Returns:
- the byte rate (per second) based on the historical information for the last
SECONDS_OF_HISTORY
seconds before the current time.
-
sumBytesToTransfer
- Parameters:
progressWatchers
- all the watchers involved in the same byte transfer operation.- Returns:
- the total number of bytes to transfer.
-
sumBytesTransferred
- Parameters:
progressWatchers
- all the watchers involved in the same byte transfer operation.- Returns:
- the total number of bytes already transferred.
-
calculateRemainingTime
- Parameters:
progressWatchers
- all the watchers involved in the same byte transfer operation.- Returns:
- an estimate of the time (in seconds) it will take for the transfer to completed, based on the number of bytes remaining to transfer and the overall bytes/second rate.
-
calculateOverallBytesPerSecond
- Parameters:
progressWatchers
- all the watchers involved in the same byte transfer operation.- Returns:
- the overall rate of bytes/second over all transfers for all watchers.
-
calculateRecentByteRatePerSecond
- Parameters:
progressWatchers
- all the watchers involved in the same byte transfer operation.- Returns:
- the rate of bytes/second that has been achieved recently (ie within the last
SECONDS_OF_HISTORY
seconds).
-