Skip to content
Snippets Groups Projects
Commit 44135cf6 authored by Andreas Bayha's avatar Andreas Bayha
Browse files

Constraint Checker: Asynchronous checks are run per model in parallel


There is a Job for every model and every constraint, now. Before, every
model changed canceled any previous check even for other models.

Issue-ref: 4309
Issue-URL: af3#4309

Signed-off-by: default avatarAndreas Bayha <bayha@fortiss.org>
parent bc321570
No related branches found
No related tags found
1 merge request!1784240
......@@ -19,6 +19,7 @@ import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableMap;
import static org.conqat.lib.commons.reflect.ReflectionUtils.performNearestClassLookup;
import static org.eclipse.core.runtime.Status.OK_STATUS;
import static org.eclipse.core.runtime.jobs.Job.RUNNING;
import java.util.ArrayList;
import java.util.Collections;
......@@ -39,6 +40,7 @@ import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem;
import org.fortiss.tooling.kernel.introspection.IIntrospectionItem;
import org.fortiss.tooling.kernel.introspection.IIntrospectiveKernelService;
import org.fortiss.tooling.kernel.introspection.items.ConstraintCheckerKISSDetailsItem;
import org.fortiss.tooling.kernel.model.INamedElement;
import org.fortiss.tooling.kernel.service.IConstraintCheckerService;
import org.fortiss.tooling.kernel.service.IKernelIntrospectionSystemService;
import org.fortiss.tooling.kernel.service.base.EObjectAwareServiceBase;
......@@ -57,9 +59,12 @@ public class ConstraintCheckerService extends EObjectAwareServiceBase<IConstrain
Map<Class<?>, List<IConstraintChecker<EObject>>> asynchronousConstraintCheckers =
new HashMap<Class<?>, List<IConstraintChecker<EObject>>>();
Map<IConstraintChecker<? extends EObject>, String> asynchronousCheckIdentifiers =
new HashMap<IConstraintChecker<? extends EObject>, String>();
/** Maps all constraint checkers to the last started Job, each. */
Map<IConstraintChecker<? extends EObject>, Job> asynchronousChecks =
new HashMap<IConstraintChecker<? extends EObject>, Job>();
Map<IConstraintChecker<? extends EObject>, Map<EObject, Job>> asynchronousCheckerJobs =
new HashMap<IConstraintChecker<? extends EObject>, Map<EObject, Job>>();
/** Returns singleton instance of the service. */
public static ConstraintCheckerService getInstance() {
......@@ -169,12 +174,27 @@ public class ConstraintCheckerService extends EObjectAwareServiceBase<IConstrain
}
for(IConstraintChecker<EObject> checker : asyncHandlers) {
Job checkerJob = asynchronousChecks.get(checker);
if(checkerJob != null && checkerJob.getThread().isAlive()) {
Map<EObject, Job> jobs = asynchronousCheckerJobs.get(checker);
if(jobs == null) {
jobs = new HashMap<EObject, Job>();
asynchronousCheckerJobs.put(checker, jobs);
}
Job checkerJob = jobs.get(modelElement);
if(checkerJob != null && checkerJob.getState() == RUNNING) {
checkerJob.cancel();
}
checkerJob = new Job("Product Line Analysis") {
String checkerIdentifier = asynchronousCheckIdentifiers.get(checker);
if(checkerIdentifier == null) {
checkerIdentifier = "Asynchronous Model Constraint Check";
}
String modelIdentifier = "";
if(modelElement instanceof INamedElement) {
modelIdentifier = " on " + ((INamedElement)modelElement).getName();
}
checkerJob = new Job(checkerIdentifier + modelIdentifier) {
@Override
protected IStatus run(IProgressMonitor monitor) {
......@@ -187,7 +207,7 @@ public class ConstraintCheckerService extends EObjectAwareServiceBase<IConstrain
return OK_STATUS;
}
};
asynchronousChecks.put(checker, checkerJob);
jobs.put(modelElement, checkerJob);
checkerJob.setUser(false);
checkerJob.schedule();
......@@ -248,7 +268,7 @@ public class ConstraintCheckerService extends EObjectAwareServiceBase<IConstrain
@SuppressWarnings("unchecked")
@Override
public <T extends EObject> void registerAsynchronousConstraintChecker(
IConstraintChecker<T> checker, Class<T> modelElementClass) {
IConstraintChecker<T> checker, Class<T> modelElementClass, String checkerName) {
if(checker == null) {
return;
}
......@@ -262,5 +282,7 @@ public class ConstraintCheckerService extends EObjectAwareServiceBase<IConstrain
}
checkers.add((IConstraintChecker<EObject>)checker);
asynchronousCheckIdentifiers.put(checker, checkerName);
}
}
......@@ -92,5 +92,5 @@ public interface IConstraintCheckerService {
/** Registers the given checker to be run asynchronously in the service. */
<T extends EObject> void registerAsynchronousConstraintChecker(IConstraintChecker<T> checker,
Class<T> modelElementClass);
Class<T> modelElementClass, String checkerName);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment