private static boolean flushProcessingQueues(IJobManager jobManager, IProgressMonitor monitor) throws InterruptedException, CoreException { boolean processed = false; for(IBackgroundProcessingQueue queue : getProcessingQueues(jobManager)) { queue.join(); if(!queue.isEmpty()) { Deque<MavenExecutionContext> context = MavenExecutionContext.suspend(); try { IStatus status = queue.run(monitor); if(!status.isOK()) { throw new CoreException(status); } processed = true; } finally { MavenExecutionContext.resume(context); } } if(queue.isEmpty()) { queue.cancel(); } } return processed; }
@Override public void widgetSelected(SelectionEvent e) { startButton.setText("Start"); IJobManager jobManager = Job.getJobManager(); Job[] find = jobManager.find("timer"); if (find != null) { for (Job job : find) { if (job instanceof CountDownJob) { CountDownJob cjob = (CountDownJob) job; cjob.stop(); cjob.cancel(); } } } }
private void waitForBuilder() throws Exception { IJobManager jobManager = Job.getJobManager(); synchronized (this) { wait(500); } try { jobManager.join(ResourcesPlugin.FAMILY_MANUAL_BUILD, monitor); jobManager.join(ResourcesPlugin.FAMILY_AUTO_BUILD, monitor); jobManager.join(FileSyncBuilder.class, monitor); jobManager.join(ResourcesPlugin.FAMILY_MANUAL_BUILD, monitor); jobManager.join(ResourcesPlugin.FAMILY_AUTO_BUILD, monitor); jobManager.join(FileSyncBuilder.class, monitor); } catch (InterruptedException e) { // just continue. } }
public void stop(BundleContext context) throws Exception { // grab any running indexing jobs IJobManager manager = Job.getJobManager(); Job[] jobs = manager.find(IndexRequestJob.INDEX_REQUEST_JOB_FAMILY); // ...and cancel them if (!ArrayUtil.isEmpty(jobs)) { for (Job job : jobs) { job.cancel(); } } fManager = null; plugin = null; super.stop(context); }
/** * Wait for jobs relating to dynamic extension to be finished */ public static void waitForJobs() { IJobManager manager = Job.getJobManager(); Job[] jobs = manager.find(null); while (true) { boolean joined = false; for (Job job : jobs) { if (job instanceof ExtensionEventDispatcherJob) { if (job.getResult() == null) { try { joined = true; job.join(); } catch (InterruptedException e) { LogUtil.error(e); } } } } if (!joined) { break; } } }
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (fgFirstTime) { // Join the initialize after load job. IJobManager manager= Job.getJobManager(); manager.join(JavaUI.ID_PLUGIN, monitor); } OpenTypeHistory history= OpenTypeHistory.getInstance(); if (fgFirstTime || history.isEmpty()) { if (history.needConsistencyCheck()) { monitor.beginTask(JavaUIMessages.TypeSelectionDialog_progress_consistency, 100); refreshSearchIndices(new SubProgressMonitor(monitor, 90)); history.checkConsistency(new SubProgressMonitor(monitor, 10)); } else { refreshSearchIndices(monitor); } monitor.done(); fgFirstTime= false; } else { history.checkConsistency(monitor); } }
/** * Wait until all background tasks are complete then makes sure that the UI thread is idle as well. */ protected void waitForIdleState() { final IJobManager manager = Job.getJobManager(); while (manager.currentJob() != null) { waitForUiThread(); } waitForUiThread(); }
/** Identify all jobs that we know of that are related to building. */ private static Collection<Job> findPendingBuildJobs(IProject... projects) { Set<Job> jobs = new HashSet<>(); IJobManager jobManager = Job.getJobManager(); Collections.addAll(jobs, jobManager.find(ResourcesPlugin.FAMILY_MANUAL_BUILD)); Collections.addAll(jobs, jobManager.find(ResourcesPlugin.FAMILY_AUTO_BUILD)); // J2EEElementChangedListener.PROJECT_COMPONENT_UPDATE_JOB_FAMILY Collections.addAll(jobs, jobManager.find("org.eclipse.jst.j2ee.refactor.component")); // ServerPlugin.SHUTDOWN_JOB_FAMILY Collections.addAll(jobs, jobManager.find("org.eclipse.wst.server.core.family")); Collections.addAll(jobs, jobManager.find("org.eclipse.wst.server.ui.family")); Collections.addAll(jobs, jobManager.find(ValidationBuilder.FAMILY_VALIDATION_JOB)); for (IProject project : projects) { Collections.addAll(jobs, jobManager.find(project.getName() + ValidatorManager.VALIDATOR_JOB_FAMILY)); } // some jobs are not part of a family for (Job job : jobManager.find(null)) { switch (job.getClass().getName()) { case "org.eclipse.wst.jsdt.web.core.internal.project.ConvertJob": case "org.eclipse.m2e.core.ui.internal.wizards.ImportMavenProjectsJob": case "org.eclipse.m2e.core.internal.project.registry.ProjectRegistryRefreshJob": jobs.add(job); break; } } return jobs; }
private static List<IBackgroundProcessingQueue> getProcessingQueues(IJobManager jobManager) { ArrayList<IBackgroundProcessingQueue> queues = new ArrayList<>(); for(Job job : jobManager.find(null)) { if(job instanceof IBackgroundProcessingQueue) { queues.add((IBackgroundProcessingQueue) job); } } return queues; }
/** Waits for all the jobs to finish. */ public static void waitForJobsToFinish() { EclipseMisc.withService(IJobManager.class, jobManager -> { Job job; while ((job = jobManager.currentJob()) != null) { System.out.print(" waiting for " + job.getName() + " to finish... "); job.join(); System.out.println("complete."); } }); }
/** * Build a project and launch a Runnable afterwards. * * See http://www.eclipse.org/articles/Article-Builders/builders.html * * @param projectToBuild * the project to build before launching * @param runAfterBuild * the Runnable to launch after the build on the projectToBuild has been completed */ public static void buildAndRun(final IProject projectToBuild, final Runnable runAfterBuild) { (new Thread() { @Override public void run() { try { IJobManager manager = Job.getJobManager(); if (projectToBuild.getWorkspace().isAutoBuilding()) { projectToBuild.build(IncrementalProjectBuilder.CLEAN_BUILD, NULL_MONITOR); manager.wakeUp(ResourcesPlugin.FAMILY_AUTO_BUILD); manager.join(ResourcesPlugin.FAMILY_AUTO_BUILD, NULL_MONITOR); } else { projectToBuild.build(IncrementalProjectBuilder.FULL_BUILD, NULL_MONITOR); manager.wakeUp(ResourcesPlugin.FAMILY_MANUAL_BUILD); manager.join(ResourcesPlugin.FAMILY_MANUAL_BUILD, NULL_MONITOR); } runAfterBuild.run(); } catch (Exception e) { Utilities.showException(e); } } }).start(); }
/** * Undo/redo this operation, while enforcing its scheduling rule. * This method is required to be executed in a Job. * * @param info * @param monitor * @param operation * @param undo true if undo, false if redo * @return */ private IStatus inJobEnforceRule(IAdaptable info, IProgressMonitor monitor, IUndoableOperation operation, boolean undo) { IJobManager jobManager = Job.getJobManager(); ISchedulingRule currentRule = jobManager.currentRule(); ISchedulingRule operationRule = OperationJob.getSchedulingRule(operation); ISchedulingRule rule = MultiRule.combine(currentRule, operationRule); try { jobManager.beginRule(rule, monitor); return inJobInRule(info, monitor, operation, undo); } finally { jobManager.endRule(rule); } }
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (fgFirstTime) { // Join the initialize after load job. IJobManager manager = Job.getJobManager(); manager.join(DLTKUIPlugin.PLUGIN_ID, monitor); } OpenTypeHistory history = OpenTypeHistory.getInstance(tookit); if (fgFirstTime || history.isEmpty()) { if (history.needConsistencyCheck()) { monitor .beginTask( DLTKUIMessages.TypeSelectionDialog_progress_consistency, 100); refreshSearchIndices(new SubProgressMonitor(monitor, 90)); history .checkConsistency(new SubProgressMonitor(monitor, 10)); } else { refreshSearchIndices(monitor); } monitor.done(); fgFirstTime = false; } else { history.checkConsistency(monitor); } }
public IJobManager getJobManager() { return Job.getJobManager(); }
/** * Must be called in the UI thread.<br> * <strong>Use {@link #perform(boolean, boolean)} unless you know exactly what you are * doing!</strong> * * @param fork if set, the operation will be forked * @param forkChangeExecution if the change should not be executed in the UI thread: This may not * work in any case * @param cancelable if set, the operation will be cancelable * @throws InterruptedException thrown when the operation is cancelled * @throws InvocationTargetException thrown when the operation failed to execute */ public RefactoringStatus perform(boolean fork, boolean forkChangeExecution, boolean cancelable) throws InterruptedException, InvocationTargetException, CoreException { // Assert.isTrue(Display.getCurrent() != null); final IJobManager manager = Job.getJobManager(); final ISchedulingRule rule; if (fRefactoring instanceof IScheduledRefactoring) { rule = ((IScheduledRefactoring) fRefactoring).getSchedulingRule(); } else { rule = ResourcesPlugin.getWorkspace().getRoot(); } Operation op = null; try { // try { // Runnable r= new Runnable() { // public void run() { // manager.beginRule(rule, null); // } // }; //// BusyIndicator.showWhile(fParent.getDisplay(), r); // } catch (OperationCanceledException e) { // throw new InterruptedException(e.getMessage()); // } // RefactoringSaveHelper saveHelper= new RefactoringSaveHelper(fSaveMode); // if (!saveHelper.saveEditors(fParent)) // throw new InterruptedException(); try { op = new Operation(fork, forkChangeExecution); op.run(new NullProgressMonitor()); fPerformChangeOperation = op.fPerformChangeOperation; // fRefactoring.setValidationContext(fParent); if (op.fPerformChangeOperation != null) { ResourcesPlugin.getWorkspace().run(op.fPerformChangeOperation, new NullProgressMonitor()); } // if (fork && !forkChangeExecution && op.fPerformChangeOperation != null) // fExecContext.run(false, false, new // WorkbenchRunnableAdapter(op.fPerformChangeOperation, rule, true)); if (op.fPerformChangeOperation != null) { RefactoringStatus validationStatus = op.fPerformChangeOperation.getValidationStatus(); if (validationStatus != null /*&& validationStatus.hasFatalError()*/) { // MessageDialog.openError(fParent, fRefactoring.getName(), // Messages.format( // RefactoringMessages.RefactoringExecutionHelper_cannot_execute, // validationStatus.getMessageMatchingSeverity(RefactoringStatus.FATAL))); // throw new InterruptedException(); return validationStatus; } } } catch (OperationCanceledException e) { if (op != null) { if (op.allConditions != null) { return op.allConditions; } } throw new InterruptedException(e.getMessage()); } finally { // saveHelper.triggerIncrementalBuild(); } } finally { // manager.endRule(rule); fRefactoring.setValidationContext(null); } return new RefactoringStatus(); }
public static void joinOperationFamily(IProgressMonitor monitor) throws OperationCanceledException, InterruptedException { IJobManager jobManager = Job.getJobManager(); jobManager.join(OPERATION_FAMILY, monitor); }
public void testEditWithNoNature() throws Exception { NullProgressMonitor monitor = new NullProgressMonitor(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IPath workspaceLoc = root.getRawLocation(); IProject project = root.getProject("pydev_nature_pre_configured"); if (project.exists()) { project.delete(true, monitor); } //let's create its structure IPath projectLoc = workspaceLoc.append("pydev_nature_pre_configured"); projectLoc.toFile().mkdir(); writeProjectFile(projectLoc.append(".project")); writePydevProjectFile(projectLoc.append(".pydevproject")); File srcLocFile = projectLoc.append("src").toFile(); srcLocFile.mkdir(); assertTrue(!project.exists()); project.create(monitor); project.open(monitor); project.refreshLocal(IResource.DEPTH_INFINITE, monitor); IJobManager jobManager = Job.getJobManager(); jobManager.resume(); final PythonNature nature = (PythonNature) PythonNature.addNature(project, null, null, null, null, null, null); assertTrue(nature != null); //Let's give it some time to run the jobs that restore the nature goToIdleLoopUntilCondition(new ICallback<Boolean, Object>() { @Override public Boolean call(Object arg) { if (nature != null) { if (nature.getAstManager() != null) { return true; } } return false; } }); assertTrue(nature.getAstManager() != null); PythonPathHelper pythonPathHelper = (PythonPathHelper) nature.getAstManager().getModulesManager() .getPythonPathHelper(); List<String> lst = new ArrayList<String>(); lst.add(FileUtils.getFileAbsolutePath(srcLocFile)); assertEquals(lst, pythonPathHelper.getPythonpath()); }
private JobPool(){ IJobManager jobman = Platform.getJobManager(); changeLock = jobman.newLock(); }