Changeset 4054


Ignore:
Timestamp:
Dec 11, 2007, 11:51:57 AM (16 years ago)
Author:
Martin Svensson
Message:

Fixes #865 Progress reporter implementation should detect and handle negative values due to integer wrap around.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.5-stable/src/core/net/sf/basedb/core/Job.java

    r4034 r4054  
    12101210    private long lastUpdate;
    12111211   
     1212    private int lastValue;
     1213    private int offset;
     1214   
    12121215    ProgressReporterImpl(Job job, String server, ProgressReporter chained)
    12131216      throws BaseException
     
    12191222      this.chained = chained;
    12201223      this.lastUpdate = 0;
     1224      this.lastValue = 0;
     1225      this.offset = 0;
    12211226    }
    12221227   
     
    12301235      if (System.currentTimeMillis() - lastUpdate > UPDATE_INTERVAL)
    12311236      {
     1237        // If the percent is negative and less then the last value, an offset will be calculated.
     1238        // This will adjust the percent to a realistic value.
     1239        //Notice: It is only possible to give a value close to what expected.
     1240        if (percent < lastValue && percent < 0)
     1241        {
     1242          if (Math.abs(percent) < Math.abs(lastValue))
     1243          {
     1244            offset = offset + 2*Math.abs(lastValue);
     1245          }
     1246          else
     1247          {
     1248            offset = offset + 2*Math.abs(percent);
     1249          }
     1250        }
     1251        lastValue = percent;   
     1252        percent = percent + offset;
     1253       
    12321254        lastUpdate = System.currentTimeMillis();
    12331255        DbControl dc = null;
Note: See TracChangeset for help on using the changeset viewer.