com.intellij.util.TimeoutUtil Java Examples
The following examples show how to use
com.intellij.util.TimeoutUtil.
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: 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 #2
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 #3
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 #4
Source File: ToggleDumbModeAction.java From consulo with Apache License 2.0 | 6 votes |
@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); } } }); } }
Example #5
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 #6
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 #7
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 #8
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 #9
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 #10
Source File: DialogWrapper.java From consulo with Apache License 2.0 | 5 votes |
private void resizeWithAnimation(@Nonnull 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(); }
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: 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 #13
Source File: DartVmServiceDebugProcess.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void scheduleConnect() { ApplicationManager.getApplication().executeOnPooledThread(() -> { // Poll, waiting for "flutter run" to give us a websocket. // Don't use a timeout - the user can cancel manually the operation. String url = myConnector.getWebSocketUrl(); while (url == null) { if (getSession().isStopped()) return; TimeoutUtil.sleep(100); url = myConnector.getWebSocketUrl(); } if (getSession().isStopped()) { return; } // "flutter run" has given us a websocket; we can assume it's ready immediately, because // "flutter run" has already connected to it. final VmService vmService; try { vmService = VmService.connect(url); } catch (IOException | RuntimeException e) { onConnectFailed("Failed to connect to the VM observatory service at: " + url + "\n" + e.toString() + "\n" + formatStackTraces(e)); return; } onConnectSucceeded(vmService); }); }
Example #14
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 #15
Source File: DartVmServiceDebugProcess.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void scheduleConnect() { ApplicationManager.getApplication().executeOnPooledThread(() -> { // Poll, waiting for "flutter run" to give us a websocket. // Don't use a timeout - the user can cancel manually the operation. String url = myConnector.getWebSocketUrl(); while (url == null) { if (getSession().isStopped()) return; TimeoutUtil.sleep(100); url = myConnector.getWebSocketUrl(); } if (getSession().isStopped()) { return; } // "flutter run" has given us a websocket; we can assume it's ready immediately, because // "flutter run" has already connected to it. final VmService vmService; try { vmService = VmService.connect(url); } catch (IOException | RuntimeException e) { onConnectFailed("Failed to connect to the VM observatory service at: " + url + "\n" + e.toString() + "\n" + formatStackTraces(e)); return; } onConnectSucceeded(vmService); }); }
Example #16
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 #17
Source File: UnityRefreshBeforeRunTaskProvider.java From consulo-unity3d with Apache License 2.0 | 4 votes |
@Nonnull @Override public AsyncResult<Void> executeTaskAsync(UIAccess uiAccess, DataContext context, RunConfiguration configuration, ExecutionEnvironment env, UnityRefreshBeforeRunTask task) { AsyncResult<Void> result = AsyncResult.undefined(); uiAccess.give(() -> { FileDocumentManager.getInstance().saveAllDocuments(); Task.Backgroundable.queue(env.getProject(), "Queue UnityEditor refresh", true, indicator -> { boolean[] receiveData = new boolean[1]; UnityRefresh postObject = new UnityRefresh(); UnityPingPong.Token<Boolean> accessToken = UnityPingPong.wantReply(postObject.uuid, o -> { if(o) { result.setDone(); } else { result.setRejected(); } receiveData[0] = o; }); boolean request = UnityEditorCommunication.request(env.getProject(), postObject, true); if(!request) { new Notification("unity", ApplicationNamesInfo.getInstance().getProductName(), "UnityEditor is not responding", NotificationType.INFORMATION).notify(env.getProject()); accessToken.finish(Boolean.FALSE); return; } while(!receiveData[0]) { if(indicator.isCanceled()) { accessToken.finish(Boolean.FALSE); break; } TimeoutUtil.sleep(500L); } }); }).doWhenRejectedWithThrowable(result::rejectWithThrowable); return result; }
Example #18
Source File: Unity3dProjectImportUtil.java From consulo-unity3d with Apache License 2.0 | 4 votes |
public static void syncProjectStep1(@Nonnull final Project project, @Nullable final Sdk sdk, @Nullable UnityOpenFilePostHandlerRequest requestor, final boolean runValidator) { // set flag project.putUserData(ourInProgressFlag, Boolean.TRUE); Task.Backgroundable.queue(project, "Fetching defines from UnityEditor", indicator -> { UnityRequestDefines request = new UnityRequestDefines(); SimpleReference<Boolean> received = SimpleReference.create(Boolean.FALSE); UnityPingPong.Token<UnitySetDefines> token = UnityPingPong.wantReply(request.uuid, o -> { received.set(Boolean.TRUE); syncProjectStep2(project, sdk, requestor, runValidator, o); }); if(!UnityEditorCommunication.request(project, request, true)) { token.finish(null); notifyAboutUnityEditorProblem(project); return; } int i = 0; while(!received.get()) { if(i == 5) { token.finish(null); notifyAboutUnityEditorProblem(project); break; } TimeoutUtil.sleep(500L); i++; } }); }
Example #19
Source File: Preloader.java From consulo with Apache License 2.0 | 4 votes |
private static void checkHeavyProcessRunning() { if (HeavyProcessLatch.INSTANCE.isRunning()) { TimeoutUtil.sleep(1); } }
Example #20
Source File: StartupManagerImpl.java From consulo with Apache License 2.0 | 4 votes |
private void checkProjectRoots() { VirtualFile[] roots = ProjectRootManager.getInstance(myProject).getContentRoots(); if (roots.length == 0) return; LocalFileSystem fs = LocalFileSystem.getInstance(); if (!(fs instanceof LocalFileSystemImpl)) return; FileWatcher watcher = ((LocalFileSystemImpl)fs).getFileWatcher(); if (!watcher.isOperational()) { //ProjectFsStatsCollector.watchedRoots(myProject, -1); return; } myApplication.executeOnPooledThread(() -> { LOG.debug("FW/roots waiting started"); while (true) { if (myProject.isDisposed()) return; if (!watcher.isSettingRoots()) break; TimeoutUtil.sleep(10); } LOG.debug("FW/roots waiting finished"); Collection<String> manualWatchRoots = watcher.getManualWatchRoots(); int pctNonWatched = 0; if (!manualWatchRoots.isEmpty()) { List<String> nonWatched = new SmartList<>(); for (VirtualFile root : roots) { if (!(root.getFileSystem() instanceof LocalFileSystem)) continue; String rootPath = root.getPath(); for (String manualWatchRoot : manualWatchRoots) { if (FileUtil.isAncestor(manualWatchRoot, rootPath, false)) { nonWatched.add(rootPath); } } } if (!nonWatched.isEmpty()) { String message = ApplicationBundle.message("watcher.non.watchable.project"); watcher.notifyOnFailure(message, null); LOG.info("unwatched roots: " + nonWatched); LOG.info("manual watches: " + manualWatchRoots); pctNonWatched = (int)(100.0 * nonWatched.size() / roots.length); } } //ProjectFsStatsCollector.watchedRoots(myProject, pctNonWatched); }); }