diff --git a/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/ConnectionStatus.java b/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/ConnectionStatus.java index 60265e802850..be444466bc76 100644 --- a/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/ConnectionStatus.java +++ b/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/ConnectionStatus.java @@ -6,7 +6,7 @@ import com.intellij.openapi.util.text.StringUtil; * @author nik */ public enum ConnectionStatus { - DISCONNECTED, CONNECTED, CONNECTING, DISCONNECTING; + DISCONNECTED, CONNECTED, CONNECTING; public String getPresentableText() { return StringUtil.capitalize(name().toLowerCase()); diff --git a/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/ServerConnection.java b/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/ServerConnection.java index ba3b4188f148..ddaf04b6ff9f 100644 --- a/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/ServerConnection.java +++ b/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/ServerConnection.java @@ -28,6 +28,8 @@ public interface ServerConnection { void connect(@NotNull Runnable onFinished); + void disconnect(); + void deploy(@NotNull DeploymentTask task, @NotNull ParameterizedRunnable onDeploymentStarted); void computeDeployments(@NotNull Runnable onFinished); diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ServerConnectionImpl.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ServerConnectionImpl.java index 6176998ef4e7..9d8ec2e8cbd3 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ServerConnectionImpl.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ServerConnectionImpl.java @@ -28,6 +28,7 @@ public class ServerConnectionImpl implements private final RemoteServer myServer; private final ServerConnector myConnector; private final ServerConnectionEventDispatcher myEventDispatcher; + private final ServerConnectionManagerImpl myConnectionManager; private volatile ConnectionStatus myStatus = ConnectionStatus.DISCONNECTED; private volatile String myStatusText; private volatile ServerRuntimeInstance myRuntimeInstance; @@ -35,10 +36,11 @@ public class ServerConnectionImpl implements private final Map myLocalDeployments = Collections.synchronizedMap(new HashMap()); private final Map myLoggingHandlers = new ConcurrentHashMap(); - public ServerConnectionImpl(RemoteServer server, ServerConnector connector, ServerConnectionEventDispatcher eventDispatcher) { + public ServerConnectionImpl(RemoteServer server, ServerConnector connector, ServerConnectionManagerImpl connectionManager) { myServer = server; myConnector = connector; - myEventDispatcher = eventDispatcher; + myConnectionManager = connectionManager; + myEventDispatcher = myConnectionManager.getEventDispatcher(); } @NotNull @@ -61,7 +63,7 @@ public class ServerConnectionImpl implements @Override public void connect(@NotNull final Runnable onFinished) { - disconnect(); + doDisconnect(); connectIfNeeded(new ServerConnector.ConnectionCallback() { @Override public void connected(@NotNull ServerRuntimeInstance serverRuntimeInstance) { @@ -75,7 +77,13 @@ public class ServerConnectionImpl implements }); } - private void disconnect() { + @Override + public void disconnect() { + myConnectionManager.removeConnection(myServer); + doDisconnect(); + } + + private void doDisconnect() { if (myStatus == ConnectionStatus.CONNECTED) { myRuntimeInstance = null; myConnector.disconnect(); @@ -93,7 +101,7 @@ public class ServerConnectionImpl implements myLocalDeployments.put(deploymentName, new DeploymentImpl(deploymentName, DeploymentStatus.DEPLOYING, null, null)); myLoggingHandlers.put(deploymentName, (LoggingHandlerImpl)task.getLoggingHandler()); onDeploymentStarted.run(deploymentName); - instance.deploy(task, new DeploymentOperationCallbackImpl(task.getSource(), deploymentName)); + instance.deploy(task, new DeploymentOperationCallbackImpl(deploymentName)); } }); } @@ -210,11 +218,9 @@ public class ServerConnectionImpl implements } private class DeploymentOperationCallbackImpl implements ServerRuntimeInstance.DeploymentOperationCallback { - private final DeploymentSource mySource; private final String myDeploymentName; - public DeploymentOperationCallbackImpl(DeploymentSource source, String deploymentName) { - mySource = source; + public DeploymentOperationCallbackImpl(String deploymentName) { myDeploymentName = deploymentName; } diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ServerConnectionManagerImpl.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ServerConnectionManagerImpl.java index af9d1412f802..d480270ce83f 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ServerConnectionManagerImpl.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ServerConnectionManagerImpl.java @@ -17,7 +17,7 @@ import java.util.Map; * @author nik */ public class ServerConnectionManagerImpl extends ServerConnectionManager { - private Map, ServerConnection> myConnections = new HashMap, ServerConnection>(); + private final Map, ServerConnection> myConnections = new HashMap, ServerConnection>(); private final ServerConnectionEventDispatcher myEventDispatcher = new ServerConnectionEventDispatcher(); @NotNull @@ -27,7 +27,7 @@ public class ServerConnectionManagerImpl extends ServerConnectionManager { ServerConnection connection = myConnections.get(server); if (connection == null) { ServerTaskExecutorImpl executor = new ServerTaskExecutorImpl(); - connection = new ServerConnectionImpl(server, server.getType().createConnector(server.getConfiguration(), executor), myEventDispatcher); + connection = new ServerConnectionImpl(server, server.getType().createConnector(server.getConfiguration(), executor), this); myConnections.put(server, connection); myEventDispatcher.fireConnectionCreated(connection); } @@ -40,6 +40,15 @@ public class ServerConnectionManagerImpl extends ServerConnectionManager { return myConnections.get(server); } + public void removeConnection(RemoteServer server) { + ApplicationManager.getApplication().assertIsDispatchThread(); + myConnections.remove(server); + } + + public ServerConnectionEventDispatcher getEventDispatcher() { + return myEventDispatcher; + } + @NotNull @Override public Collection getConnections() {