use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class ExecutionHelper method createTimeLimitedExecutionProcess.
private static Runnable createTimeLimitedExecutionProcess(final ProcessHandler processHandler, final ExecutionMode mode, @NotNull final String presentableCmdline) {
return new Runnable() {
private final Semaphore mySemaphore = new Semaphore();
private final Runnable myProcessThread = () -> {
try {
final boolean finished = processHandler.waitFor(1000 * mode.getTimeout());
if (!finished) {
mode.getTimeoutCallback().consume(mode, presentableCmdline);
processHandler.destroyProcess();
}
} finally {
mySemaphore.up();
}
};
@Override
public void run() {
mySemaphore.down();
ApplicationManager.getApplication().executeOnPooledThread(myProcessThread);
mySemaphore.waitFor();
}
};
}
use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class SvnAuthenticationTest method synchronousBackground.
private static void synchronousBackground(final Runnable runnable) throws InterruptedException {
final Semaphore semaphore = new Semaphore();
semaphore.down();
ApplicationManager.getApplication().executeOnPooledThread((Runnable) () -> {
try {
runnable.run();
} finally {
semaphore.up();
}
});
semaphore.waitFor();
}
use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class SvnHistoryTest method testLocallyMovedToRenamedDirectory.
@Test
public void testLocallyMovedToRenamedDirectory() throws Exception {
enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE);
myCnt = 0;
final VcsHistoryProvider provider = SvnVcs.getInstance(myProject).getVcsHistoryProvider();
final SubTree tree = new SubTree(myWorkingCopyDir);
checkin();
for (int i = 0; i < 10; i++) {
VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3\n4\n" + i);
checkin();
}
VcsTestUtil.renameFileInCommand(myProject, tree.myTargetDir, "renamedTarget");
VcsTestUtil.moveFileInCommand(myProject, tree.myS1File, tree.myTargetDir);
VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
ChangeListManager.getInstance(myProject).ensureUpToDate(false);
final Semaphore semaphore = new Semaphore();
semaphore.down();
provider.reportAppendableHistory(VcsUtil.getFilePath(tree.myS1File), new VcsAppendableHistorySessionPartner() {
@Override
public void reportCreatedEmptySession(VcsAbstractHistorySession session) {
}
@Override
public void acceptRevision(VcsFileRevision revision) {
++myCnt;
}
@Override
public void reportException(VcsException exception) {
throw new RuntimeException(exception);
}
@Override
public void finished() {
semaphore.up();
}
@Override
public void beforeRefresh() {
}
@Override
public void forceRefresh() {
}
});
semaphore.waitFor(1000);
Assert.assertEquals(11, myCnt);
myCnt = 0;
semaphore.down();
provider.reportAppendableHistory(VcsUtil.getFilePath(tree.myTargetDir), new VcsAppendableHistorySessionPartner() {
@Override
public void reportCreatedEmptySession(VcsAbstractHistorySession session) {
}
@Override
public void acceptRevision(VcsFileRevision revision) {
++myCnt;
}
@Override
public void reportException(VcsException exception) {
throw new RuntimeException(exception);
}
@Override
public void finished() {
semaphore.up();
}
@Override
public void beforeRefresh() {
}
@Override
public void forceRefresh() {
}
});
semaphore.waitFor(1000);
Assert.assertEquals(1, myCnt);
myCnt = 0;
semaphore.down();
provider.reportAppendableHistory(VcsUtil.getFilePath(tree.myTargetFiles.get(0)), new VcsAppendableHistorySessionPartner() {
@Override
public void reportCreatedEmptySession(VcsAbstractHistorySession session) {
}
@Override
public void acceptRevision(VcsFileRevision revision) {
++myCnt;
}
@Override
public void reportException(VcsException exception) {
throw new RuntimeException(exception);
}
@Override
public void finished() {
semaphore.up();
}
@Override
public void beforeRefresh() {
}
@Override
public void forceRefresh() {
}
});
semaphore.waitFor(1000);
Assert.assertEquals(1, myCnt);
}
use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class ConnectionOnProcess method waitForProcess.
private void waitForProcess(Application application) {
myWaitSemaphore = new Semaphore();
myWaitSemaphore.down();
myWaitForThreadFuture = application.executeOnPooledThread(() -> {
try {
myProcess.waitFor();
} catch (InterruptedException ignored) {
} finally {
myWaitSemaphore.up();
}
});
}
use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class ProcessCloseUtil method close.
public static void close(final Process process) {
final Semaphore outerSemaphore = new Semaphore();
outerSemaphore.down();
final Application application = ApplicationManager.getApplication();
application.executeOnPooledThread(() -> {
try {
final Semaphore semaphore = new Semaphore();
semaphore.down();
final Runnable closeRunnable = () -> {
try {
closeProcessImpl(process);
} finally {
semaphore.up();
}
};
final Future<?> innerFuture = application.executeOnPooledThread(closeRunnable);
semaphore.waitFor(ourAsynchronousWaitTimeout);
if (!(innerFuture.isDone() || innerFuture.isCancelled())) {
// will call interrupt()
innerFuture.cancel(true);
}
} finally {
outerSemaphore.up();
}
});
// just wait
outerSemaphore.waitFor(ourSynchronousWaitTimeout);
}
Aggregations