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());
}
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;
}
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();
}
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");
}
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();
}
}
Aggregations