Search in sources :

Example 96 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.

the class Marker method delete.

/**
 * @see IMarker#delete()
 */
public void delete() throws CoreException {
    final ISchedulingRule rule = getWorkspace().getRuleFactory().markerRule(resource);
    try {
        getWorkspace().prepareOperation(rule, null);
        getWorkspace().beginOperation(true);
        getWorkspace().getMarkerManager().removeMarker(getResource(), getId());
    } finally {
        getWorkspace().endOperation(rule, false, null);
    }
}
Also used : ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 97 with ISchedulingRule

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

the class DataProviderWriter method save.

/**
 * Save connection item and update the dependencies(optional). <B>To update dependencies of the connection the
 * #careDependency must be set as TRUE.</B>
 *
 * @see org.talend.dq.writer.AElementPersistance#save(org.talend.core.model.properties.Item, boolean[])
 */
@Override
public ReturnCode save(Item item, boolean careDependency) {
    final ConnectionItem connItem = (ConnectionItem) item;
    final boolean isCare = careDependency;
    // MOD qiongli TDQ-6287 avoid all notification of changes before the end of the modifications.
    final ReturnCode returnCode = new ReturnCode();
    RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>(// $NON-NLS-1$
    "Save connection item: " + item.getProperty().getDisplayName()) {

        @Override
        protected void run() {
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            IWorkspaceRunnable operation = new IWorkspaceRunnable() {

                public void run(IProgressMonitor monitor) throws CoreException {
                    try {
                        if (isCare) {
                            saveWithDependencies(connItem, connItem.getConnection());
                        } else {
                            saveWithoutDependencies(connItem, connItem.getConnection());
                        }
                    } catch (PersistenceException e) {
                        log.error(e, e);
                        returnCode.setOk(Boolean.FALSE);
                        returnCode.setMessage(e.getMessage());
                    }
                }
            };
            ISchedulingRule schedulingRule = workspace.getRoot();
            try {
                workspace.run(operation, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
            } catch (CoreException e) {
                log.error(e, e);
                returnCode.setOk(false);
            }
        }
    };
    workUnit.setAvoidUnloadResources(true);
    ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(workUnit);
    // MOD yyi 2012-02-07 TDQ-4621:Update dependencies(connection) when careDependency is true.
    return returnCode;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ReturnCode(org.talend.utils.sugars.ReturnCode) ConnectionItem(org.talend.core.model.properties.ConnectionItem) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) EObject(org.eclipse.emf.ecore.EObject)

Example 98 with ISchedulingRule

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

the class MultiRuleTest method testCombine.

public void testCombine() {
    ISchedulingRule child1 = new PathRule("/a");
    ISchedulingRule child2 = new PathRule("/b/c");
    ISchedulingRule childOfChild1 = new PathRule("/a/b");
    ISchedulingRule nonChild = new PathRule("/z/d");
    MultiRule multi1 = new MultiRule(new ISchedulingRule[] { child1, child2 });
    // add multi to its own children
    assertEquals("1.0", multi1, MultiRule.combine(new ISchedulingRule[] { multi1 }));
    assertEquals("1.1", multi1, MultiRule.combine(new ISchedulingRule[] { multi1, child1, child2, childOfChild1 }));
    assertEquals("1.2", multi1, MultiRule.combine(multi1, child2));
    assertEquals("1.3", multi1, MultiRule.combine(childOfChild1, multi1));
    // null
    assertEquals("1.4", null, MultiRule.combine(null, null));
    assertEquals("1.5", multi1, MultiRule.combine(null, multi1));
    assertEquals("1.6", child1, MultiRule.combine(child1, null));
    MultiRule result = (MultiRule) MultiRule.combine(multi1, nonChild);
    assertTrue("2.0" + result, result.contains(multi1));
    assertTrue("2.1", result.contains(nonChild));
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 99 with ISchedulingRule

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

the class MultiRuleTest method testIsConflicting.

public void testIsConflicting() {
    ISchedulingRule child1 = new PathRule("/a");
    ISchedulingRule child2 = new PathRule("/b/c");
    ISchedulingRule childOfChild1 = new PathRule("/a/b");
    ISchedulingRule nonChild = new PathRule("/z/d");
    MultiRule multi1 = new MultiRule(new ISchedulingRule[] { child1, child2 });
    MultiRule multi2 = new MultiRule(new ISchedulingRule[] { childOfChild1, nonChild });
    assertTrue("1.0", multi1.isConflicting(child1));
    assertTrue("1.1", multi1.isConflicting(child2));
    assertTrue("1.2", !multi1.isConflicting(nonChild));
    assertTrue("1.3", multi1.isConflicting(childOfChild1));
    assertTrue("1.4", multi1.isConflicting(multi2));
    assertTrue("1.5", multi2.isConflicting(multi1));
    assertTrue("1.6", multi1.isConflicting(multi1));
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 100 with ISchedulingRule

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

the class Bug_129551 method testBug.

public void testBug() {
    ISchedulingRule rule = new IdentityRule();
    BugJob job = new BugJob();
    job.setRule(rule);
    TestJob other = new TestJob("bug_129551_other", 1, 1);
    other.setRule(rule);
    job.schedule();
    other.schedule();
    // wait until the first job is about to run
    barrier.waitForStatus(TestBarrier.STATUS_RUNNING);
    // wait to ensure the other job is blocked
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        fail("4.99", e);
    }
    // let the first job go
    barrier.setStatus(TestBarrier.STATUS_START);
    barrier.waitForStatus(TestBarrier.STATUS_DONE);
    // check for failure
    if (failure[0] != null)
        fail(failure[0].getMessage());
    // tell the job not to sleep this time around
    shouldSleep[0] = false;
    job.wakeUp();
    waitForCompletion(job);
    waitForCompletion(other);
}
Also used : TestJob(org.eclipse.core.tests.harness.TestJob) 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