Package net.sf.basedb.util
Class TransferRateProgressReporter
java.lang.Object
net.sf.basedb.util.TransferRateProgressReporter
- All Implemented Interfaces:
AbsoluteProgressReporter
,ProgressReporter
public class TransferRateProgressReporter extends Object implements AbsoluteProgressReporter
A progress reporter implementation that has a "side-effect"
that limits the transfer rate. The parent progress reporter
is optional.
- Since:
- 3.2
- Author:
- nicklas
-
Field Summary
Fields Modifier and Type Field Description private int
maxDelay
private int
maxTicksPerSecond
private AbsoluteProgressReporter
parent
private long
startTime
-
Constructor Summary
Constructors Constructor Description TransferRateProgressReporter(AbsoluteProgressReporter parent, int maxTicksPerSecond)
Create a new progress reporter.TransferRateProgressReporter(AbsoluteProgressReporter parent, int maxTicksPerSecond, int maxDelay)
Create a new progress reporter. -
Method Summary
Modifier and Type Method Description void
append(String message)
Forward the call to the parent if one exists.void
display(int percent, String message)
Forward the call to the parent if one exists.void
displayAbsolute(long completed, String message)
Forward the call to the parent if one exists.
-
Field Details
-
parent
-
maxTicksPerSecond
private final int maxTicksPerSecond -
maxDelay
private final int maxDelay -
startTime
private long startTime
-
-
Constructor Details
-
TransferRateProgressReporter
Create a new progress reporter. Max delay per progress update is 8 seconds.- Parameters:
parent
- An optional parent progress reportermaxTicksPerSecond
- Max allowed ticks-per-second, if the rate goes above this, thedisplayAbsolute(long, String)
method will wait a short time before returning
-
TransferRateProgressReporter
public TransferRateProgressReporter(AbsoluteProgressReporter parent, int maxTicksPerSecond, int maxDelay)Create a new progress reporter. Max delay per progress update is 8 seconds.- Parameters:
parent
- An optional parent progress reportermaxTicksPerSecond
- Max allowed ticks-per-second, if the rate goes above this, thedisplayAbsolute(long, String)
method will wait a short time before returningmaxDelay
- The max delay in milliseconds for each call todisplayAbsolute(long, String)
-
-
Method Details
-
display
Forward the call to the parent if one exists. There is no rate control in this method.- Specified by:
display
in interfaceProgressReporter
- Parameters:
percent
- How many percent of the task that is completed or -1 if not knownmessage
- A message, or null
-
append
Forward the call to the parent if one exists.- Specified by:
append
in interfaceProgressReporter
- Parameters:
message
- The message
-
displayAbsolute
Forward the call to the parent if one exists. Then check the number of completed ticks and time since start against the max transfer rate. If the max rate has been exceeded pause the thread for a while.- Specified by:
displayAbsolute
in interfaceAbsoluteProgressReporter
- Parameters:
completed
- The progress of the taskmessage
- A message, or null
-