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]);
}
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();
}
Aggregations