Search in sources :

Example 61 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project tbd-studio-se by Talend.

the class HadoopRepositoryWizard method createConnectionItem.

protected void createConnectionItem() throws CoreException {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    IWorkspaceRunnable operation = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            try {
                String nextId = factory.getNextId();
                connectionProperty.setId(nextId);
                factory.create(connectionItem, propertiesPage.getDestinationPath());
                HCRepositoryUtil.setupConnectionToHadoopCluster(repNode, connectionItem.getProperty().getId());
            } catch (PersistenceException e) {
                throw new CoreException(new Status(IStatus.ERROR, HadoopClusterPlugin.PLUGIN_ID, Messages.getString("HadoopClusterWizard.save.exception", connectionProperty.getLabel()), // $NON-NLS-1$
                e));
            }
        }
    };
    ISchedulingRule schedulingRule = workspace.getRoot();
    // the update the project files need to be done in the workspace runnable to avoid all
    // notification of changes before the end of the modifications.
    workspace.run(operation, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 62 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project snow-owl by b2ihealthcare.

the class ValidationThreadPool method submit.

public Promise<Object> submit(CheckType checkType, Runnable runnable) {
    final Job job = new ValidationJob(checkType.getName(), runnable);
    final String uniqueRuleId = UUID.randomUUID().toString();
    final ISchedulingRule schedulingRule = new ValidationRuleSchedulingRule(checkType, maxValidationThreadCount, maxConcurrentExpensiveJobs, maxConcurrentNormalJobs, uniqueRuleId);
    final Promise<Object> promise = new Promise<>();
    job.setSystem(true);
    job.setRule(schedulingRule);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            if (event.getResult().isOK()) {
                promise.resolve(Boolean.TRUE);
            } else {
                promise.reject(new ValidationException(String.format("Validation job failed with status %s.", event.getResult())));
            }
        }
    });
    job.schedule();
    return promise;
}
Also used : Promise(com.b2international.snowowl.core.events.util.Promise) ValidationException(javax.validation.ValidationException) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 63 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project che by eclipse.

the class RefactoringExecutionHelper method perform.

/**
	 * 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 {
            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 (op.fPerformChangeOperation != null) {
                RefactoringStatus validationStatus = op.fPerformChangeOperation.getValidationStatus();
                if (validationStatus != null) /*&& validationStatus.hasFatalError()*/
                {
                    //						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();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 64 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project che by eclipse.

the class WorkspaceModifyOperation method threadChange.

/* (non-Javadoc)
     * @see IThreadListener#threadChange(Thread);
     * @since 3.2
     */
public void threadChange(Thread thread) {
    //already owns a scheduling rule because this is deadlock prone (bug 105491)
    if (rule == null) {
        return;
    }
    Job currentJob = Job.getJobManager().currentJob();
    if (currentJob == null) {
        return;
    }
    ISchedulingRule currentRule = currentJob.getRule();
    if (currentRule == null) {
        return;
    }
    //$NON-NLS-1$
    throw new IllegalStateException("Cannot fork a thread from a thread owning a rule");
}
Also used : Job(org.eclipse.core.runtime.jobs.Job) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 65 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project che by eclipse.

the class Resource method move.

@Override
public void move(IPath destination, int updateFlags, IProgressMonitor monitor) throws CoreException {
    monitor = Policy.monitorFor(monitor);
    try {
        String message = NLS.bind(Messages.resources_moving, getFullPath());
        monitor.beginTask(message, Policy.totalWork);
        Policy.checkCanceled(monitor);
        destination = makePathAbsolute(destination);
        //            checkValidPath(destination, getType(), false);
        Resource destResource = workspace.newResource(destination, getType());
        final ISchedulingRule rule = workspace.getRuleFactory().moveRule(this, destResource);
        WorkManager workManager = workspace.getWorkManager();
        try {
            workspace.prepareOperation(rule, monitor);
            workspace.beginOperation(true);
            int depth = 0;
            try {
                depth = workManager.beginUnprotected();
                unprotectedMove(destResource, updateFlags, monitor);
            } finally {
                workManager.endUnprotected(depth);
            }
        } finally {
            workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
        }
    } finally {
        monitor.done();
    }
}
Also used : IResource(org.eclipse.core.resources.IResource) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Aggregations

ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)116 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)41 CoreException (org.eclipse.core.runtime.CoreException)40 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)32 IWorkspace (org.eclipse.core.resources.IWorkspace)30 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)22 PersistenceException (org.talend.commons.exception.PersistenceException)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)17 IStatus (org.eclipse.core.runtime.IStatus)17 Status (org.eclipse.core.runtime.Status)15 IResource (org.eclipse.core.resources.IResource)14 MultiRule (org.eclipse.core.runtime.jobs.MultiRule)14 ArrayList (java.util.ArrayList)13 IResourceRuleFactory (org.eclipse.core.resources.IResourceRuleFactory)12 Job (org.eclipse.core.runtime.jobs.Job)12 IFile (org.eclipse.core.resources.IFile)11 HashSet (java.util.HashSet)10 IPath (org.eclipse.core.runtime.IPath)10 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)10 RepositoryWorkUnit (org.talend.repository.RepositoryWorkUnit)10