Package org.jets3t.service.io
Class BytesProgressWatcher
- java.lang.Object
-
- org.jets3t.service.io.BytesProgressWatcher
-
public class BytesProgressWatcher extends Object
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
Fields Modifier and Type Field Description static int
SECONDS_OF_HISTORY
The number of seconds worth of historical byte transfer information that will be stored and used to calculate the recent transfer rate.
-
Constructor Summary
Constructors Constructor Description BytesProgressWatcher(long bytesToTransfer)
Construct a watcher for a transfer that will involve a given number of bytes.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static double
calculateOverallBytesPerSecond(BytesProgressWatcher[] progressWatchers)
static long
calculateRecentByteRatePerSecond(BytesProgressWatcher[] progressWatchers)
static long
calculateRemainingTime(BytesProgressWatcher[] progressWatchers)
long
getBytesRemaining()
long
getBytesToTransfer()
long
getBytesTransferred()
double
getRecentByteRatePerSecond()
long
getRemainingTime()
void
resetWatcher()
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 Detail
-
SECONDS_OF_HISTORY
public static final int SECONDS_OF_HISTORY
The number of seconds worth of historical byte transfer information that will be stored and used to calculate the recent transfer rate.- See Also:
- Constant Field Values
-
-
Method Detail
-
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
public static long sumBytesToTransfer(BytesProgressWatcher[] progressWatchers)
- Parameters:
progressWatchers
- all the watchers involved in the same byte transfer operation.- Returns:
- the total number of bytes to transfer.
-
sumBytesTransferred
public static long sumBytesTransferred(BytesProgressWatcher[] progressWatchers)
- Parameters:
progressWatchers
- all the watchers involved in the same byte transfer operation.- Returns:
- the total number of bytes already transferred.
-
calculateRemainingTime
public static long calculateRemainingTime(BytesProgressWatcher[] progressWatchers)
- 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
public static double calculateOverallBytesPerSecond(BytesProgressWatcher[] progressWatchers)
- 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
public static long calculateRecentByteRatePerSecond(BytesProgressWatcher[] progressWatchers)
- 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).
-
-