From 16702447d8b92f3449caccc3de4ec122ec2e2a52 Mon Sep 17 00:00:00 2001 From: Michael Golubev Date: Tue, 25 Jul 2017 23:33:46 +0200 Subject: [PATCH] IDEA-CR-23082 - remove hierarchy of inner classes to make code simpler --- .../impl/runtime/ServerConnectionImpl.java | 70 +++++++------------ 1 file changed, 24 insertions(+), 46 deletions(-) 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 b2be63571f01..4abbfc5cfab9 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 @@ -235,7 +235,7 @@ public class ServerConnectionImpl implements @Override public void undeploy(@NotNull Deployment deployment, @NotNull final DeploymentRuntime runtime) { String deploymentName = deployment.getName(); - final StateTransition undeployInProgress = myAllDeployments.startUndeploy(deploymentName); + final UndeployTransition undeployInProgress = myAllDeployments.startUndeploy(deploymentName); myEventDispatcher.queueDeploymentsChanged(this); @@ -507,7 +507,7 @@ public class ServerConnectionImpl implements @SuppressWarnings("Duplicates") @Nullable - public StateTransition startUndeploy(@NotNull String deploymentName) { + public UndeployTransition startUndeploy(@NotNull String deploymentName) { synchronized (myLocalLock) { synchronized (myRemoteLock) { @@ -518,7 +518,7 @@ public class ServerConnectionImpl implements @Override public void succeeded() { synchronized (myLocalLock) { - if (completeStateChange()) { + if (tryChangeToTerminalState(DeploymentStatus.NOT_DEPLOYED)) { myLocalDeployments.remove(getDeployment().getName()); myCachedAllDeployments = null; } @@ -528,7 +528,7 @@ public class ServerConnectionImpl implements @Override public void failed() { synchronized (myLocalLock) { - rollbackStateChange(); + tryChangeToTerminalState(DeploymentStatus.DEPLOYED); } } }; @@ -539,7 +539,7 @@ public class ServerConnectionImpl implements @Override public void succeeded() { synchronized (myRemoteLock) { - if (completeStateChange()) { + if (tryChangeToTerminalState(DeploymentStatus.NOT_DEPLOYED)) { myRemoteDeployments.remove(getDeployment().getName()); myCachedAllDeployments = null; } @@ -549,7 +549,7 @@ public class ServerConnectionImpl implements @Override public void failed() { synchronized (myRemoteLock) { - rollbackStateChange(); + tryChangeToTerminalState(DeploymentStatus.DEPLOYED); } } }; @@ -558,48 +558,26 @@ public class ServerConnectionImpl implements } } } - - private static abstract class UndeployTransition extends StateTransitionImpl { - public UndeployTransition(@NotNull DeploymentImpl deployment) { - super(deployment, DeploymentStatus.DEPLOYED, DeploymentStatus.DEPLOYING, DeploymentStatus.NOT_DEPLOYED); - } - } - - private static abstract class StateTransitionImpl implements StateTransition { - private final DeploymentImpl myDeployment; - private final DeploymentStatus myStartStatus; - private final DeploymentStatus myInProgressStatus; - private final DeploymentStatus myEndStatus; - - public StateTransitionImpl(@NotNull DeploymentImpl deployment, - @NotNull DeploymentStatus start, @NotNull DeploymentStatus inProgress, @NotNull DeploymentStatus end) { - - myDeployment = deployment; - myStartStatus = start; - myEndStatus = end; - myInProgressStatus = inProgress; - // - myDeployment.changeState(start, inProgress, null, null); - } - - @NotNull - protected final DeploymentImpl getDeployment() { - return myDeployment; - } - - protected boolean completeStateChange() { - return myDeployment.changeState(myInProgressStatus, myEndStatus, null, null); - } - - protected boolean rollbackStateChange() { - return myDeployment.changeState(myInProgressStatus, myStartStatus, null, null); - } - } } - private interface StateTransition { - void succeeded(); + private static abstract class UndeployTransition { + private final DeploymentImpl myDeployment; - void failed(); + public UndeployTransition(@NotNull DeploymentImpl deployment) { + myDeployment = deployment; + myDeployment.changeState(DeploymentStatus.DEPLOYED, DeploymentStatus.DEPLOYING, null, null); + } + + public abstract void succeeded(); + + public abstract void failed(); + + protected boolean tryChangeToTerminalState(DeploymentStatus terminalState) { + return myDeployment.changeState(DeploymentStatus.DEPLOYING, terminalState, null, null); + } + + protected DeploymentImpl getDeployment() { + return myDeployment; + } } }