use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class AbstractToolBeforeRunTask method execute.
public boolean execute(final DataContext context, final long executionId) {
final Semaphore targetDone = new Semaphore();
final Ref<Boolean> result = new Ref<>(false);
try {
ApplicationManager.getApplication().invokeAndWait(() -> ToolAction.runTool(myToolActionId, context, null, executionId, new ProcessAdapter() {
public void startNotified(final ProcessEvent event) {
targetDone.down();
}
@Override
public void processTerminated(ProcessEvent event) {
result.set(event.getExitCode() == 0);
targetDone.up();
}
}), ModalityState.NON_MODAL);
} catch (Exception e) {
LOG.error(e);
return false;
}
targetDone.waitFor();
return result.get();
}
use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class PotemkinProgress method ensureBackgroundThreadStarted.
private void ensureBackgroundThreadStarted(@NotNull Runnable action) {
Semaphore started = new Semaphore();
started.down();
ApplicationManager.getApplication().executeOnPooledThread(() -> ProgressManager.getInstance().runProcess(() -> {
started.up();
action.run();
}, this));
started.waitFor();
}
use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class UpdateRequestsQueue method waitUntilRefreshed.
@TestOnly
public void waitUntilRefreshed() {
while (true) {
final Semaphore semaphore = new Semaphore();
synchronized (myLock) {
if (!myRequestSubmitted && !myRequestRunning) {
return;
}
if (!myRequestRunning) {
myFuture.set(myExecutor.submit(new MyRunnable()));
}
semaphore.down();
myWaitingUpdateCompletionSemaphores.add(semaphore);
}
if (!semaphore.waitFor(100 * 1000)) {
LOG.error("Too long VCS update");
return;
}
}
}
use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class ChangeListManagerImpl method waitUpdateAlarm.
// this is for perforce tests to ensure that LastSuccessfulUpdateTracker receives the event it needs
private void waitUpdateAlarm() {
final Semaphore semaphore = new Semaphore();
semaphore.down();
myScheduledExecutorService.execute(() -> semaphore.up());
semaphore.waitFor();
}
use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class LaterInvocator method invokeAndWait.
static void invokeAndWait(@NotNull final Runnable runnable, @NotNull ModalityState modalityState) {
LOG.assertTrue(!isDispatchThread());
final Semaphore semaphore = new Semaphore();
semaphore.down();
final Ref<Throwable> exception = Ref.create();
Runnable runnable1 = new Runnable() {
@Override
public void run() {
try {
runnable.run();
} catch (Throwable e) {
exception.set(e);
} finally {
semaphore.up();
}
}
@Override
@NonNls
public String toString() {
return "InvokeAndWait[" + runnable + "]";
}
};
invokeLater(runnable1, modalityState);
semaphore.waitFor();
if (!exception.isNull()) {
Throwable cause = exception.get();
if (SystemPropertyUtil.getBoolean("invoke.later.wrap.error", true)) {
// also TC ComparisonFailure feature depends on this
throw new RuntimeException(cause);
} else {
ExceptionUtil.rethrow(cause);
}
}
}
Aggregations