Fix findbugs warnings + address concurrency issues in handlers
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / NewConnectionHandler.java
index f635102a359f96a5ed4d07a7c1ad3829d32e346b..0f898eb3c0a5a3b6fabd3e4c18241699ad83285d 100644 (file)
@@ -114,19 +114,24 @@ public class NewConnectionHandler extends BaseControlViewHandler {
                 return null;
             }
         }
-
+        
         if (host != null) {
-            // successful creation of host
-            TargetNodeComponent node = null;
-            if (!fRoot.containsChild(hostName)) {
-                node = new TargetNodeComponent(hostName, fRoot, host);
-                fRoot.addChild(node);
-            }
-            else {
-                node = (TargetNodeComponent)fRoot.getChild(hostName);
+            fLock.lock();
+            try {
+                // successful creation of host
+                TargetNodeComponent node = null;
+                if (!fRoot.containsChild(hostName)) {
+                    node = new TargetNodeComponent(hostName, fRoot, host);
+                    fRoot.addChild(node);
+                }
+                else {
+                    node = (TargetNodeComponent)fRoot.getChild(hostName);
+                }
+
+                node.connect();
+            } finally {
+                fLock.unlock();
             }
-
-            node.connect();
         }
         return null;
     }
@@ -145,12 +150,24 @@ public class NewConnectionHandler extends BaseControlViewHandler {
             return false;
         }
 
-        fRoot = null;
+        ITraceControlComponent root = null;
 
         // no need to verify part because it has been already done in getWorkbenchPage()
         IWorkbenchPart part = page.getActivePart(); 
-        fRoot = ((ControlView) part).getTraceControlRoot();
+        root = ((ControlView) part).getTraceControlRoot();
+        
+        boolean isEnabled = root != null;
+        
+        fLock.lock();
+        try {
+            fRoot = null;
+            if (isEnabled) {
+                fRoot = root;
+            }
+        } finally {
+            fLock.unlock();
+        }
         
-        return (fRoot != null);
+        return isEnabled;
     }
 }
This page took 0.024287 seconds and 5 git commands to generate.