]> gerrit.simantics Code Review - simantics/r.git/blobdiff - org.simantics.r.scl/src/org/simantics/r/scl/RSessionManager.java
refs #6626
[simantics/r.git] / org.simantics.r.scl / src / org / simantics / r / scl / RSessionManager.java
index f75df4c9b48638e2b9faf24e3b438d37c6c76d21..86c6f9676f36714af117893480045d5aa9948d5c 100644 (file)
@@ -1,3 +1,14 @@
+/*******************************************************************************\r
+ * Copyright (c) 2014, 2016 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
 package org.simantics.r.scl;\r
 \r
 import java.util.UUID;\r
@@ -5,11 +16,15 @@ import java.util.concurrent.ConcurrentHashMap;
 \r
 import org.rosuda.REngine.Rserve.RConnection;\r
 import org.rosuda.REngine.Rserve.RserveException;\r
+import org.simantics.db.layer0.variable.NodeSupport;\r
 import org.simantics.scl.runtime.function.Function;\r
 \r
 public class RSessionManager {\r
     static ConcurrentHashMap<String, RSession> CONNECTIONS =\r
             new ConcurrentHashMap<String, RSession>(); \r
+\r
+    static ConcurrentHashMap<String, NodeSupport<String>> SUPPORTS =\r
+            new ConcurrentHashMap<String, NodeSupport<String>>(); \r
     \r
     public static RSession getSession(String id) {\r
         // CONNECTIONS is ConcurrentHashMap so no synchronization is needed here\r
@@ -54,4 +69,16 @@ public class RSessionManager {
             return managedConnection;\r
         }\r
     }\r
+    \r
+    public static NodeSupport<String> getOrCreateNodeSupport(String id) {\r
+        synchronized(SUPPORTS) {\r
+            NodeSupport<String> result = SUPPORTS.get(id);\r
+            if(result == null) {\r
+                RSession session = getSession(id);\r
+                result = new NodeSupport<String>(session.getNodeManager());\r
+                SUPPORTS.put(id, result);\r
+            }\r
+            return result;\r
+        }\r
+    }\r
 }\r