Java Code Examples for com.intellij.util.TimeoutUtil#sleep()
The following examples show how to use
com.intellij.util.TimeoutUtil#sleep() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PsiCustomUtil.java From intellij-spring-assistant with MIT License | 6 votes |
public static boolean isValidType(@NotNull PsiType type) { if (!type.isValid()) { TimeoutUtil.sleep( 1); // to see if processing in another thread suddenly makes the type valid again (which is a bug) if (!type.isValid()) { return false; } } if (type instanceof PsiArrayType) { return isValidType(PsiArrayType.class.cast(type).getComponentType()); } else if (type instanceof PsiWildcardType) { PsiType bound = ((PsiWildcardType) type).getBound(); return bound != null && isValidType(bound); } else if (type instanceof PsiCapturedWildcardType) { PsiType lowerBound = ((PsiCapturedWildcardType) type).getLowerBound(); type = (lowerBound != NULL ? lowerBound : ((PsiCapturedWildcardType) type).getUpperBound()); return type != NULL && isValidType(type); } else if (type instanceof PsiClassType) { PsiClassType.ClassResolveResult classResolveResult = ((PsiClassType) type).resolveGenerics(); return classResolveResult.isValidResult() && isValidElement( requireNonNull(classResolveResult.getElement())) && !hasUnresolvedComponents(type); } return true; }
Example 2
Source File: DirDiffTableModel.java From consulo with Apache License 2.0 | 6 votes |
@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; } }
Example 3
Source File: FileWatcherTest.java From consulo with Apache License 2.0 | 6 votes |
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); } }
Example 4
Source File: FileWatcherTest.java From consulo with Apache License 2.0 | 6 votes |
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); } }
Example 5
Source File: FileAttributesReadingTest.java From consulo with Apache License 2.0 | 6 votes |
@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); }
Example 6
Source File: AsyncFilterRunner.java From consulo with Apache License 2.0 | 6 votes |
boolean waitForPendingFilters(long timeoutMs) { ApplicationManager.getApplication().assertIsDispatchThread(); long started = System.currentTimeMillis(); while (true) { if (myQueue.isEmpty()) { // results are available before queue is emptied, so process the last results, if any, and exit highlightAvailableResults(); return true; } if (hasResults()) { highlightAvailableResults(); continue; } if (System.currentTimeMillis() - started > timeoutMs) { return false; } TimeoutUtil.sleep(1); } }
Example 7
Source File: MappedBufferWrapper.java From consulo with Apache License 2.0 | 6 votes |
@Override public void flush() { MappedByteBuffer buffer = myBuffer; if (buffer != null && isDirty()) { for (int i = 0; i < MAX_FORCE_ATTEMPTS; i++) { try { buffer.force(); myDirty = false; break; } catch (Throwable e) { Logger.getInstance(MappedBufferWrapper.class).info(e); TimeoutUtil.sleep(10); } } } }
Example 8
Source File: VcsInitialization.java From consulo with Apache License 2.0 | 6 votes |
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())); } }
Example 9
Source File: PsiCustomUtil.java From intellij-spring-assistant with MIT License | 5 votes |
/** * 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. */ // Copied & modified from PsiUtilCore.ensureValid private static boolean isValidElement(@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) return element.isValid(); } return true; }
Example 10
Source File: PrefetchIndexingTask.java From intellij with Apache License 2.0 | 5 votes |
@Override public void performInDumbMode(ProgressIndicator indicator) { indicator.setIndeterminate(true); indicator.setText("Prefetching files..."); while (!future.isCancelled() && !future.isDone()) { indicator.checkCanceled(); TimeoutUtil.sleep(50); } long end = System.currentTimeMillis(); logger.info(String.format("%s took: %d ms", taskName, (end - startTimeMillis))); }
Example 11
Source File: PsiUtilCore.java From consulo with Apache License 2.0 | 5 votes |
public static void ensureValid(@Nonnull 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); } }
Example 12
Source File: OutOfMemoryDialog.java From consulo with Apache License 2.0 | 5 votes |
@SuppressWarnings("SSBasedInspection") private void snapshot() { enableControls(false); myDumpMessageLabel.setVisible(true); myDumpMessageLabel.setText("Dumping memory..."); Runnable task = () -> { TimeoutUtil.sleep(250); // to give UI chance to update String message = ""; try { String name = ApplicationNamesInfo.getInstance().getFullProductName().replace(' ', '-').toLowerCase(Locale.US); String path = SystemProperties.getUserHome() + File.separator + "heapDump-" + name + '-' + System.currentTimeMillis() + ".hprof.zip"; MemoryDumpHelper.captureMemoryDumpZipped(path); message = "Dumped to " + path; } catch (Throwable t) { message = "Error: " + t.getMessage(); } finally { final String _message = message; SwingUtilities.invokeLater(() -> { myDumpMessageLabel.setText(_message); enableControls(true); }); } }; new Thread(task, "OOME Heap Dump").start(); }
Example 13
Source File: Preloader.java From consulo with Apache License 2.0 | 4 votes |
private static void checkHeavyProcessRunning() { if (HeavyProcessLatch.INSTANCE.isRunning()) { TimeoutUtil.sleep(1); } }