Fix open method, reentrant calls

Project: http://git-wip-us.apache.org/repos/asf/incubator-wave/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-wave/commit/d8a5b956
Tree: http://git-wip-us.apache.org/repos/asf/incubator-wave/tree/d8a5b956
Diff: http://git-wip-us.apache.org/repos/asf/incubator-wave/diff/d8a5b956

Branch: refs/heads/swellrt
Commit: d8a5b9564bb4dea6a1ce8084a5c9bd14b4a6d93a
Parents: 5571998
Author: Pablo Ojanguren <pablo...@gmail.com>
Authored: Tue Sep 6 18:00:47 2016 +0200
Committer: Pablo Ojanguren <pablo...@gmail.com>
Committed: Wed Sep 7 10:52:15 2016 +0200

----------------------------------------------------------------------
 wave/src/main/java/org/swellrt/api/SwellRT.java | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/d8a5b956/wave/src/main/java/org/swellrt/api/SwellRT.java
----------------------------------------------------------------------
diff --git a/wave/src/main/java/org/swellrt/api/SwellRT.java 
b/wave/src/main/java/org/swellrt/api/SwellRT.java
index 90c5760..6529863 100644
--- a/wave/src/main/java/org/swellrt/api/SwellRT.java
+++ b/wave/src/main/java/org/swellrt/api/SwellRT.java
@@ -465,6 +465,17 @@ public class SwellRT implements EntryPoint, 
UnsavedDataListener {
       
     };
     
+    if (waveRegistry.containsKey(waveId)) {    
+      ModelJS cobJsFacade = objectRegistry.get(waveId);
+      
+      if (cobJsFacade != null)
+        
callback.onComplete(ServiceCallback.JavaScriptResponse.success(cobJsFacade));
+      else
+        
callback.onComplete(ServiceCallback.JavaScriptResponse.error("SERVICE_EXCEPTION",
 "Object is open but no native facade found"));
+      
+      return; // don't continue
+    }
+    
     
     if (shouldOpenWebsocket) {
       openWebsocket(new Callback<Void, Void>() {
@@ -508,16 +519,16 @@ public class SwellRT implements EntryPoint, 
UnsavedDataListener {
     String id = extractWaveIdParameter(parameters);
     Preconditions.checkArgument(id != null, "Missing object or id");
     WaveId waveId = WaveId.deserialise(id);
-    Preconditions.checkArgument(waveRegistry.containsKey(waveId), "Object is 
not opened");    
+    Preconditions.checkArgument(waveRegistry.containsKey(waveId), "Object is 
not open");    
     
     for (TextEditor e: editorRegistry.values())
       if (e.getWaveId().equals(waveId))
         e.cleanUp();
     
     waveRegistry.remove(waveId).destroy();
-    ModelJS co = objectRegistry.remove(waveId);
-    SwellRTUtils.deleteJsObject(co);
-   
+    ModelJS co = objectRegistry.get(waveId);
+    objectRegistry.remove(waveId);
+    SwellRTUtils.deleteJsObject(co);   
   }
 
   

Reply via email to