Class MultiProgressMonitor
- All Implemented Interfaces:
- com.google.gerrit.server.cancellation.RequestStateProvider
Output is of the format:
Task: subA: 1, subB: 75% (3/4) (-)\r Task: subA: 2, subB: 75% (3/4), subC: 1 (\)\r Task: subA: 2, subB: 100% (4/4), subC: 1 (|)\r Task: subA: 4, subB: 100% (4/4), subC: 4, done \n
Callers should try to keep task and sub-task descriptions short, since the output should fit on one terminal line. (Note that git clients do not accept terminal control characters, so true multi-line progress messages would be impossible.)
Whether the client is disconnected or the deadline is exceeded can be checked by checkIfCancelled(RequestStateProvider.OnCancelled). This allows the worker thread to react to
 cancellations and abort its execution and finish gracefully. After a cancellation has been
 signaled the worker thread has 10 * maxIntervalNanos to react to the cancellation and
 finish gracefully. If the worker thread doesn't finish gracefully in time after the cancellation
 has been signaled, the future executing the task is forcefully cancelled which means that the
 worker thread gets interrupted and an internal error is returned to the client. To react to
 cancellations it is recommended that the task opens a RequestStateContext in a try-with-resources block to
 register the MultiProgressMonitor as a RequestStateProvider. This way the worker
 thread gets aborted by a RequestCancelledException
 when the request is cancelled which allows the worker thread to handle the cancellation
 gracefully by catching this exception (e.g. to return a proper error message). RequestCancelledException is only thrown when the worker
 thread checks for cancellation via RequestStateContext.abortIfCancelled(). E.g. this is done
 whenever TraceContext.TraceTimer is opened/closed.
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceclassHandle for a sub-task.static enumclassHandle for a sub-task whose total work can be updated while the task is in progress.Nested classes/interfaces inherited from interface com.google.gerrit.server.cancellation.RequestStateProvidercom.google.gerrit.server.cancellation.RequestStateProvider.OnCancelled, com.google.gerrit.server.cancellation.RequestStateProvider.Reason
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intConstant indicating the total work units cannot be predicted.
- 
Method SummaryModifier and TypeMethodDescriptionbeginSubTask(String subTask, int subTaskWork) Begin a sub-task.beginVolatileSubTask(String subTask) Begin a sub-task whose total work can be updated.voidcheckIfCancelled(com.google.gerrit.server.cancellation.RequestStateProvider.OnCancelled onCancelled) voidend()End the overall task.<T> TWait for a task managed by aFuture, with no timeout.<T> TwaitFor(Future<T> workerFuture, long taskTimeoutTime, TimeUnit taskTimeoutUnit, long cancellationTimeoutTime, TimeUnit cancellationTimeoutUnit) Wait for a task managed by aFuture.<T> TwaitForNonFinalTask(Future<T> workerFuture) Wait for a non-final task managed by aFuture, with no timeout.<T> TwaitForNonFinalTask(Future<T> workerFuture, long taskTimeoutTime, TimeUnit taskTimeoutUnit, long cancellationTimeoutTime, TimeUnit cancellationTimeoutUnit) Wait for a task managed by aFuture.
- 
Field Details- 
UNKNOWNpublic static final int UNKNOWNConstant indicating the total work units cannot be predicted.- See Also:
 
 
- 
- 
Method Details- 
waitForWait for a task managed by aFuture, with no timeout.
- 
waitFor@CanIgnoreReturnValue public <T> T waitFor(Future<T> workerFuture, long taskTimeoutTime, TimeUnit taskTimeoutUnit, long cancellationTimeoutTime, TimeUnit cancellationTimeoutUnit) throws TimeoutException Wait for a task managed by aFuture.Must be called from the main thread, not a worker thread. Once a worker thread calls end(), the future has an additionalmaxIntervalto finish before it is forcefully cancelled andExecutionExceptionis thrown.- Parameters:
- workerFuture- a future that returns when worker threads are finished.
- taskTimeoutTime- overall timeout for the task; the future gets a cancellation signal after this timeout is exceeded; non-positive values indicate no timeout.
- taskTimeoutUnit- unit for overall task timeout.
- cancellationTimeoutTime- timeout for the task to react to the cancellation signal; if the task doesn't terminate within this time it is forcefully cancelled; non-positive values indicate no timeout.
- cancellationTimeoutUnit- unit for the cancellation timeout.
- Throws:
- TimeoutException- if this thread or a worker thread was interrupted, the worker was cancelled, or timed out waiting for a worker to call- end().
- See Also:
 
- 
waitForNonFinalTaskWait for a non-final task managed by aFuture, with no timeout.
- 
waitForNonFinalTaskpublic <T> T waitForNonFinalTask(Future<T> workerFuture, long taskTimeoutTime, TimeUnit taskTimeoutUnit, long cancellationTimeoutTime, TimeUnit cancellationTimeoutUnit) throws TimeoutException Wait for a task managed by aFuture. This call does not expect the worker thread to callend(). It is intended to be used to track a non-final task.- Parameters:
- workerFuture- a future that returns when worker threads are finished.
- taskTimeoutTime- overall timeout for the task; the future is forcefully cancelled if the task exceeds the timeout. Non-positive values indicate no timeout.
- taskTimeoutUnit- unit for overall task timeout.
- cancellationTimeoutTime- timeout for the task to react to the cancellation signal; if the task doesn't terminate within this time it is forcefully cancelled; non-positive values indicate no timeout.
- cancellationTimeoutUnit- unit for the cancellation timeout.
- Throws:
- TimeoutException- if this thread or a worker thread was interrupted, the worker was cancelled, or timed out waiting for a worker to call- end().
 
- 
beginSubTaskBegin a sub-task.- Parameters:
- subTask- sub-task name.
- subTaskWork- total work units in sub-task, or- UNKNOWN.
- Returns:
- sub-task handle.
 
- 
beginVolatileSubTaskBegin a sub-task whose total work can be updated.- Parameters:
- subTask- sub-task name.
- Returns:
- sub-task handle.
 
- 
endpublic void end()End the overall task.Must be called from a worker thread. 
- 
checkIfCancelledpublic void checkIfCancelled(com.google.gerrit.server.cancellation.RequestStateProvider.OnCancelled onCancelled) - Specified by:
- checkIfCancelledin interface- com.google.gerrit.server.cancellation.RequestStateProvider
 
 
-