Make values forwarded to bandwidth listener final again.

When notifying the bandwidth listeners of new samples, the forwarded values
need to be final to prevent concurrent access. Putting the event forwarding
into a separate method ensures the values are final.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=204877650
This commit is contained in:
tonihei 2018-07-17 02:00:30 -07:00 committed by Oliver Woodman
parent b25a124239
commit 74dadae520

View File

@ -226,13 +226,14 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
bitrateEstimate = (long) slidingPercentile.getPercentile(0.5f);
}
}
eventDispatcher.dispatch(
listener ->
listener.onBandwidthSample(
sampleElapsedTimeMs, sampleBytesTransferred, bitrateEstimate));
notifyBandwidthSample(sampleElapsedTimeMs, sampleBytesTransferred, bitrateEstimate);
if (--streamCount > 0) {
sampleStartTimeMs = nowMs;
}
sampleBytesTransferred = 0;
}
private void notifyBandwidthSample(int elapsedMs, long bytes, long bitrate) {
eventDispatcher.dispatch(listener -> listener.onBandwidthSample(elapsedMs, bytes, bitrate));
}
}