diff --git a/designer-base/src/main/java/com/fr/design/backup/EnvBackupHelper.java b/designer-base/src/main/java/com/fr/design/backup/EnvBackupHelper.java index bb9575ea19..73d0cbc1b1 100644 --- a/designer-base/src/main/java/com/fr/design/backup/EnvBackupHelper.java +++ b/designer-base/src/main/java/com/fr/design/backup/EnvBackupHelper.java @@ -4,11 +4,13 @@ import com.fanruan.carina.Carina; import com.fanruan.config.realm.ConfigRepositoryFactory; import com.fanruan.config.realm.local.LocalConfigRepositoryBuilder; import com.fr.design.ConfigHelper; +import com.fr.design.env.RemoteWorkspace; import com.fr.design.mem.MemConfigBackupManager; import com.fr.design.mem.MemConfigRepositoryBuilder; import com.fr.log.FineLoggerFactory; import com.fr.workspace.WorkContext; import com.fr.workspace.Workspace; +import com.fr.workspace.server.repository.connect.FineWorkspaceHttpClient; import java.util.Properties; @@ -42,11 +44,13 @@ public class EnvBackupHelper { FineLoggerFactory.getLogger().info("[EnvBackup] 1.back start..."); this.swtiching = true; local = WorkContext.getCurrent().isLocal(); + origin = WorkContext.getCurrent(); if (local) { properties = ConfigHelper.getEnvProperties(); path = ConfigHelper.getEnvPropertiesPath(); + } else { + closeEnv(); } - origin = WorkContext.getCurrent(); } /** @@ -107,10 +111,30 @@ public class EnvBackupHelper { } else { // 如果是远程,则新环境的配置全部弃用,直接走老的 MemConfigBackupManager.getInstance().failed(); + rollbackEnv(); } } + /** + * 关闭环境 + */ + public void closeEnv() { + // 如果原来是远程,要先发请求告诉原来的环境我这边要断开 + if (origin instanceof RemoteWorkspace) { + origin.close(); + } + } + + /** + * 重新进入老环境 + */ + public void rollbackEnv() { + if (origin instanceof RemoteWorkspace && ((RemoteWorkspace) origin).getClient() instanceof FineWorkspaceHttpClient) { + ((FineWorkspaceHttpClient) ((RemoteWorkspace) origin).getClient()).startHeartBeat(); + } + } + public boolean isSwtiching() { return swtiching; }