Search in sources :

Example 76 with Semaphore

use of com.intellij.util.concurrency.Semaphore in project Perl5-IDEA by Camelcade.

the class PerlDebugThread method loadRemoteSource.

@Nullable
public VirtualFile loadRemoteSource(String filePath) {
    if (DEV_MODE) {
        LOG.debug("Loading file " + filePath);
    }
    final Semaphore responseSemaphore = new Semaphore();
    responseSemaphore.down();
    final String[] response = new String[] { "# Source could not be loaded..." };
    PerlDebuggingTransactionHandler perlDebuggingTransactionHandler = new PerlDebuggingTransactionHandler() {

        @Override
        public void run(JsonObject eventObject, JsonDeserializationContext jsonDeserializationContext) {
            response[0] = eventObject.getAsJsonPrimitive("data").getAsString();
            responseSemaphore.up();
        }
    };
    if (mySocket != null) {
        sendCommandAndGetResponse("get_source", new PerlSourceRequestDescriptor(filePath), perlDebuggingTransactionHandler);
        responseSemaphore.waitFor(2000);
    }
    return myPerlRemoteFileSystem.registerRemoteFile(filePath, response[0]);
}
Also used : JsonDeserializationContext(com.google.gson.JsonDeserializationContext) JsonObject(com.google.gson.JsonObject) Semaphore(com.intellij.util.concurrency.Semaphore) Nullable(org.jetbrains.annotations.Nullable)

Example 77 with Semaphore

use of com.intellij.util.concurrency.Semaphore in project moe-ide-integration by multi-os-engine.

the class MOEGradleTaskProvider method executeTask.

@Override
public boolean executeTask(DataContext context, final RunConfiguration configuration, final ExecutionEnvironment env, MOEGradleTask task) {
    final AtomicBoolean success = new AtomicBoolean();
    final AtomicReference<String> errorMsgRef = new AtomicReference<String>();
    try {
        final Semaphore doneSemaphore = new Semaphore();
        doneSemaphore.down();
        final MOERunConfiguration runConfig = (MOERunConfiguration) configuration;
        isOpenDialog = runConfig.getOpenDeploymentTargetDialog();
        final MOEGradleRunner gradleRunner = new MOEGradleRunner(env.getProject(), "Building MOE application", runConfig);
        final MOEAfterGradleInvocationTask afterTask = new MOEAfterGradleInvocationTask() {

            @Override
            public void execute(@NotNull MOEGradleInvocationResult result) {
                LOG.debug("MOE application gradle build ended");
                success.set(result.isBuildSuccessful());
                errorMsgRef.set(result.getErrorMessage());
                gradleRunner.removeAfterTask(this);
                doneSemaphore.up();
            }
        };
        gradleRunner.addAfterTask(afterTask);
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                if (ApplicationManager.getApplication().isDispatchThread()) {
                    showDialog(runConfig);
                    gradleRunner.queue();
                } else {
                    UIUtil.invokeAndWaitIfNeeded(new Runnable() {

                        @Override
                        public void run() {
                            showDialog(runConfig);
                            gradleRunner.queue();
                        }
                    });
                }
            }
        });
        doneSemaphore.waitFor();
    } catch (Exception e) {
        Log.debug("Unable execute task", e);
        return false;
    }
    ApplicationManager.getApplication().invokeLater(new Runnable() {

        @Override
        public void run() {
            String errorMessage = errorMsgRef.get();
            if (errorMessage != null) {
                MOEToolWindow toolWindow = MOEToolWindow.getInstance(env.getProject());
                toolWindow.printErrorMessage(errorMessage);
            }
        }
    });
    return success.get();
}
Also used : MOERunConfiguration(org.moe.idea.runconfig.configuration.MOERunConfiguration) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(com.intellij.util.concurrency.Semaphore) NotNull(org.jetbrains.annotations.NotNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MOEToolWindow(org.moe.idea.ui.MOEToolWindow)

Aggregations

Semaphore (com.intellij.util.concurrency.Semaphore)77 Ref (com.intellij.openapi.util.Ref)10 NotNull (org.jetbrains.annotations.NotNull)9 Nullable (org.jetbrains.annotations.Nullable)9 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)8 Project (com.intellij.openapi.project.Project)8 IOException (java.io.IOException)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 Test (org.junit.Test)7 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)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