Java 类com.intellij.util.TimeoutUtil 实例源码

项目:educational-plugin    文件:StudyUtils.java   
@Nullable
public static <T> T execCancelable(@NotNull final Callable<T> callable) {
  final Future<T> future = ApplicationManager.getApplication().executeOnPooledThread(callable);

  while (!future.isCancelled() && !future.isDone()) {
    ProgressManager.checkCanceled();
    TimeoutUtil.sleep(500);
  }
  T result = null;
  try {
    result = future.get();
  }
  catch (InterruptedException | ExecutionException e) {
    LOG.warn(e.getMessage());
  }
  return result;
}
项目:intellij-ce-playground    文件:DirDiffTableModel.java   
@Override
public void run() {
  if (!myDisposed && myLoadingPanel.isLoading()) {
    TimeoutUtil.sleep(mySleep);
    ApplicationManager.getApplication().invokeLater(new Runnable() {
      @Override
      public void run() {
        final String s = text.get();
        if (s != null && myLoadingPanel.isLoading()) {
          myLoadingPanel.setLoadingText(s);
        }
      }
    }, ModalityState.stateForComponent(myLoadingPanel));
    myUpdater = new Updater(myLoadingPanel, mySleep);
    myUpdater.start();
  } else {
    myUpdater = null;
    myPanel.focusTable();
  }
}
项目:intellij-ce-playground    文件:ProjectManagerImpl.java   
private static void waitForFileWatcher(@NotNull ProgressIndicator indicator) {
  LocalFileSystem fs = LocalFileSystem.getInstance();
  if (!(fs instanceof LocalFileSystemImpl)) return;

  final FileWatcher watcher = ((LocalFileSystemImpl)fs).getFileWatcher();
  if (!watcher.isOperational() || !watcher.isSettingRoots()) return;

  LOG.info("FW/roots waiting started");
  indicator.setIndeterminate(true);
  indicator.setText(ProjectBundle.message("project.load.waiting.watcher"));
  if (indicator instanceof ProgressWindow) {
    ((ProgressWindow)indicator).setCancelButtonText(CommonBundle.message("button.skip"));
  }
  while (watcher.isSettingRoots() && !indicator.isCanceled()) {
    TimeoutUtil.sleep(10);
  }
  LOG.info("FW/roots waiting finished");
}
项目:intellij-ce-playground    文件:AddManyTestProcesses.java   
@Override
public void actionPerformed(AnActionEvent e) {
  final Project project = e.getData(CommonDataKeys.PROJECT);
  for (int i = 0; i < 100; i++) {
    new Task.Backgroundable(project, "Test Process", true, PerformInBackgroundOption.ALWAYS_BACKGROUND) {
      public void run(@NotNull final ProgressIndicator indicator) {
        for (int j = 0; j < 10000; j++) {
          TimeoutUtil.sleep(1);
          indicator.setText("foo " + j);
        }
      }
    }.queue();

  }

}
项目:intellij-ce-playground    文件:ToggleDumbModeAction.java   
public void actionPerformed(final AnActionEvent e) {
  if (myDumb) {
    myDumb = false;
  }
  else {
    myDumb = true;
    final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
    if (project == null) return;

    DumbServiceImpl.getInstance(project).queueTask(new DumbModeTask() {
      @Override
      public void performInDumbMode(@NotNull ProgressIndicator indicator) {
        while (myDumb) {
          indicator.checkCanceled();
          TimeoutUtil.sleep(100);
        }
      }
    });
  }
}
项目:intellij-ce-playground    文件:ShowDelayedMessageInternalAction.java   
@Override
public void actionPerformed(AnActionEvent e) {

  new Thread("show delayed msg") {
    @Override
    public void run() {
      super.run();

      //noinspection EmptyCatchBlock
      TimeoutUtil.sleep(3000);

      //noinspection SSBasedInspection
      SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
          MessageDialogBuilder.yesNo("Nothing happens after that", "Some message goes here").yesText(
            ApplicationBundle.message("command.exit")).noText(
            CommonBundle.message("button.cancel")).show();
        }
      });
    }
  }.start();

}
项目:intellij-ce-playground    文件:ApplicationImplTest.java   
public void testProgressVsReadAction() throws Throwable {
  ProgressManager.getInstance().runProcessWithProgressSynchronously((ThrowableComputable<Void, Exception>)() -> {
    try {
      assertFalse(ApplicationManager.getApplication().isReadAccessAllowed());
      assertFalse(ApplicationManager.getApplication().isDispatchThread());
      for (int i=0; i<100;i++) {
        SwingUtilities.invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> {
          TimeoutUtil.sleep(20);
        }));
        ApplicationManager.getApplication().runReadAction(() -> {
          TimeoutUtil.sleep(20);
        });
      }
    }
    catch (Exception e) {
      exception = e;
    }
    return null;
  }, "cc", false, getProject());
  if (exception != null) throw exception;
}
项目:intellij-ce-playground    文件:JobUtilTest.java   
public void testJobWaitForTerminationAfterCancelInTheMiddleOfTheExecutionWaitsUntilFinished() throws Exception {
  for (int i=0; i<100; i++) {
    final AtomicBoolean finished = new AtomicBoolean();
    final AtomicBoolean started = new AtomicBoolean();
    Job<Void> job = JobLauncher.getInstance().submitToJobThread(new Runnable() {
      @Override
      public void run() {
        started.set(true);
        TimeoutUtil.sleep(100);
        finished.set(true);
      }
    }, null);
    assertFalse(job.isDone());
    while (!started.get());
    job.cancel();
    job.waitForCompletion(100000);
    assertTrue(finished.get());
  }
}
项目:intellij-ce-playground    文件:FileWatcherTest.java   
public void testDirectoryRecreation() throws Exception {
  File rootDir = createTestDir(myTempDirectory, "root");
  File topDir = createTestDir(rootDir, "top");
  File file1 = createTestFile(topDir, "file1.txt", "abc");
  File file2 = createTestFile(topDir, "file2.txt", "123");
  refresh(topDir);

  LocalFileSystem.WatchRequest request = watch(rootDir);
  try {
    myAccept = true;
    assertTrue(FileUtil.delete(topDir));
    assertTrue(topDir.mkdir());
    TimeoutUtil.sleep(100);
    assertTrue(file1.createNewFile());
    assertTrue(file2.createNewFile());
    assertEvent(VFileContentChangeEvent.class, file1.getPath(), file2.getPath());
  }
  finally {
    unwatch(request);
    delete(topDir);
  }
}
项目:intellij-ce-playground    文件:FileWatcherTest.java   
public void testWatchRootRecreation() throws Exception {
  File rootDir = createTestDir(myTempDirectory, "root");
  File file1 = createTestFile(rootDir, "file1.txt", "abc");
  File file2 = createTestFile(rootDir, "file2.txt", "123");
  refresh(rootDir);

  LocalFileSystem.WatchRequest request = watch(rootDir);
  try {
    myAccept = true;
    assertTrue(FileUtil.delete(rootDir));
    assertTrue(rootDir.mkdir());
    if (SystemInfo.isLinux) TimeoutUtil.sleep(1500);  // implementation specific
    assertTrue(file1.createNewFile());
    assertTrue(file2.createNewFile());
    assertEvent(VFileContentChangeEvent.class, file1.getPath(), file2.getPath());
  }
  finally {
    unwatch(request);
    delete(rootDir);
  }
}
项目:intellij-ce-playground    文件:FileAttributesReadingTest.java   
@Test
public void stamps() throws Exception {
  FileAttributes attributes = FileSystemUtil.getAttributes(myTempDirectory);
  assumeTrue(attributes != null && attributes.lastModified > (attributes.lastModified/1000)*1000);

  long t1 = System.currentTimeMillis();
  TimeoutUtil.sleep(10);
  File file = IoTestUtil.createTestFile(myTempDirectory, "test.txt");
  TimeoutUtil.sleep(10);
  long t2 = System.currentTimeMillis();
  attributes = getAttributes(file);
  assertTrue(attributes.lastModified + " not in " + t1 + ".." + t2, t1 <= attributes.lastModified && attributes.lastModified <= t2);

  t1 = System.currentTimeMillis();
  TimeoutUtil.sleep(10);
  FileUtil.writeToFile(file, myTestData);
  TimeoutUtil.sleep(10);
  t2 = System.currentTimeMillis();
  attributes = getAttributes(file);
  assertTrue(attributes.lastModified + " not in " + t1 + ".." + t2, t1 <= attributes.lastModified && attributes.lastModified <= t2);

  ProcessBuilder cmd = SystemInfo.isWindows ? new ProcessBuilder("attrib", "-A", file.getPath()) : new ProcessBuilder("chmod", "644", file.getPath());
  assertEquals(0, cmd.start().waitFor());
  attributes = getAttributes(file);
  assertTrue(attributes.lastModified + " not in " + t1 + ".." + t2, t1 <= attributes.lastModified && attributes.lastModified <= t2);
}
项目:intellij-ce-playground    文件:RemoteDebugger.java   
protected void doRun() {
  try {
    while (true) {
      boolean read = readAvailableBlocking();

      if (!read) {
        break;
      }
      else {
        if (isStopped) {
          break;
        }

        TimeoutUtil.sleep(mySleepingPolicy.getTimeToSleep(true));
      }
    }
  }
  catch (Exception e) {
    fireCommunicationError();
  }
  finally {
    close();
    fireExitEvent();
  }
}
项目:intellij-ce-playground    文件:PydevConsoleRunner.java   
private boolean handshake() {
  boolean res;
  long started = System.currentTimeMillis();
  do {
    try {
      res = myPydevConsoleCommunication.handshake();
    }
    catch (XmlRpcException ignored) {
      res = false;
    }
    if (res) {
      break;
    }
    else {
      long now = System.currentTimeMillis();
      if (now - started > APPROPRIATE_TO_WAIT) {
        break;
      }
      else {
        TimeoutUtil.sleep(100);
      }
    }
  }
  while (true);
  return res;
}
项目:intellij-ce-playground    文件:RepeatSvnActionThroughBusy.java   
public void execute() throws VcsException {
  while (true) {
    try {
      executeImpl();
      break;
    }
    catch (VcsException e) {
      if (ourBusyExceptionProcessor.process(e)) {
        if (myCnt > 0) {
          TimeoutUtil.sleep(myTimeout * (REPEAT - myCnt + 1));
          -- myCnt;
          continue;
        }
      }
      throw e;
    }
  }
}
项目:intellij-ce-playground    文件:SvnExternalCommitNoticedTest.java   
@Test
public void testSimpleCommit() throws Exception {
  final SubTree tree = new SubTree(myWorkingCopyDir);
  checkin();

  VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "test1");
  VcsTestUtil.editFileInCommand(myProject, tree.myS2File, "test2");
  VcsTestUtil.editFileInCommand(myProject, tree.myTargetFiles.get(1), "target1");

  myVcsDirtyScopeManager.markEverythingDirty();
  clManager.ensureUpToDate(false);
  Assert.assertEquals(3, clManager.getChangesIn(myWorkingCopyDir).size());

  TimeoutUtil.sleep(100);

  checkin();

  myWorkingCopyDir.refresh(false, true);
  imitateEvent(myWorkingCopyDir);
  // no dirty scope externally provided! just VFS refresh
  clManager.ensureUpToDate(false);
  Assert.assertEquals(0, clManager.getChangesIn(myWorkingCopyDir).size());
}
项目:intellij-ce-playground    文件:SvnExternalCommitNoticedTest.java   
@Test
public void testRenameDirCommit() throws Exception {
  final SubTree tree = new SubTree(myWorkingCopyDir);
  checkin();

  VcsTestUtil.renameFileInCommand(myProject, tree.myTargetDir, "aabbcc");

  myVcsDirtyScopeManager.markEverythingDirty();
  clManager.ensureUpToDate(false);
  Assert.assertEquals(11, clManager.getChangesIn(myWorkingCopyDir).size());

  TimeoutUtil.sleep(100);

  checkin();

  myWorkingCopyDir.refresh(false, true);
  imitateEvent(myWorkingCopyDir);
  // no dirty scope externally provided! just VFS refresh
  clManager.ensureUpToDate(false);
  Assert.assertEquals(0, clManager.getChangesIn(myWorkingCopyDir).size());
}
项目:intellij-ce-playground    文件:SvnCachingRepositoryPoolTest.java   
@Test
public void testCloseWorker() throws Exception {
  final SvnIdeaRepositoryPoolManager poolManager = new SvnIdeaRepositoryPoolManager(true, null, null);
  final ApplicationLevelNumberConnectionsGuardImpl guard = SvnIdeaRepositoryPoolManager.getOurGuard();
  guard.setDelay(20);
  ((CachingSvnRepositoryPool) poolManager.getPool()).setConnectionTimeout(20);
  testBigFlow(poolManager, false);
  TimeoutUtil.sleep(50);
  Assert.assertEquals(0, guard.getCurrentlyActiveConnections());
  final CachingSvnRepositoryPool pool = (CachingSvnRepositoryPool) poolManager.getPool();
  Map<String,CachingSvnRepositoryPool.RepoGroup> groups = pool.getGroups();
  Assert.assertEquals(1, groups.size());
  CachingSvnRepositoryPool.RepoGroup group = groups.values().iterator().next();
  Assert.assertEquals(0, group.getUsedSize());
  Assert.assertEquals(0, group.getInactiveSize());  // !!!
  poolManager.dispose();
  checkAfterDispose(poolManager);
}
项目:intellij-ce-playground    文件:SvnExternalCommitNoticedTest.java   
@Test
public void testSimpleCommit() throws Exception {
  final SubTree tree = new SubTree(myWorkingCopyDir);
  checkin();

  VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "test1");
  VcsTestUtil.editFileInCommand(myProject, tree.myS2File, "test2");
  VcsTestUtil.editFileInCommand(myProject, tree.myTargetFiles.get(1), "target1");

  myVcsDirtyScopeManager.markEverythingDirty();
  clManager.ensureUpToDate(false);
  Assert.assertEquals(3, clManager.getChangesIn(myWorkingCopyDir).size());

  TimeoutUtil.sleep(100);

  checkin();

  myWorkingCopyDir.refresh(false, true);
  imitateEvent(myWorkingCopyDir);
  // no dirty scope externally provided! just VFS refresh
  clManager.ensureUpToDate(false);
  Assert.assertEquals(0, clManager.getChangesIn(myWorkingCopyDir).size());
}
项目:intellij-ce-playground    文件:SvnExternalCommitNoticedTest.java   
@Test
public void testRenameDirCommit() throws Exception {
  final SubTree tree = new SubTree(myWorkingCopyDir);
  checkin();

  VcsTestUtil.renameFileInCommand(myProject, tree.myTargetDir, "aabbcc");

  myVcsDirtyScopeManager.markEverythingDirty();
  clManager.ensureUpToDate(false);
  Assert.assertEquals(11, clManager.getChangesIn(myWorkingCopyDir).size());

  TimeoutUtil.sleep(100);

  checkin();

  myWorkingCopyDir.refresh(false, true);
  imitateEvent(myWorkingCopyDir);
  // no dirty scope externally provided! just VFS refresh
  clManager.ensureUpToDate(false);
  Assert.assertEquals(0, clManager.getChangesIn(myWorkingCopyDir).size());
}
项目:tools-idea    文件:ProjectManagerImpl.java   
private void waitForFileWatcher(@NotNull Project project) {
  LocalFileSystem fs = LocalFileSystem.getInstance();
  if (!(fs instanceof LocalFileSystemImpl)) return;

  final FileWatcher watcher = ((LocalFileSystemImpl)fs).getFileWatcher();
  if (!watcher.isOperational() || !watcher.isSettingRoots()) return;

  LOG.info("FW/roots waiting started");
  Task.Modal task = new Task.Modal(project, ProjectBundle.message("project.load.progress"), true) {
    @Override
    public void run(@NotNull ProgressIndicator indicator) {
      indicator.setIndeterminate(true);
      indicator.setText(ProjectBundle.message("project.load.waiting.watcher"));
      if (indicator instanceof ProgressWindow) {
        ((ProgressWindow)indicator).setCancelButtonText(CommonBundle.message("button.skip"));
      }
      while (watcher.isSettingRoots() && !indicator.isCanceled()) {
        TimeoutUtil.sleep(10);
      }
      LOG.info("FW/roots waiting finished");
    }
  };
  myProgressManager.run(task);
}
项目:tools-idea    文件:FileWatcherTest.java   
public void testDirectoryRecreation() throws Exception {
  File rootDir = createTestDir("root");
  File topDir = createTestDir(rootDir, "top");
  File file1 = createTestFile(topDir, "file1.txt", "abc");
  File file2 = createTestFile(topDir, "file2.txt", "123");
  refresh(topDir);

  LocalFileSystem.WatchRequest request = watch(rootDir);
  try {
    myAccept = true;
    assertTrue(FileUtil.delete(topDir));
    assertTrue(topDir.mkdir());
    TimeoutUtil.sleep(100);
    assertTrue(file1.createNewFile());
    assertTrue(file2.createNewFile());
    assertEvent(VFileContentChangeEvent.class, file1.getPath(), file2.getPath());
  }
  finally {
    unwatch(request);
    delete(topDir);
  }
}
项目:tools-idea    文件:FileWatcherTest.java   
public void testWatchRootRecreation() throws Exception {
  File rootDir = createTestDir("root");
  File file1 = createTestFile(rootDir, "file1.txt", "abc");
  File file2 = createTestFile(rootDir, "file2.txt", "123");
  refresh(rootDir);

  LocalFileSystem.WatchRequest request = watch(rootDir);
  try {
    myAccept = true;
    assertTrue(FileUtil.delete(rootDir));
    assertTrue(rootDir.mkdir());
    if (SystemInfo.isLinux) TimeoutUtil.sleep(1500);  // implementation specific
    assertTrue(file1.createNewFile());
    assertTrue(file2.createNewFile());
    assertEvent(VFileContentChangeEvent.class, file1.getPath(), file2.getPath());
  }
  finally {
    unwatch(request);
    delete(rootDir);
  }
}
项目:tools-idea    文件:FileAttributesReadingTest.java   
@Test
public void stamps() throws Exception {
  FileAttributes attributes = FileSystemUtil.getAttributes(myTempDirectory);
  assumeTrue(attributes != null && attributes.lastModified > (attributes.lastModified/1000)*1000);

  long t1 = System.currentTimeMillis();
  TimeoutUtil.sleep(10);
  File file = IoTestUtil.createTestFile(myTempDirectory, "test.txt");
  TimeoutUtil.sleep(10);
  long t2 = System.currentTimeMillis();
  attributes = getAttributes(file);
  assertTrue(attributes.lastModified + " not in " + t1 + ".." + t2, t1 <= attributes.lastModified && attributes.lastModified <= t2);

  t1 = System.currentTimeMillis();
  TimeoutUtil.sleep(10);
  FileUtil.writeToFile(file, myTestData);
  TimeoutUtil.sleep(10);
  t2 = System.currentTimeMillis();
  attributes = getAttributes(file);
  assertTrue(attributes.lastModified + " not in " + t1 + ".." + t2, t1 <= attributes.lastModified && attributes.lastModified <= t2);

  ProcessBuilder cmd = SystemInfo.isWindows ? new ProcessBuilder("attrib", "-A", file.getPath()) : new ProcessBuilder("chmod", "644", file.getPath());
  assertEquals(0, cmd.start().waitFor());
  attributes = getAttributes(file);
  assertTrue(attributes.lastModified + " not in " + t1 + ".." + t2, t1 <= attributes.lastModified && attributes.lastModified <= t2);
}
项目:consulo    文件:DirDiffTableModel.java   
@Override
public void run() {
  if (!myDisposed && myLoadingPanel.isLoading()) {
    TimeoutUtil.sleep(mySleep);
    ApplicationManager.getApplication().invokeLater(() -> {
      final String s = text.get();
      if (s != null && myLoadingPanel.isLoading()) {
        myLoadingPanel.setLoadingText(s);
      }
    }, ModalityState.stateForComponent(myLoadingPanel));
    myUpdater = new Updater(myLoadingPanel, mySleep);
    myUpdater.start();
  } else {
    myUpdater = null;
  }
}
项目:consulo    文件:FileWatcherTest.java   
public void testDirectoryRecreation() throws Exception {
  File rootDir = createTestDir("root");
  File topDir = createTestDir(rootDir, "top");
  File file1 = createTestFile(topDir, "file1.txt", "abc");
  File file2 = createTestFile(topDir, "file2.txt", "123");
  refresh(topDir);

  LocalFileSystem.WatchRequest request = watch(rootDir);
  try {
    myAccept = true;
    assertTrue(FileUtil.delete(topDir));
    assertTrue(topDir.mkdir());
    TimeoutUtil.sleep(100);
    assertTrue(file1.createNewFile());
    assertTrue(file2.createNewFile());
    assertEvent(VFileContentChangeEvent.class, file1.getPath(), file2.getPath());
  }
  finally {
    unwatch(request);
    delete(topDir);
  }
}
项目:consulo    文件:FileWatcherTest.java   
public void testWatchRootRecreation() throws Exception {
  File rootDir = createTestDir("root");
  File file1 = createTestFile(rootDir, "file1.txt", "abc");
  File file2 = createTestFile(rootDir, "file2.txt", "123");
  refresh(rootDir);

  LocalFileSystem.WatchRequest request = watch(rootDir);
  try {
    myAccept = true;
    assertTrue(FileUtil.delete(rootDir));
    assertTrue(rootDir.mkdir());
    if (SystemInfo.isLinux) TimeoutUtil.sleep(1500);  // implementation specific
    assertTrue(file1.createNewFile());
    assertTrue(file2.createNewFile());
    assertEvent(VFileContentChangeEvent.class, file1.getPath(), file2.getPath());
  }
  finally {
    unwatch(request);
    delete(rootDir);
  }
}
项目:consulo    文件:FileAttributesReadingTest.java   
@Test
public void stamps() throws Exception {
  FileAttributes attributes = FileSystemUtil.getAttributes(myTempDirectory);
  assumeTrue(attributes != null && attributes.lastModified > (attributes.lastModified/1000)*1000);

  long t1 = System.currentTimeMillis();
  TimeoutUtil.sleep(10);
  File file = IoTestUtil.createTestFile(myTempDirectory, "test.txt");
  TimeoutUtil.sleep(10);
  long t2 = System.currentTimeMillis();
  attributes = getAttributes(file);
  assertTrue(attributes.lastModified + " not in " + t1 + ".." + t2, t1 <= attributes.lastModified && attributes.lastModified <= t2);

  t1 = System.currentTimeMillis();
  TimeoutUtil.sleep(10);
  FileUtil.writeToFile(file, myTestData);
  TimeoutUtil.sleep(10);
  t2 = System.currentTimeMillis();
  attributes = getAttributes(file);
  assertTrue(attributes.lastModified + " not in " + t1 + ".." + t2, t1 <= attributes.lastModified && attributes.lastModified <= t2);

  ProcessBuilder cmd = SystemInfo.isWindows ? new ProcessBuilder("attrib", "-A", file.getPath()) : new ProcessBuilder("chmod", "644", file.getPath());
  assertEquals(0, cmd.start().waitFor());
  attributes = getAttributes(file);
  assertTrue(attributes.lastModified + " not in " + t1 + ".." + t2, t1 <= attributes.lastModified && attributes.lastModified <= t2);
}
项目:consulo    文件:ToggleDumbModeAction.java   
@Override
public void actionPerformed(final AnActionEvent e) {
  if (myDumb) {
    myDumb = false;
  }
  else {
    myDumb = true;
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null) return;

    DumbServiceImpl.getInstance(project).queueTask(new DumbModeTask() {
      @Override
      public void performInDumbMode(@Nonnull ProgressIndicator indicator) {
        while (myDumb) {
          indicator.checkCanceled();
          TimeoutUtil.sleep(100);
        }
      }
    });
  }
}
项目:consulo    文件:VcsInitialization.java   
private void waitFor(@Nonnull Predicate<Status> predicate) {
  LOG.debug("waitFor() status=" + myStatus);
  // have to wait for task completion to avoid running it in background for closed project
  long start = System.currentTimeMillis();
  Status status = null;
  while (System.currentTimeMillis() < start + 10000) {
    synchronized (myLock) {
      status = myStatus;
      if (predicate.test(status)) {
        break;
      }
    }
    TimeoutUtil.sleep(10);
  }
  if (status == Status.RUNNING) {
    LOG.error("Failed to wait for completion of VCS initialization for project " + myProject,
              new Attachment("thread dump", ThreadDumper.dumpThreadsToString()));
  }
}
项目:intellij-ce-playground    文件:JpsBuildTestCase.java   
protected static void sleepUntil(long time) {
  //we need this to ensure that the file won't be treated as changed by user during compilation and therefore marked for recompilation
  long delta;
  while ((delta = time - System.currentTimeMillis()) > 0) {
    TimeoutUtil.sleep(delta);
  }
}
项目:intellij-ce-playground    文件:DefaultJavaProgramRunner.java   
public void after() {
  if (myProject == null) {
    myProcessHandler.removeProcessListener(myListener);
    return;
  }
  ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
    @Override
    public void run() {
      if (myProcessHandler.isProcessTerminated() || myProcessHandler.isProcessTerminating()) return;
      List<ThreadState> threadStates = null;
      final long start = System.currentTimeMillis();
      while ((System.currentTimeMillis() - start) < 1000) {
        final String stdout = myListener.getOutput().getStdout();
        threadStates = ThreadDumpParser.parse(stdout);
        if (threadStates == null || threadStates.isEmpty()) {
          TimeoutUtil.sleep(50);
          threadStates = null;
          continue;
        }
        break;
      }
      myProcessHandler.removeProcessListener(myListener);
      if (threadStates != null && ! threadStates.isEmpty()) {
        showThreadDump(myListener.getOutput().getStdout(), threadStates);
      }
    }

  });
}
项目:intellij-ce-playground    文件:DefaultMessageHandler.java   
private boolean isDumbMode() {
  final DumbService dumbService = DumbService.getInstance(myProject);
  boolean isDumb = dumbService.isDumb();
  if (isDumb) {
    // wait some time
    for (int idx = 0; idx < 5; idx++) {
      TimeoutUtil.sleep(10L);
      isDumb = dumbService.isDumb();
      if (!isDumb) {
        break;
      }
    }
  }
  return isDumb;
}
项目:intellij-ce-playground    文件:DialogWrapper.java   
private void resizeWithAnimation(@NotNull final Dimension size) {
  //todo[kb]: fix this PITA
  myResizeInProgress = true;
  if (!Registry.is("enable.animation.on.dialogs")) {
    setSize(size.width, size.height);
    myResizeInProgress = false;
    return;
  }

  new Thread("DialogWrapper resizer") {
    int time = 200;
    int steps = 7;

    @Override
    public void run() {
      int step = 0;
      final Dimension cur = getSize();
      int h = (size.height - cur.height) / steps;
      int w = (size.width - cur.width) / steps;
      while (step++ < steps) {
        setSize(cur.width + w * step, cur.height + h * step);
        TimeoutUtil.sleep(time / steps);
      }
      setSize(size.width, size.height);
      //repaint();
      if (myErrorText.shouldBeVisible()) {
        myErrorText.setVisible(true);
      }
      myResizeInProgress = false;
    }
  }.start();
}
项目:intellij-ce-playground    文件:WorkerThread.java   
@Override
public void run() {
  while (true) {
    while (true) {
      Runnable task;
      synchronized (myTasks) {
        if (myTasks.isEmpty()) break;
        task = myTasks.removeFirst();
      }
      task.run();
      if (mySleep > 0) {
        TimeoutUtil.sleep(mySleep);
      }
    }

    synchronized (myTasks) {
      if (myToDispose && myTasks.isEmpty()) {
        myDisposed = true;
        return;
      }

      try {
        myTasks.wait();
      }
      catch (InterruptedException ignored) {
      }
    }
  }
}
项目:intellij-ce-playground    文件:PsiUtilCore.java   
/**
 * Checks if the element is valid. If not, throws {@link com.intellij.psi.PsiInvalidElementAccessException} with
 * a meaningful message that points to the reasons why the element is not valid and may contain the stack trace
 * when it was invalidated.
 */
