public void updateProgress ( long latestProgress , long expectedProgress ) { lastProgress = progress ; progress = latestProgress ; expected = expectedProgress ; if ( connected ( ) == false ) state = State . CONNECTED ; else state = State . UPDATE ; // The threshold effectively divides the progress into // different set of ranges: // // Range 0: 0..threshold-1, // Range 1: threshold .. 2*threshold-1 // .... // Range n: n*threshold .. (n+1)*threshold-1 // // To determine which range the progress belongs to, it // would be calculated as follow: // // range number = progress / threshold // // Notification should only be triggered when the current // progress and the last progress are in different ranges, // i.e. they have different range numbers. // // Using this range scheme, notification will be generated // only once when the progress reaches each range. // if ( lastProgress / threshold != progress / threshold ) { progressMonitor . updateProgress ( this ) ; } // Detect read overrun if ( expected != - 1 ) { if ( progress >= expected && progress != 0 ) close ( ) ; } }
Update progress .