@NotThreadSafe public abstract class WorkProgressUpdater extends Object
startReportingProgress() and
stopReportingProgress() methods. The updater queries the
worker for progress updates and sends the updates to the worker
service. The interval between two consecutive updates is
controlled by the worker service through reporting interval hints
sent back in the update response messages. To avoid update storms
and monitoring staleness, the interval between two consecutive
updates is also bound by getMinReportingInterval() and
getMaxReportingInterval().| Modifier and Type | Field and Description |
|---|---|
static long |
DEFAULT_LEASE_DURATION_MILLIS
The default lease duration to request from the external worker service (3 minutes).
|
protected Reader.DynamicSplitResult |
dynamicSplitResultToReport
The
Reader.DynamicSplitResult to report to the service in the next progress update,
or null if there is nothing to report (if no dynamic split happened since the last
progress update). |
protected long |
progressReportIntervalMs
The time period until the next work progress update.
|
protected long |
requestedLeaseDurationMs
The lease duration to request from the external worker service.
|
protected WorkExecutor |
worker
Worker providing the work progress updates.
|
| Constructor and Description |
|---|
WorkProgressUpdater(WorkExecutor worker) |
| Modifier and Type | Method and Description |
|---|---|
Reader.DynamicSplitResult |
getDynamicSplitResultToReport() |
protected long |
getLeaseRenewalLatencyMargin()
Returns the maximum allowed time between a periodic progress update and the moment
the current lease expires.
|
protected long |
getMaxReportingInterval()
Returns the maximum allowed time between two periodic progress updates.
|
protected long |
getMinReportingInterval()
Returns the minimum allowed time between two periodic progress updates.
|
protected abstract long |
getWorkUnitLeaseExpirationTimestamp()
Returns the current work item's lease expiration timestamp.
|
protected long |
getWorkUnitSuggestedReportingInterval()
Returns the current work item's suggested progress reporting interval.
|
protected long |
leaseRemainingTime(long leaseExpirationTimestamp)
Computes the amount of time left, in milliseconds, before a lease
with the specified expiration timestamp expires.
|
protected long |
nextProgressReportInterval(long suggestedInterval,
long leaseRemainingTime)
Computes the time before sending the next work progress update making sure
that it falls between the [
getMinReportingInterval(),
getMaxReportingInterval()] interval. |
protected abstract void |
reportProgressHelper()
Reports the current work progress to the worker service.
|
void |
startReportingProgress()
Starts sending work progress updates to the worker service.
|
void |
stopReportingProgress()
Stops sending work progress updates to the worker service.
|
protected abstract String |
workString()
Returns a string representation of the work item whose progress
is being updated, for use in logging messages.
|
public static final long DEFAULT_LEASE_DURATION_MILLIS
protected final WorkExecutor worker
protected long requestedLeaseDurationMs
protected long progressReportIntervalMs
protected Reader.DynamicSplitResult dynamicSplitResultToReport
Reader.DynamicSplitResult to report to the service in the next progress update,
or null if there is nothing to report (if no dynamic split happened since the last
progress update).public WorkProgressUpdater(WorkExecutor worker)
public void startReportingProgress()
public void stopReportingProgress()
throws Exception
Exceptionprotected final long nextProgressReportInterval(long suggestedInterval,
long leaseRemainingTime)
getMinReportingInterval(),
getMaxReportingInterval()] interval. Makes an attempt to bound
the result by the remaining lease time, with an RPC latency margin of
getLeaseRenewalLatencyMargin().suggestedInterval - the suggested progress report intervalleaseRemainingTime - milliseconds left before the work lease expiresprotected long leaseRemainingTime(long leaseExpirationTimestamp)
public Reader.DynamicSplitResult getDynamicSplitResultToReport()
protected abstract void reportProgressHelper()
throws Exception
Exceptionprotected abstract long getWorkUnitLeaseExpirationTimestamp()
protected long getWorkUnitSuggestedReportingInterval()
protected long getMinReportingInterval()
protected long getMaxReportingInterval()
protected long getLeaseRenewalLatencyMargin()
protected abstract String workString()