public static void ensureValid(@NotNull PsiElement element) {
  if (!element.isValid()) {
    TimeoutUtil.sleep(1); // to see if processing in another thread suddenly makes the element valid again (which is a bug)
    if (element.isValid()) {
      LOG.error("PSI resurrected: " + element + " of " + element.getClass());
      return;
    }
    throw new PsiInvalidElementAccessException(element);
  }
}
项目:intellij-ce-playground    文件:ClipboardSynchronizer.java   
@Nullable
public Transferable getContents() throws IllegalStateException {
  IllegalStateException last = null;
  for (int i = 0; i < 3; i++) {
    try {
      return Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this);
    }
    catch (IllegalStateException e) {
      TimeoutUtil.sleep(50);
      last = e;
    }
  }
  throw last;
}
项目:intellij-ce-playground    文件:ClipboardSynchronizer.java   
public void setContent(@NotNull final Transferable content, @NotNull final ClipboardOwner owner) {
  for (int i = 0; i < 3; i++) {
    try {
      Toolkit.getDefaultToolkit().getSystemClipboard().setContents(content, owner);
    }
    catch (IllegalStateException e) {
      TimeoutUtil.sleep(50);
      continue;
    }
    break;
  }
}
项目:intellij-ce-playground    文件:ApplicationImplTest.java   
public void testRunProcessWithProgressSynchronouslyInReadActionWithPendingWriteAction() throws Throwable {
  SwingUtilities.invokeLater(() -> ApplicationManager.getApplication().runWriteAction(EmptyRunnable.getInstance()));
  boolean result = ((ApplicationEx)ApplicationManager.getApplication())
    .runProcessWithProgressSynchronouslyInReadAction(getProject(), "title", true, "cancel", null, () -> TimeoutUtil.sleep(10000));
  assertTrue(result);
  UIUtil.dispatchAllInvocationEvents();
  if (exception != null) throw exception;
}
项目:intellij-ce-playground    文件:JobUtilTest.java   
public void testAfterCancelInTheMiddleOfTheExecutionTaskIsDoneReturnsFalseUntilFinished() throws ExecutionException, InterruptedException {
  Random random = new Random();
  for (int i=0; i<100; i++) {
    final AtomicBoolean finished = new AtomicBoolean();
    final AtomicBoolean started = new AtomicBoolean();
    Job<Void> job = JobLauncher.getInstance().submitToJobThread(new Runnable() {
      @Override
      public void run() {
        started.set(true);
        TimeoutUtil.sleep(100);
        finished.set(true);
      }
    }, null);
    assertFalse(job.isDone());
    TimeoutUtil.sleep(random.nextInt(100));
    job.cancel();
    long start = System.currentTimeMillis();
    while (!job.isDone() && (started.get() || System.currentTimeMillis() < start + 2000)) {
      boolean wasDone = job.isDone();
      boolean wasStarted = started.get();
      boolean wasFinished = finished.get();
      if (wasStarted && !wasFinished) {
        assertFalse(wasDone);
      }
      // else no guarantees

      // but can be finished=true but done=false still
      if (wasDone) {
        assertTrue(wasFinished);
      }

    }
  }
}
项目:intellij-ce-playground    文件:HttpRequestsTest.java   
@Test(timeout = 5000, expected = SocketTimeoutException.class)
public void testReadTimeout() throws IOException {
  myServer.createContext("/", ex -> {
    TimeoutUtil.sleep(1000);
    ex.sendResponseHeaders(200, 0);
    ex.close();
  });

  String url = "http://" + LOCALHOST + ":" + myServer.getAddress().getPort();
  HttpRequests.request(url).readTimeout(50).readString(null);
  fail();
}