remote servers: start/stop actions implemented in servers view

This commit is contained in:
nik
2013-08-15 12:51:16 +04:00
parent 3385890eb9
commit 3a958ef8da
4 changed files with 28 additions and 11 deletions
@@ -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());
@@ -28,6 +28,8 @@ public interface ServerConnection<D extends DeploymentConfiguration> {
void connect(@NotNull Runnable onFinished);
void disconnect();
void deploy(@NotNull DeploymentTask<D> task, @NotNull ParameterizedRunnable<String> onDeploymentStarted);
void computeDeployments(@NotNull Runnable onFinished);
@@ -28,6 +28,7 @@ public class ServerConnectionImpl<D extends DeploymentConfiguration> implements
private final RemoteServer<?> myServer;
private final ServerConnector<D> myConnector;
private final ServerConnectionEventDispatcher myEventDispatcher;
private final ServerConnectionManagerImpl myConnectionManager;
private volatile ConnectionStatus myStatus = ConnectionStatus.DISCONNECTED;
private volatile String myStatusText;
private volatile ServerRuntimeInstance<D> myRuntimeInstance;
@@ -35,10 +36,11 @@ public class ServerConnectionImpl<D extends DeploymentConfiguration> implements
private final Map<String, Deployment> myLocalDeployments = Collections.synchronizedMap(new HashMap<String, Deployment>());
private final Map<String, LoggingHandlerImpl> myLoggingHandlers = new ConcurrentHashMap<String, LoggingHandlerImpl>();
public ServerConnectionImpl(RemoteServer<?> server, ServerConnector<D> 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<D extends DeploymentConfiguration> implements
@Override
public void connect(@NotNull final Runnable onFinished) {
disconnect();
doDisconnect();
connectIfNeeded(new ServerConnector.ConnectionCallback<D>() {
@Override
public void connected(@NotNull ServerRuntimeInstance<D> serverRuntimeInstance) {
@@ -75,7 +77,13 @@ public class ServerConnectionImpl<D extends DeploymentConfiguration> 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<D extends DeploymentConfiguration> 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<D extends DeploymentConfiguration> 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;
}
@@ -17,7 +17,7 @@ import java.util.Map;
* @author nik
*/
public class ServerConnectionManagerImpl extends ServerConnectionManager {
private Map<RemoteServer<?>, ServerConnection> myConnections = new HashMap<RemoteServer<?>, ServerConnection>();
private final Map<RemoteServer<?>, ServerConnection> myConnections = new HashMap<RemoteServer<?>, 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<ServerConnection> getConnections() {