Package com.google.gerrit.server.git
Class MultiProgressMonitor
- java.lang.Object
-
- com.google.gerrit.server.git.MultiProgressMonitor
-
public class MultiProgressMonitor extends Object
Progress reporting interface that multiplexes multiple sub-tasks.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.)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classMultiProgressMonitor.TaskHandle for a sub-task.
-
Field Summary
Fields Modifier and Type Field Description static intUNKNOWNConstant indicating the total work units cannot be predicted.
-
Constructor Summary
Constructors Constructor Description MultiProgressMonitor(OutputStream out, String taskName)Create a new progress monitor for multiple sub-tasks.MultiProgressMonitor(OutputStream out, String taskName, long maxIntervalTime, TimeUnit maxIntervalUnit)Create a new progress monitor for multiple sub-tasks.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MultiProgressMonitor.TaskbeginSubTask(String subTask, int subTaskWork)Begin a sub-task.voidend()End the overall task.<T> TwaitFor(Future<T> workerFuture)Wait for a task managed by aFuture, with no timeout.<T> TwaitFor(Future<T> workerFuture, long timeoutTime, TimeUnit timeoutUnit)Wait for a task managed by aFuture.
-
-
-
Field Detail
-
UNKNOWN
public static final int UNKNOWN
Constant indicating the total work units cannot be predicted.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MultiProgressMonitor
public MultiProgressMonitor(OutputStream out, String taskName)
Create a new progress monitor for multiple sub-tasks.- Parameters:
out- stream for writing progress messages.taskName- name of the overall task.
-
MultiProgressMonitor
public MultiProgressMonitor(OutputStream out, String taskName, long maxIntervalTime, TimeUnit maxIntervalUnit)
Create a new progress monitor for multiple sub-tasks.- Parameters:
out- stream for writing progress messages.taskName- name of the overall task.maxIntervalTime- maximum interval between progress messages.maxIntervalUnit- time unit for progress interval.
-
-
Method Detail
-
waitFor
public <T> T waitFor(Future<T> workerFuture)
Wait for a task managed by aFuture, with no timeout.- See Also:
waitFor(Future, long, TimeUnit)
-
waitFor
public <T> T waitFor(Future<T> workerFuture, long timeoutTime, TimeUnit timeoutUnit) 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.timeoutTime- overall timeout for the task; the future is forcefully cancelled if the task exceeds the timeout. Non-positive values indicate no timeout.timeoutUnit- unit for overall task timeout.- Throws:
TimeoutException- if this thread or a worker thread was interrupted, the worker was cancelled, or timed out waiting for a worker to callend().
-
beginSubTask
public MultiProgressMonitor.Task beginSubTask(String subTask, int subTaskWork)
Begin a sub-task.- Parameters:
subTask- sub-task name.subTaskWork- total work units in sub-task, orUNKNOWN.- Returns:
- sub-task handle.
-
end
public void end()
End the overall task.Must be called from a worker thread.
-
-