public class ProgressIndicatorUtils
extends java.lang.Object
ProcessCanceledException
at any moment.
Processes may want to react on cancellation event by restarting the activity, see
ReadTask.onCanceled(ProgressIndicator)
for that.Constructor and Description |
---|
ProgressIndicatorUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
awaitWithCheckCanceled(java.util.concurrent.CountDownLatch waiter) |
static <T> T |
awaitWithCheckCanceled(java.util.concurrent.Future<T> future) |
static <T> T |
awaitWithCheckCanceled(java.util.concurrent.Future<T> future,
ProgressIndicator indicator) |
static void |
awaitWithCheckCanceled(java.util.concurrent.locks.Lock lock,
int timeout,
java.util.concurrent.TimeUnit timeUnit) |
static void |
awaitWithCheckCanceled(Semaphore semaphore,
ProgressIndicator indicator) |
static void |
checkCancelledEvenWithPCEDisabled(ProgressIndicator indicator)
Use when otherwise a deadlock is possible.
|
static <T,E extends java.lang.Throwable> |
computeWithLockAndCheckingCanceled(java.util.concurrent.locks.Lock lock,
int timeout,
java.util.concurrent.TimeUnit timeUnit,
ThrowableComputable<T,E> computable) |
static ProgressIndicator |
forceWriteActionPriority(ProgressIndicator progress,
Disposable parentDisposable) |
static boolean |
runInReadActionWithWriteActionPriority(java.lang.Runnable action)
This method attempts to run provided action synchronously in a read action, so that, if possible, it wouldn't impact any pending,
executing or future write actions (for this to work effectively the action should invoke
ProgressManager.checkCanceled() or
ProgressIndicator.checkCanceled() often enough). |
static boolean |
runInReadActionWithWriteActionPriority(java.lang.Runnable action,
ProgressIndicator progressIndicator)
Same as
runInReadActionWithWriteActionPriority(Runnable) , optionally allowing to pass a ProgressIndicator
instance, which can be used to cancel action externally. |
static boolean |
runWithWriteActionPriority(java.lang.Runnable action,
ProgressIndicator progressIndicator) |
static java.util.concurrent.CompletableFuture<?> |
scheduleWithWriteActionPriority(java.util.concurrent.Executor executor,
ReadTask task) |
static java.util.concurrent.CompletableFuture<?> |
scheduleWithWriteActionPriority(ProgressIndicator progressIndicator,
java.util.concurrent.Executor executor,
ReadTask readTask) |
static java.util.concurrent.CompletableFuture<?> |
scheduleWithWriteActionPriority(ProgressIndicator progressIndicator,
ReadTask readTask) |
static void |
scheduleWithWriteActionPriority(ReadTask task) |
static <T> T |
withTimeout(long timeoutMs,
Computable<T> computation)
Run the given computation with its execution time restricted to the given amount of time in milliseconds.
|
static void |
yieldToPendingWriteActions()
Ensure the current EDT activity finishes in case it requires many write actions, with each being delayed a bit
by background thread read action (until its first checkCanceled call).
|
public static ProgressIndicator forceWriteActionPriority(ProgressIndicator progress, Disposable parentDisposable)
public static void scheduleWithWriteActionPriority(ReadTask task)
public static java.util.concurrent.CompletableFuture<?> scheduleWithWriteActionPriority(ProgressIndicator progressIndicator, ReadTask readTask)
public static java.util.concurrent.CompletableFuture<?> scheduleWithWriteActionPriority(java.util.concurrent.Executor executor, ReadTask task)
public static boolean runInReadActionWithWriteActionPriority(java.lang.Runnable action, ProgressIndicator progressIndicator)
runInReadActionWithWriteActionPriority(Runnable)
, optionally allowing to pass a ProgressIndicator
instance, which can be used to cancel action externally.public static boolean runInReadActionWithWriteActionPriority(java.lang.Runnable action)
ProgressManager.checkCanceled()
or
ProgressIndicator.checkCanceled()
often enough).
It returns true
if action was executed successfully. It returns false
if the action was not
executed successfully, i.e. if:
ProcessCanceledException
when some other thread initiated
write actionNonBlockingReadAction
public static boolean runWithWriteActionPriority(java.lang.Runnable action, ProgressIndicator progressIndicator)
public static java.util.concurrent.CompletableFuture<?> scheduleWithWriteActionPriority(ProgressIndicator progressIndicator, java.util.concurrent.Executor executor, ReadTask readTask)
public static void yieldToPendingWriteActions()
public static <T> T withTimeout(long timeoutMs, Computable<T> computation)
ProgressIndicator
, runs the computation with that indicator and cancels it after the the timeout.
The computation should call ProgressManager.checkCanceled()
frequently enough, so that after the timeout has been exceeded
it can stop the execution by throwing ProcessCanceledException
, which will be caught by this withTimeout
.
If a ProcessCanceledException
happens due to any other reason (e.g. a thread's progress indicator got canceled),
it'll be thrown out of this method.null
if timeout has been exceeded.public static <T,E extends java.lang.Throwable> T computeWithLockAndCheckingCanceled(java.util.concurrent.locks.Lock lock, int timeout, java.util.concurrent.TimeUnit timeUnit, ThrowableComputable<T,E> computable) throws E extends java.lang.Throwable, ProcessCanceledException
E extends java.lang.Throwable
ProcessCanceledException
public static void awaitWithCheckCanceled(java.util.concurrent.CountDownLatch waiter)
public static <T> T awaitWithCheckCanceled(java.util.concurrent.Future<T> future)
public static <T> T awaitWithCheckCanceled(java.util.concurrent.Future<T> future, ProgressIndicator indicator)
public static void awaitWithCheckCanceled(java.util.concurrent.locks.Lock lock, int timeout, java.util.concurrent.TimeUnit timeUnit)
public static void checkCancelledEvenWithPCEDisabled(ProgressIndicator indicator)
public static void awaitWithCheckCanceled(Semaphore semaphore, ProgressIndicator indicator)