Search in sources :

Example 46 with Semaphore

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();
}
Also used : Ref(com.intellij.openapi.util.Ref) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) Semaphore(com.intellij.util.concurrency.Semaphore)

Example 47 with Semaphore

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();
}
Also used : Semaphore(com.intellij.util.concurrency.Semaphore)

Example 48 with Semaphore

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;
        }
    }
}
Also used : Semaphore(com.intellij.util.concurrency.Semaphore) TestOnly(org.jetbrains.annotations.TestOnly)

Example 49 with Semaphore

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();
}
Also used : Semaphore(com.intellij.util.concurrency.Semaphore)

Example 50 with Semaphore

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);
        }
    }
}
Also used : Semaphore(com.intellij.util.concurrency.Semaphore)

Aggregations

Semaphore (com.intellij.util.concurrency.Semaphore)74 Ref (com.intellij.openapi.util.Ref)10 Project (com.intellij.openapi.project.Project)8 IOException (java.io.IOException)8 Nullable (org.jetbrains.annotations.Nullable)8 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)7 NotNull (org.jetbrains.annotations.NotNull)7 Test (org.junit.Test)7 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 ProcessEvent (com.intellij.execution.process.ProcessEvent)5 File (java.io.File)5 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)4 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)4 Disposable (com.intellij.openapi.Disposable)4 Application (com.intellij.openapi.application.Application)4 Task (com.intellij.openapi.progress.Task)4 VcsAbstractHistorySession (com.intellij.openapi.vcs.history.VcsAbstractHistorySession)4 VcsAppendableHistorySessionPartner (com.intellij.openapi.vcs.history.VcsAppendableHistorySessionPartner)4 VcsHistoryProvider (com.intellij.openapi.vcs.history.VcsHistoryProvider)4