Search in sources :

Example 1 with LoggingHandlerImpl

use of com.intellij.remoteServer.impl.runtime.log.LoggingHandlerImpl in project intellij-community by JetBrains.

the class ServerConnectionImpl method undeploy.

@Override
public void undeploy(@NotNull Deployment deployment, @NotNull final DeploymentRuntime runtime) {
    final String deploymentName = deployment.getName();
    final DeploymentImpl deploymentImpl;
    final Map<String, ? extends DeploymentImpl> deploymentsMap;
    synchronized (myLocalDeployments) {
        synchronized (myRemoteDeployments) {
            DeploymentImpl localDeployment = myLocalDeployments.get(deploymentName);
            if (localDeployment != null) {
                deploymentImpl = localDeployment;
                deploymentsMap = myLocalDeployments;
            } else {
                DeploymentImpl remoteDeployment = myRemoteDeployments.get(deploymentName);
                if (remoteDeployment != null) {
                    deploymentImpl = remoteDeployment;
                    deploymentsMap = myRemoteDeployments;
                } else {
                    deploymentImpl = null;
                    deploymentsMap = null;
                }
            }
            if (deploymentImpl != null) {
                deploymentImpl.changeState(DeploymentStatus.DEPLOYED, DeploymentStatus.UNDEPLOYING, null, null);
            }
        }
    }
    myEventDispatcher.queueDeploymentsChanged(this);
    DeploymentLogManagerImpl logManager = myLogManagers.get(deploymentName);
    final LoggingHandlerImpl loggingHandler = logManager == null ? null : logManager.getMainLoggingHandler();
    final Consumer<String> logConsumer = message -> {
        if (loggingHandler == null) {
            LOG.info(message);
        } else {
            loggingHandler.printlnSystemMessage(message);
        }
    };
    logConsumer.consume("Undeploying '" + deploymentName + "'...");
    runtime.undeploy(new DeploymentRuntime.UndeploymentTaskCallback() {

        @Override
        public void succeeded() {
            logConsumer.consume("'" + deploymentName + "' has been undeployed successfully.");
            if (deploymentImpl != null) {
                synchronized (deploymentsMap) {
                    if (deploymentImpl.changeState(DeploymentStatus.UNDEPLOYING, DeploymentStatus.NOT_DEPLOYED, null, null)) {
                        deploymentsMap.remove(deploymentName);
                    }
                }
            }
            DeploymentLogManagerImpl logManager = myLogManagers.remove(deploymentName);
            if (logManager != null) {
                logManager.disposeLogs();
            }
            myEventDispatcher.queueDeploymentsChanged(ServerConnectionImpl.this);
            computeDeployments(myRuntimeInstance, EmptyRunnable.INSTANCE);
        }

        @Override
        public void errorOccurred(@NotNull String errorMessage) {
            logConsumer.consume("Failed to undeploy '" + deploymentName + "': " + errorMessage);
            if (deploymentImpl != null) {
                synchronized (deploymentsMap) {
                    deploymentImpl.changeState(DeploymentStatus.UNDEPLOYING, DeploymentStatus.DEPLOYED, errorMessage, runtime);
                }
            }
            myEventDispatcher.queueDeploymentsChanged(ServerConnectionImpl.this);
        }
    });
}
Also used : com.intellij.remoteServer.runtime.deployment(com.intellij.remoteServer.runtime.deployment) java.util(java.util) ExecutionException(com.intellij.execution.ExecutionException) DeploymentLogManagerImpl(com.intellij.remoteServer.impl.runtime.log.DeploymentLogManagerImpl) ContainerUtil(com.intellij.util.containers.ContainerUtil) DeploymentConfiguration(com.intellij.remoteServer.configuration.deployment.DeploymentConfiguration) Deployment(com.intellij.remoteServer.runtime.Deployment) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) LocalDeploymentImpl(com.intellij.remoteServer.impl.runtime.deployment.LocalDeploymentImpl) DebugConnectionData(com.intellij.remoteServer.runtime.deployment.debug.DebugConnectionData) DebugConnector(com.intellij.remoteServer.runtime.deployment.debug.DebugConnector) ConnectionStatus(com.intellij.remoteServer.runtime.ConnectionStatus) RemoteServer(com.intellij.remoteServer.configuration.RemoteServer) LoggingHandlerImpl(com.intellij.remoteServer.impl.runtime.log.LoggingHandlerImpl) DebugConnectionDataNotAvailableException(com.intellij.remoteServer.runtime.deployment.debug.DebugConnectionDataNotAvailableException) DeploymentTaskImpl(com.intellij.remoteServer.impl.runtime.deployment.DeploymentTaskImpl) Nullable(org.jetbrains.annotations.Nullable) ServerConnection(com.intellij.remoteServer.runtime.ServerConnection) ApplicationManager(com.intellij.openapi.application.ApplicationManager) DeploymentImpl(com.intellij.remoteServer.impl.runtime.deployment.DeploymentImpl) ServerConnector(com.intellij.remoteServer.runtime.ServerConnector) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) LoggingHandlerImpl(com.intellij.remoteServer.impl.runtime.log.LoggingHandlerImpl) LocalDeploymentImpl(com.intellij.remoteServer.impl.runtime.deployment.LocalDeploymentImpl) DeploymentImpl(com.intellij.remoteServer.impl.runtime.deployment.DeploymentImpl) DeploymentLogManagerImpl(com.intellij.remoteServer.impl.runtime.log.DeploymentLogManagerImpl)

Aggregations

ExecutionException (com.intellij.execution.ExecutionException)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Project (com.intellij.openapi.project.Project)1 EmptyRunnable (com.intellij.openapi.util.EmptyRunnable)1 RemoteServer (com.intellij.remoteServer.configuration.RemoteServer)1 DeploymentConfiguration (com.intellij.remoteServer.configuration.deployment.DeploymentConfiguration)1 DeploymentImpl (com.intellij.remoteServer.impl.runtime.deployment.DeploymentImpl)1 DeploymentTaskImpl (com.intellij.remoteServer.impl.runtime.deployment.DeploymentTaskImpl)1 LocalDeploymentImpl (com.intellij.remoteServer.impl.runtime.deployment.LocalDeploymentImpl)1 DeploymentLogManagerImpl (com.intellij.remoteServer.impl.runtime.log.DeploymentLogManagerImpl)1 LoggingHandlerImpl (com.intellij.remoteServer.impl.runtime.log.LoggingHandlerImpl)1 ConnectionStatus (com.intellij.remoteServer.runtime.ConnectionStatus)1 Deployment (com.intellij.remoteServer.runtime.Deployment)1 ServerConnection (com.intellij.remoteServer.runtime.ServerConnection)1 ServerConnector (com.intellij.remoteServer.runtime.ServerConnector)1 com.intellij.remoteServer.runtime.deployment (com.intellij.remoteServer.runtime.deployment)1 DebugConnectionData (com.intellij.remoteServer.runtime.deployment.debug.DebugConnectionData)1 DebugConnectionDataNotAvailableException (com.intellij.remoteServer.runtime.deployment.debug.DebugConnectionDataNotAvailableException)1 DebugConnector (com.intellij.remoteServer.runtime.deployment.debug.DebugConnector)1