3.2.4: 2013-12-06

net.sf.basedb.util
Class TransferRateProgressReporter

java.lang.Object
  extended by 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
private  int maxDelay
           
private  int maxTicksPerSecond
           
private  AbsoluteProgressReporter parent
           
private  long startTime
           
 
Constructor Summary
TransferRateProgressReporter(AbsoluteProgressReporter parent, int maxTicksPerSecond)
          Create a new progress reporter.
TransferRateProgressReporter(AbsoluteProgressReporter parent, int maxTicksPerSecond, int maxDelay)
          Create a new progress reporter.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parent

private final AbsoluteProgressReporter parent

maxTicksPerSecond

private final int maxTicksPerSecond

maxDelay

private final int maxDelay

startTime

private long startTime
Constructor Detail

TransferRateProgressReporter

public TransferRateProgressReporter(AbsoluteProgressReporter parent,
                                    int maxTicksPerSecond)
Create a new progress reporter. Max delay per progress update is 8 seconds.

Parameters:
parent - An optional parent progress reporter
ticksPerSecond - Max allowed ticks-per-second, if the rate goes above this, the displayAbsolute(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 reporter
ticksPerSecond - Max allowed ticks-per-second, if the rate goes above this, the displayAbsolute(long, String) method will wait a short time before returning
maxDelay - The max delay in milliseconds for each call to displayAbsolute(long, String)
Method Detail

display

public void display(int percent,
                    String message)
Forward the call to the parent if one exists. There is no rate control in this method.

Specified by:
display in interface ProgressReporter
Parameters:
percent - How many percent of the task that is completed or -1 if not known
message - A message, or null

append

public void append(String message)
Forward the call to the parent if one exists.

Specified by:
append in interface ProgressReporter
Parameters:
message - The message

displayAbsolute

public void displayAbsolute(long completed,
                            String message)
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 interface AbsoluteProgressReporter
Parameters:
completed - The progress of the task
message - A message, or null

3.2.4: 2013-12-06