Package org.eclipse.jgit.lib
Class ThreadSafeProgressMonitor
- java.lang.Object
-
- org.eclipse.jgit.lib.ThreadSafeProgressMonitor
-
- All Implemented Interfaces:
ProgressMonitor
public class ThreadSafeProgressMonitor extends Object implements ProgressMonitor
Wrapper around the generalProgressMonitor
to make it thread safe. Updates to the underlying ProgressMonitor are made only from the thread that allocated this wrapper. Callers are responsible for ensuring the allocating thread usespollForUpdates()
orwaitForCompletion()
to update the underlying ProgressMonitor. Onlyupdate(int)
,isCancelled()
, andendWorker()
may be invoked from a worker thread. All other methods of the ProgressMonitor interface can only be called from the thread that allocates this wrapper.
-
-
Field Summary
-
Fields inherited from interface org.eclipse.jgit.lib.ProgressMonitor
UNKNOWN
-
-
Constructor Summary
Constructors Constructor Description ThreadSafeProgressMonitor(ProgressMonitor pm)
Wrap a ProgressMonitor to be thread safe.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beginTask(String title, int totalWork)
Begin processing a single task.void
endTask()
Finish the current task, so the next can begin.void
endWorker()
Notify the monitor a worker is finished.boolean
isCancelled()
Check for user task cancellation.void
pollForUpdates()
Non-blocking poll for pending updates.void
start(int totalTasks)
Advise the monitor of the total number of subtasks.void
startWorker()
Notify the monitor a worker is starting.void
startWorkers(int count)
Notify the monitor of workers starting.void
update(int completed)
Denote that some work units have been completed.void
waitForCompletion()
Process pending updates and wait for workers to finish.
-
-
-
Constructor Detail
-
ThreadSafeProgressMonitor
public ThreadSafeProgressMonitor(ProgressMonitor pm)
Wrap a ProgressMonitor to be thread safe.- Parameters:
pm
- the underlying monitor to receive events.
-
-
Method Detail
-
start
public void start(int totalTasks)
Advise the monitor of the total number of subtasks.This should be invoked at most once per progress monitor interface.
- Specified by:
start
in interfaceProgressMonitor
- Parameters:
totalTasks
- the total number of tasks the caller will need to complete their processing.
-
beginTask
public void beginTask(String title, int totalWork)
Begin processing a single task.- Specified by:
beginTask
in interfaceProgressMonitor
- Parameters:
title
- title to describe the task. Callers should publish these as stable string constants that implementations could match against for translation support.totalWork
- total number of work units the application will perform;ProgressMonitor.UNKNOWN
if it cannot be predicted in advance.
-
startWorker
public void startWorker()
Notify the monitor a worker is starting.
-
startWorkers
public void startWorkers(int count)
Notify the monitor of workers starting.- Parameters:
count
- the number of worker threads that are starting.
-
endWorker
public void endWorker()
Notify the monitor a worker is finished.
-
pollForUpdates
public void pollForUpdates()
Non-blocking poll for pending updates. This method can only be invoked by the same thread that allocated this ThreadSafeProgressMonior.
-
waitForCompletion
public void waitForCompletion() throws InterruptedException
Process pending updates and wait for workers to finish. This method can only be invoked by the same thread that allocated this ThreadSafeProgressMonior.- Throws:
InterruptedException
- if the main thread is interrupted while waiting for completion of workers.
-
update
public void update(int completed)
Denote that some work units have been completed.This is an incremental update; if invoked once per work unit the correct value for our argument is
1
, to indicate a single unit of work has been finished by the caller.- Specified by:
update
in interfaceProgressMonitor
- Parameters:
completed
- the number of work units completed since the last call.
-
isCancelled
public boolean isCancelled()
Check for user task cancellation.- Specified by:
isCancelled
in interfaceProgressMonitor
- Returns:
- true if the user asked the process to stop working.
-
endTask
public void endTask()
Finish the current task, so the next can begin.- Specified by:
endTask
in interfaceProgressMonitor
-
-