Browse Source

修复代码问题

feature/x
roger 1 year ago
parent
commit
1b33fedef8
  1. 43
      designer-base/src/main/java/com/fr/design/RPCConnectHandlerCenter.java
  2. 35
      designer-base/src/main/java/com/fr/design/lock/TemplateLockInfoReSave.java
  3. 13
      designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java
  4. 22
      designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java
  5. 2
      designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java

43
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<Workspace> listener = new Listener<Workspace>() {
@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<Workspace>() {
@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);
}
}
}

35
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<Workspace> listener = new Listener<Workspace>() {
@Override
public void on(Event event, Workspace workspace) {
List<JTemplate<?, ?>> 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<Workspace>() {
@Override
public void on(Event event, Workspace workspace) {
List<JTemplate<?, ?>> 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);
}
}
}

13
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<T extends BaseBook, U extends BaseUndoState<?>>
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();
}

22
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) {

2
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

Loading…
Cancel
Save