Java Code Examples for com.intellij.openapi.application.AccessToken#finish()
The following examples show how to use
com.intellij.openapi.application.AccessToken#finish() .
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: BaseApplication.java From consulo with Apache License 2.0 | 6 votes |
public void load(@Nonnull String configPath, @Nonnull String optionsPath) throws IOException { IApplicationStore store = getStateStore(); store.setOptionsPath(optionsPath); store.setConfigPath(configPath); fireBeforeApplicationLoaded(); AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Loading application components"); try { store.load(); } catch (StateStorageException e) { throw new IOException(e.getMessage()); } finally { token.finish(); } myLoaded = true; createLocatorFile(); }
Example 2
Source File: VfsDirectoryBasedStorage.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public static VirtualFile getFile(@Nonnull String fileName, @Nonnull VirtualFile parentVirtualFile, @Nonnull Object requestor) { VirtualFile file = parentVirtualFile.findChild(fileName); if (file != null) { return file; } AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(VfsDirectoryBasedStorage.class); try { return parentVirtualFile.createChildData(requestor, fileName); } catch (IOException e) { throw new StateStorageException(e); } finally { token.finish(); } }
Example 3
Source File: FileEditorManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
/** * @param splitters - taken getAllSplitters() value if parameter is null */ void runChange(@Nonnull FileEditorManagerChange change, @Nullable EditorsSplitters splitters) { Set<EditorsSplitters> target = new HashSet<>(); if (splitters == null) { target.addAll(getAllSplitters()); } else { target.add(splitters); } for (EditorsSplitters each : target) { AccessToken token = each.increaseChange(); try { change.run(each); } finally { token.finish(); } } }
Example 4
Source File: ConsoleHistoryController.java From consulo with Apache License 2.0 | 6 votes |
private void saveHistory() { try { if (getModel().isEmpty()) return; if (myRootType.isHidden()) { saveHistoryOld(); return; } AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass()); try { VirtualFile file = HistoryRootType.getInstance().findFile(null, getHistoryName(myRootType, myId), ScratchFileService.Option.create_if_missing); VfsUtil.saveText(file, StringUtil.join(getModel().getEntries(), myRootType.getEntrySeparator())); } finally { token.finish(); } } catch (Exception ex) { LOG.error(ex); } }
Example 5
Source File: BlazePyPositionConverter.java From intellij with Apache License 2.0 | 5 votes |
/** Convert from 1- to 0-indexed line numbering, and account for continuation lines */ private static int convertLocalLineToRemote(VirtualFile file, int line) { AccessToken lock = ApplicationManager.getApplication().acquireReadActionLock(); try { final Document document = FileDocumentManager.getInstance().getDocument(file); if (document != null) { while (PyDebugSupportUtils.isContinuationLine(document, line)) { line++; } } return line + 1; } finally { lock.finish(); } }
Example 6
Source File: FileDocumentManagerImplTest.java From consulo with Apache License 2.0 | 5 votes |
private static void renameFile(VirtualFile file, String newName) throws IOException { AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(FileDocumentManagerImplTest.class); try { file.rename(null, newName); } finally { token.finish(); } }
Example 7
Source File: SymlinkHandlingTest.java From consulo with Apache License 2.0 | 5 votes |
public void testLinkDeleteIsSafe() throws Exception { File targetFile = createTestFile(myTempDir, "target"); File linkFile = createSymLink(targetFile.getPath(), myTempDir + "/link"); VirtualFile linkVFile = refreshAndFind(linkFile); assertTrue("link=" + linkFile + ", vLink=" + linkVFile, linkVFile != null && !linkVFile.isDirectory() && linkVFile.is(VFileProperty.SYMLINK)); AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass()); try { linkVFile.delete(this); } finally { token.finish(); } assertFalse(linkVFile.toString(), linkVFile.isValid()); assertFalse(linkFile.exists()); assertTrue(targetFile.exists()); File targetDir = createTestDir(myTempDir, "targetDir"); File childFile = new File(targetDir, "child.txt"); assertTrue(childFile.getPath(), childFile.exists() || childFile.createNewFile()); File linkDir = createSymLink(targetDir.getPath(), myTempDir + "/linkDir"); VirtualFile linkVDir = refreshAndFind(linkDir); assertTrue("link=" + linkDir + ", vLink=" + linkVDir, linkVDir != null && linkVDir.isDirectory() && linkVDir.is(VFileProperty.SYMLINK) && linkVDir.getChildren().length == 1); token = ApplicationManager.getApplication().acquireWriteActionLock(getClass()); try { linkVDir.delete(this); } finally { token.finish(); } assertFalse(linkVDir.toString(), linkVDir.isValid()); assertFalse(linkDir.exists()); assertTrue(targetDir.exists()); assertTrue(childFile.exists()); }
Example 8
Source File: FileWatcherTest.java From consulo with Apache License 2.0 | 5 votes |
private void delete(File file) throws IOException { VirtualFile vFile = myFileSystem.findFileByIoFile(file); if (vFile != null) { AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass()); try { vFile.delete(this); } finally { token.finish(); } } if (file.exists()) { FileUtil.delete(file); } }
Example 9
Source File: StorageUtil.java From consulo with Apache License 2.0 | 5 votes |
public static void deleteFile(@Nonnull Object requestor, @Nonnull VirtualFile virtualFile) throws IOException { AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(StorageUtil.class); try { virtualFile.delete(requestor); } catch (FileNotFoundException e) { throw new ReadOnlyModificationException(VfsUtil.virtualToIoFile(virtualFile)); } finally { token.finish(); } }
Example 10
Source File: VfsDirectoryBasedStorage.java From consulo with Apache License 2.0 | 5 votes |
private void deleteFiles(@Nonnull VirtualFile dir) { AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(VfsDirectoryBasedStorage.class); try { for (VirtualFile file : dir.getChildren()) { if (removedFileNames.contains(file.getName())) { deleteFile(file, this); } } } finally { token.finish(); } }
Example 11
Source File: SchemesManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
private void deleteFiles() { if (myFilesToDelete.isEmpty()) { return; } if (myProvider != null && myProvider.isEnabled()) { for (String nameWithoutExtension : myFilesToDelete) { deleteServerFile(nameWithoutExtension + mySchemeExtension); if (!DirectoryStorageData.DEFAULT_EXT.equals(mySchemeExtension)) { deleteServerFile(nameWithoutExtension + DirectoryStorageData.DEFAULT_EXT); } } } VirtualFile dir = getVirtualDir(); if (dir != null) { AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(SchemesManagerImpl.class); try { for (VirtualFile file : dir.getChildren()) { if (myFilesToDelete.contains(file.getNameWithoutExtension())) { VfsDirectoryBasedStorage.deleteFile(file, this); } } myFilesToDelete.clear(); } finally { token.finish(); } } }
Example 12
Source File: ProjectStructureConfigurable.java From consulo with Apache License 2.0 | 5 votes |
@Override public void reset() { // need this to ensure VFS operations will not block because of storage flushing // and other maintenance IO tasks run in background AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Resetting Project Structure"); try { myContext.reset(); ShowSdksSettingsUtil settingsUtil = (ShowSdksSettingsUtil)ShowSettingsUtil.getInstance(); settingsUtil.getSdksModel().reset(); Configurable toSelect = null; for (Configurable each : myName2Config) { if (myUiState.lastEditedConfigurable != null && myUiState.lastEditedConfigurable.equals(each.getDisplayName())) { toSelect = each; } if (each instanceof MasterDetailsComponent) { ((MasterDetailsComponent)each).setHistory(myHistory); } each.reset(); } myHistory.clear(); if (toSelect == null && myName2Config.size() > 0) { toSelect = myName2Config.iterator().next(); } removeSelected(); navigateTo(toSelect != null ? createPlaceFor(toSelect) : null, false); } finally { token.finish(); } }
Example 13
Source File: ConsoleHistoryController.java From consulo with Apache License 2.0 | 5 votes |
public boolean loadHistory(String id, VirtualFile consoleFile) { try { VirtualFile file = myRootType.isHidden() ? null : HistoryRootType.getInstance().findFile(null, getHistoryName(myRootType, id), ScratchFileService.Option.existing_only); if (file == null) { if (loadHistoryOld(id)) { if (!myRootType.isHidden()) { // migrate content AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass()); try { VfsUtil.saveText(consoleFile, myContent); } finally { token.finish(); } } return true; } return false; } String[] split = VfsUtilCore.loadText(file).split(myRootType.getEntrySeparator()); getModel().resetEntries(Arrays.asList(split)); return true; } catch (Exception ignored) { return false; } }
Example 14
Source File: ScratchFileServiceImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public VirtualFile findFile(@Nonnull RootType rootType, @Nonnull String pathName, @Nonnull Option option) throws IOException { ApplicationManager.getApplication().assertReadAccessAllowed(); String fullPath = getRootPath(rootType) + "/" + pathName; if (option != Option.create_new_always) { VirtualFile file = LocalFileSystem.getInstance().findFileByPath(fullPath); if (file != null && !file.isDirectory()) return file; if (option == Option.existing_only) return null; } String ext = PathUtil.getFileExtension(pathName); String fileNameExt = PathUtil.getFileName(pathName); String fileName = StringUtil.trimEnd(fileNameExt, ext == null ? "" : "." + ext); AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass()); try { VirtualFile dir = VfsUtil.createDirectories(PathUtil.getParentPath(fullPath)); if (option == Option.create_new_always) { return VfsUtil.createChildSequent(LocalFileSystem.getInstance(), dir, fileName, StringUtil.notNullize(ext)); } else { return dir.createChildData(LocalFileSystem.getInstance(), fileNameExt); } } finally { token.finish(); } }
Example 15
Source File: AsyncFileStatusCalculator.java From SVNToolBox with Apache License 2.0 | 4 votes |
@Override public void run() { final boolean DEBUG = LOG.isDebugEnabled(); if (myCalculationInProgress.compareAndSet(false, true)) { boolean exhausted = false; try { StatusRequest request = myRequestQueue.poll(150, TimeUnit.MILLISECONDS); if (request != null) { if (myPendingFiles.remove(request.file)) { AccessToken token = ApplicationManager.getApplication().acquireReadActionLock(); LogStopwatch watch = LogStopwatch.debugStopwatch(PV_SEQ, new MfSupplier("Status calculation for {0}", request.file)).start(); FileStatus status; try { status = myStatusCalc.statusFor(request.project, request.file); } finally { token.finish(); watch.stop(); } ProjectViewStatus viewStatus; if (status.isUnderVcs()) { if (status.getBranchName().isPresent()) { viewStatus = new ProjectViewStatus(status.getBranchName().get()); } else { viewStatus = ProjectViewStatus.NOT_CONFIGURED; } } else { viewStatus = ProjectViewStatus.EMPTY; } ProjectViewStatusCache cache = myProjectViewManager.getStatusCache(); cache.add(request.file, viewStatus); } else { if (DEBUG) { LOG.debug("[" + PV_SEQ.get() + "] " + request.file.getPath() + " was already calculated"); } } } else { if (DEBUG) { LOG.debug("[" + PV_SEQ.get() + "] Requests exhausted"); } exhausted = true; } } catch (InterruptedException e) { LOG.error(e); } finally { if (myCalculationInProgress.compareAndSet(true, false)) { if (exhausted) { refreshView(); } else { if (DEBUG) { LOG.debug("[" + PV_SEQ.get() + "] Scheduling next status calculation - " + myRequestQueue.size() + " requests pending"); } calculateStatus(); } } } } else { if (DEBUG) { LOG.debug("[" + PV_SEQ.get() + "] Another status calculation in progress"); } } }
Example 16
Source File: DvcsUtil.java From consulo with Apache License 2.0 | 4 votes |
/** * @deprecated Call {@link AccessToken#finish()} directly from the AccessToken received by {@link #workingTreeChangeStarted(Project)} */ @Deprecated public static void workingTreeChangeFinished(@Nonnull Project project, @Nonnull AccessToken token) { token.finish(); }