From 1b33fedef80097a538385671d20c6de0a2152eaa Mon Sep 17 00:00:00 2001 From: roger Date: Thu, 14 Dec 2023 14:20:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/RPCConnectHandlerCenter.java | 43 +++++++++++++++---- .../design/lock/TemplateLockInfoReSave.java | 35 +++++++++------ .../com/fr/design/mainframe/JTemplate.java | 13 +++++- .../worker/save/SaveFailureHandler.java | 22 ++++++++++ .../fr/start/module/DesignerActivator.java | 2 + 5 files changed, 93 insertions(+), 22 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/RPCConnectHandlerCenter.java b/designer-base/src/main/java/com/fr/design/RPCConnectHandlerCenter.java index a80fb3c3c9..eb08789d0d 100644 --- a/designer-base/src/main/java/com/fr/design/RPCConnectHandlerCenter.java +++ b/designer-base/src/main/java/com/fr/design/RPCConnectHandlerCenter.java @@ -19,6 +19,7 @@ import com.fr.workspace.Workspace; import com.fr.workspace.WorkspaceEvent; import com.fr.workspace.base.WorkspaceConstants; import com.fr.workspace.connect.WorkspaceConnectionInfo; +import com.fr.workspace.engine.channel.WorkspaceChannelFactory; import com.fr.workspace.engine.exception.WorkspaceConnectionException; import javax.swing.JOptionPane; @@ -36,18 +37,20 @@ public class RPCConnectHandlerCenter { private static volatile boolean alerting = false; private static final int TIMEOUT = 5000; + private static Listener listener = new Listener() { + @Override + public void on(Event event, Workspace workspace) { + //暂时先不做重连处理,3次RPC连接失败后提示切换工作目录 + showRPCDisconnectDialog(); + } + }; + /** * 开启事件监听 */ public static void startListener() { if (!WorkContext.getCurrent().isLocal()) { - EventDispatcher.listen(WorkspaceEvent.LostConnect, new Listener() { - @Override - public void on(Event event, Workspace workspace) { - //暂时先不做重连处理,3次RPC连接失败后提示切换工作目录 - showRPCDisconnectDialog(); - } - }); + EventDispatcher.listen(WorkspaceEvent.LostConnect, listener); } } @@ -59,12 +62,27 @@ public class RPCConnectHandlerCenter { } /** - * 连接检测,从DesignerSocketIO中移过来的 + * RPC连接测试 * * @param info 连接信息 * @return 是否连接成功 */ public static boolean checkRPCConnect(WorkspaceConnectionInfo info) { + try { + return WorkspaceChannelFactory.testConnection(info); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e, e.getMessage()); + return false; + } + } + + /** + * http连接检测,从DesignerSocketIO中移过来的,先保留着 + * + * @param info 连接信息 + * @return 是否连接成功 + */ + public static boolean checkHttpConnect(WorkspaceConnectionInfo info) { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet(StableUtils.pathJoin(info.getUrl(), WorkspaceConstants.CONTROLLER_PREFIX, WorkspaceConstants.VT)); RequestConfig requestConfig = RequestConfig @@ -129,4 +147,13 @@ public class RPCConnectHandlerCenter { private static boolean isErrorStatus(int status) { return status >= 500 && status <= 600; } + + /** + * 停止事件监听 + */ + public static void stopListener() { + if (!WorkContext.getCurrent().isLocal()) { + EventDispatcher.stopListen(listener); + } + } } diff --git a/designer-base/src/main/java/com/fr/design/lock/TemplateLockInfoReSave.java b/designer-base/src/main/java/com/fr/design/lock/TemplateLockInfoReSave.java index 8812be93f7..f1f927abb1 100644 --- a/designer-base/src/main/java/com/fr/design/lock/TemplateLockInfoReSave.java +++ b/designer-base/src/main/java/com/fr/design/lock/TemplateLockInfoReSave.java @@ -23,23 +23,34 @@ import java.util.List; */ public class TemplateLockInfoReSave { + private static Listener listener = new Listener() { + @Override + public void on(Event event, Workspace workspace) { + List> templates = HistoryTemplateListCache.getInstance().getHistoryList(); + if (CollectionUtils.isEmpty(templates)) { + return; + } + String[] paths = templates.stream().map(JTemplate::getPath).toArray(String[]::new); + String[] lockedPath = WorkContext.getCurrent().get(LockInfoOperator.class).lockTemplates(paths); + FineLoggerFactory.getLogger().warn("template lock failed:{}", String.join(";", lockedPath)); + } + }; + /** * 启动监听 */ public static void startListener() { if (!WorkContext.getCurrent().isLocal()) { - EventDispatcher.listen(WorkspaceEvent.ReConnectSuccess, new Listener() { - @Override - public void on(Event event, Workspace workspace) { - List> templates = HistoryTemplateListCache.getInstance().getHistoryList(); - if (CollectionUtils.isEmpty(templates)) { - return; - } - String[] paths = templates.stream().map(JTemplate::getPath).toArray(String[]::new); - String[] lockedPath = WorkContext.getCurrent().get(LockInfoOperator.class).lockTemplates(paths); - FineLoggerFactory.getLogger().warn("template lock failed:{}", String.join(";", lockedPath)); - } - }); + EventDispatcher.listen(WorkspaceEvent.ConnectSuccess, listener); + } + } + + /** + * 停止事件监听 + */ + public static void stopListener() { + if (!WorkContext.getCurrent().isLocal()) { + EventDispatcher.stopListen(listener); } } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index f8033d926a..3cd8fdb78c 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -92,6 +92,7 @@ import com.fr.plugin.observer.PluginEventListener; import com.fr.plugin.observer.PluginEventType; import com.fr.plugin.observer.PluginListenerRegistration; import com.fr.report.InconsistentLockException; +import com.fr.report.LockedException; import com.fr.report.UnLockedException; import com.fr.report.cell.Elem; import com.fr.report.cell.cellattr.CellImage; @@ -103,6 +104,7 @@ import com.fr.stable.StringUtils; import com.fr.stable.core.UUID; import com.fr.widgettheme.designer.WidgetThemeDisplayAction; import com.fr.workspace.WorkContext; +import com.fr.workspace.base.UserInfo; import com.fr.workspace.server.lock.TplOperator; import javax.swing.BorderFactory; @@ -1059,13 +1061,20 @@ public abstract class JTemplate> protected void checkBeforeSave() throws Exception { // 保存前校验下未解锁 - if (WorkContext.getCurrent().get(LockInfoOperator.class).isTplUnLocked(getEditingFILE().getPath())) { + LockInfoOperator lockInfoOperator = WorkContext.getCurrent().get(LockInfoOperator.class); + String path = getEditingFILE().getPath(); + if (lockInfoOperator.isTplUnLocked(path)) { throw new UnLockedException(); } + //睡眠超过90s之后,锁信息会被清掉,之后其他人可能打开模板进行锁定,所以定这里还判断一下模板是否被其他人锁 + UserInfo userInfo = lockInfoOperator.getUserInfo(path); + if (userInfo != null) { + throw new LockedException(userInfo); + } // 过滤掉本地文件 boolean localFile = getEditingFILE() instanceof FileFILE; boolean inconsistent = !localFile && getEditingFILE().exists() - && !WorkContext.getCurrent().get(LockInfoOperator.class).consistentCheckAndLockIfNecessary(getEditingFILE().getPath()); + && !lockInfoOperator.consistentCheckAndLockIfNecessary(path); if (inconsistent) { throw new InconsistentLockException(); } diff --git a/designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java b/designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java index 9ab897d7e8..458ead48a1 100644 --- a/designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java +++ b/designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java @@ -4,6 +4,7 @@ import com.fr.common.exception.ThrowableHandler; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.i18n.Toolkit; +import com.fr.design.lock.LockInfoDialog; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; import com.fr.design.ui.util.UIUtil; @@ -11,7 +12,9 @@ import com.fr.design.utils.TemplateUtils; import com.fr.file.FileNodeFILE; import com.fr.file.filetree.FileNode; import com.fr.general.IOUtils; +import com.fr.report.LockedException; import com.fr.report.UnLockedException; +import com.fr.workspace.base.UserInfo; import com.fr.workspace.exception.DiskSpaceFullException; import com.fr.report.InconsistentLockException; import java.awt.Frame; @@ -89,6 +92,25 @@ public class SaveFailureHandler implements ThrowableHandler { } }, + LOCKED { + @Override + public boolean process(Throwable e) { + LockedException exception = null; + if (e.getCause() instanceof LockedException) { + exception = (LockedException) e.getCause(); + } + if (e instanceof LockedException) { + exception = (LockedException) e; + } + if (exception != null) { + UserInfo userInfo = exception.getUserInfo(); + LockInfoDialog.show(userInfo); + return true; + } + return false; + } + }, + Other { @Override public boolean process(Throwable e) { diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java b/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java index 4fd0a93854..15edc3e095 100644 --- a/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java +++ b/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java @@ -541,6 +541,8 @@ public class DesignerActivator extends Activator implements Prepare { public void stop() { unloadLogAppender(); DesignerSocketIO.close(); + TemplateLockInfoReSave.stopListener(); + RPCConnectHandlerCenter.stopListener(); } @Override