tmf remote: Fix connection handling for explicitely opened connections
authorBernd Hufmann <Bernd.Hufmann@ericsson.com>
Tue, 31 Mar 2015 18:46:21 +0000 (14:46 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Wed, 1 Apr 2015 16:58:29 +0000 (12:58 -0400)
It turns our that call to remoteConnection.isOpen() sends a
connection changed event with type closed. This will overwrite
the flag to false that keeps track whether the connection was
opened explicitely.

Also, when calling disconnect() on the RemoteSystemProxy only
close the connection if it was not explicitely opened.

Change-Id: Idce1cf9515c01667ce2e4d49a30d8296a8a7977d
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/44946
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
org.eclipse.tracecompass.tmf.remote.core/src/org/eclipse/tracecompass/tmf/remote/core/proxy/RemoteSystemProxy.java

index 092e77e5c80329acfc7d1bf34f9ae617027ea419..685aaad0dc02a974b882e6475ade607ef547fe3f 100644 (file)
@@ -80,8 +80,9 @@ public class RemoteSystemProxy implements IRemoteConnectionChangeListener {
     public void connect(IProgressMonitor monitor) throws ExecutionException {
         try {
             if (!fHost.isOpen()) {
     public void connect(IProgressMonitor monitor) throws ExecutionException {
         try {
             if (!fHost.isOpen()) {
-                fExplicitConnect = true;
+                // Note that open() may trigger a RemoteConnectionChangeEvent
                 fHost.open(monitor);
                 fHost.open(monitor);
+                fExplicitConnect = true;
             }
         } catch (RemoteConnectionException e) {
             throw new ExecutionException("Cannot connect " + fHost.getName(), e); //$NON-NLS-1$
             }
         } catch (RemoteConnectionException e) {
             throw new ExecutionException("Cannot connect " + fHost.getName(), e); //$NON-NLS-1$
@@ -89,10 +90,13 @@ public class RemoteSystemProxy implements IRemoteConnectionChangeListener {
     }
 
     /**
     }
 
     /**
-     * Disconnects from the remote connection.
+     * Disconnects from the remote connection, may close the connection.
      */
     public void disconnect() {
      */
     public void disconnect() {
-        fHost.close();
+        if (fExplicitConnect) {
+            fHost.close();
+            fExplicitConnect = false;
+        }
     }
 
     /**
     }
 
     /**
@@ -100,9 +104,7 @@ public class RemoteSystemProxy implements IRemoteConnectionChangeListener {
      */
     public void dispose() {
         fHost.removeConnectionChangeListener(this);
      */
     public void dispose() {
         fHost.removeConnectionChangeListener(this);
-        if (fExplicitConnect) {
-            fHost.close();
-        }
+        disconnect();
     }
 
     /**
     }
 
     /**
This page took 0.035848 seconds and 5 git commands to generate.