Top Description Fields Constructors Methods
org.eclipse.jgit.lib

public Class ThreadSafeProgressMonitor

extends Object
implements ProgressMonitor
Class Inheritance
All Implemented Interfaces
org.eclipse.jgit.lib.ProgressMonitor
Imports
java.util.concurrent.Semaphore, java.util.concurrent.atomic.AtomicInteger, java.util.concurrent.locks.ReentrantLock

Wrapper around the general org.eclipse.jgit.lib.ProgressMonitor 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 uses pollForUpdates() or waitForCompletion() to update the underlying ProgressMonitor. Only update(int), isCancelled(), and endWorker() 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

Modifier and TypeField and Description
private final ReentrantLock
private final Thread
private final AtomicInteger
private final ProgressMonitor
private final Semaphore
private final AtomicInteger

Constructor Summary

AccessConstructor and Description
public
ThreadSafeProgressMonitor(ProgressMonitor
the underlying monitor to receive events.
pm
)

Wrap a ProgressMonitor to be thread safe.

Method Summary

Modifier and TypeMethod and Description
public void
beginTask(String
title to describe the task. Callers should publish these as stable string constants that implementations could match against for translation support.
title
,
int
total number of work units the application will perform; UNKNOWN if it cannot be predicted in advance.
totalWork
)

Implements org.eclipse.jgit.lib.ProgressMonitor.beginTask.

Begin processing a single task.

private void
public void
endTask()

Implements org.eclipse.jgit.lib.ProgressMonitor.endTask.

Finish the current task, so the next can begin.

public void
endWorker()

Notify the monitor a worker is finished.

public boolean
isCancelled()

Implements org.eclipse.jgit.lib.ProgressMonitor.isCancelled.

Check for user task cancellation.

private boolean
public void
pollForUpdates()

Non-blocking poll for pending updates.

public void
showDuration(boolean
whether to show elapsed time per task
enabled
)

Implements org.eclipse.jgit.lib.ProgressMonitor.showDuration.

Set whether the monitor should show elapsed time per task

public void
start(int
the total number of tasks the caller will need to complete their processing.
totalTasks
)

Implements org.eclipse.jgit.lib.ProgressMonitor.start.

Advise the monitor of the total number of subtasks.

public void
startWorker()

Notify the monitor a worker is starting.

public void
startWorkers(int
the number of worker threads that are starting.
count
)

Notify the monitor of workers starting.

public void
update(int
the number of work units completed since the last call.
completed
)

Implements org.eclipse.jgit.lib.ProgressMonitor.update.

Denote that some work units have been completed.

public void
waitForCompletion()

Process pending updates and wait for workers to finish.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lockback to summary
private final ReentrantLock lock
mainThreadback to summary
private final Thread mainThread
pendingUpdatesback to summary
private final AtomicInteger pendingUpdates
pmback to summary
private final ProgressMonitor pm
processback to summary
private final Semaphore process
workersback to summary
private final AtomicInteger workers

Constructor Detail

ThreadSafeProgressMonitorback to summary
public ThreadSafeProgressMonitor(ProgressMonitor pm)

Wrap a ProgressMonitor to be thread safe.

Parameters
pm:ProgressMonitor

the underlying monitor to receive events.

Method Detail

beginTaskback to summary
public void beginTask(String title, int totalWork)

Implements org.eclipse.jgit.lib.ProgressMonitor.beginTask.

Doc from org.eclipse.jgit.lib.ProgressMonitor.beginTask.

Begin processing a single task.

Parameters
title:String

title to describe the task. Callers should publish these as stable string constants that implementations could match against for translation support.

totalWork:int

total number of work units the application will perform; UNKNOWN if it cannot be predicted in advance.

Annotations
@Override
doUpdatesback to summary
private void doUpdates()
endTaskback to summary
public void endTask()

Implements org.eclipse.jgit.lib.ProgressMonitor.endTask.

Doc from org.eclipse.jgit.lib.ProgressMonitor.endTask.

Finish the current task, so the next can begin.

Annotations
@Override
endWorkerback to summary
public void endWorker()

Notify the monitor a worker is finished.

isCancelledback to summary
public boolean isCancelled()

Implements org.eclipse.jgit.lib.ProgressMonitor.isCancelled.

Doc from org.eclipse.jgit.lib.ProgressMonitor.isCancelled.

Check for user task cancellation.

Returns:boolean

true if the user asked the process to stop working.

Annotations
@Override
isMainThreadback to summary
private boolean isMainThread()
pollForUpdatesback to summary
public void pollForUpdates()

Non-blocking poll for pending updates. This method can only be invoked by the same thread that allocated this ThreadSafeProgressMonior.

showDurationback to summary
public void showDuration(boolean enabled)

Implements org.eclipse.jgit.lib.ProgressMonitor.showDuration.

Doc from org.eclipse.jgit.lib.ProgressMonitor.showDuration.

Set whether the monitor should show elapsed time per task

Parameters
enabled:boolean

whether to show elapsed time per task

Annotations
@Override
startback to summary
public void start(int totalTasks)

Implements org.eclipse.jgit.lib.ProgressMonitor.start.

Doc from org.eclipse.jgit.lib.ProgressMonitor.start.

Advise the monitor of the total number of subtasks.

This should be invoked at most once per progress monitor interface.

Parameters
totalTasks:int

the total number of tasks the caller will need to complete their processing.

Annotations
@Override
startWorkerback to summary
public void startWorker()

Notify the monitor a worker is starting.

startWorkersback to summary
public void startWorkers(int count)

Notify the monitor of workers starting.

Parameters
count:int

the number of worker threads that are starting.

updateback to summary
public void update(int completed)

Implements org.eclipse.jgit.lib.ProgressMonitor.update.

Doc from org.eclipse.jgit.lib.ProgressMonitor.update.

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.

Parameters
completed:int

the number of work units completed since the last call.

Annotations
@Override
waitForCompletionback to summary
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.

Exceptions
InterruptedException:
if the main thread is interrupted while waiting for completion of workers.