]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/SCLContext.java
(refs #7607) Fixed handling of SCLContext in asynchronous requests
[simantics/platform.git] / bundles / org.simantics.scl.runtime / src / org / simantics / scl / runtime / SCLContext.java
index 8703819776a95f521109b36eadbbbcec847ca6f8..a9444bcf909f97bd77fde8c47b16ec97996bb0cb 100644 (file)
@@ -1,5 +1,7 @@
 package org.simantics.scl.runtime;
 
+import org.simantics.scl.runtime.reporting.SCLReportingHandler;
+
 import gnu.trove.map.hash.THashMap;
 
 public class SCLContext extends THashMap<String,Object> {
@@ -32,6 +34,22 @@ public class SCLContext extends THashMap<String,Object> {
         CONTEXT.set(newContext);
     }
     
+    /**
+     * Creates a new context based on some properties of the current context.
+     * The new context is safe for use in parallel threads.
+     */
+    public static SCLContext createDerivedContext() {
+        SCLContext newContext = new SCLContext();
+        
+        SCLContext baseContext = CONTEXT.get();
+        if(baseContext != null) {
+            Object reportingHandler = baseContext.get(SCLReportingHandler.REPORTING_HANDLER);
+            if(reportingHandler != null)
+                newContext.put(SCLReportingHandler.REPORTING_HANDLER, reportingHandler);
+        }
+        return newContext;
+    }
+    
     public static void pop() {
         OldContextNode node = OLD_CONTEXT.get();
         if(node == null)