]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fixed SCLScriptAnnotationModel script validation threading 83/1183/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 2 Nov 2017 13:37:32 +0000 (15:37 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 2 Nov 2017 13:37:32 +0000 (15:37 +0200)
Previously the code performed the script validation directly in the DB
listener thread, which is essentially QueryThread-0 without putting the
related ReadGraph into the current SCLContext while doing so. This
caused the validation code to crash because the validation code tries to
start a new database transaction from within the transaction thread
calling the listener.

The solution schedules the validation to a BUILD priority Job thread.

refs #7450

Change-Id: I01c030be032890638919c3800e04e14670f8726c

bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/scl/scriptEditor/SCLScriptAnnotationModel.java

index fadb4f909f9c679aeb52f11247e45e1a21cf3c06..6653422dde16055df325de5d9602ca942b5e525c 100644 (file)
@@ -14,6 +14,10 @@ package org.simantics.modeling.ui.scl.scriptEditor;
 import java.util.Arrays;
 import java.util.List;
 
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.Position;
 import org.eclipse.jface.text.source.Annotation;
@@ -51,7 +55,7 @@ public class SCLScriptAnnotationModel extends AnnotationModel {
         @Override
         public void execute(String result) {
             if (connected && result != null)
-                updateAnnotations(result);
+                scheduleUpdateAnnotations(result);
         }
         @Override
         public void exception(Throwable t) {
@@ -72,6 +76,21 @@ public class SCLScriptAnnotationModel extends AnnotationModel {
         public void print(String text) {}
     };
 
+    private void scheduleUpdateAnnotations(String sourceText) {
+        //LOGGER.debug("scheduleUpdateAnnotations:\n" + sourceText);
+        Job validateJob = new Job("Validate Script") {
+            @Override
+            protected IStatus run(IProgressMonitor monitor) {
+                updateAnnotations(sourceText);
+                return Status.OK_STATUS;
+            }
+        };
+        validateJob.setPriority(Job.BUILD);
+        validateJob.setUser(false);
+        validateJob.setSystem(false);
+        validateJob.schedule();
+    }
+
     private void updateAnnotations(String sourceText) {
         //LOGGER.debug("updateAnnotations:\n" + sourceText);
         CompilationError[] errors = new CommandSession(repository, NOP).validate(sourceText);