From ae73305f84e4dde3b2cc85c565fccb831fb2d4b4 Mon Sep 17 00:00:00 2001 From: Maksim Date: Mon, 2 Mar 2020 21:25:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E6=BB=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/socketio/DesignerSocketIO.java | 167 +++++++----------- 1 file changed, 63 insertions(+), 104 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/socketio/DesignerSocketIO.java b/designer-realize/src/main/java/com/fr/design/mainframe/socketio/DesignerSocketIO.java index 63bc3d999b..e2b13b1adf 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/socketio/DesignerSocketIO.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/socketio/DesignerSocketIO.java @@ -13,6 +13,7 @@ import com.fr.report.RemoteDesignConstants; import com.fr.serialization.SerializerHelper; import com.fr.stable.ArrayUtils; import com.fr.third.apache.log4j.spi.LoggingEvent; +import com.fr.third.guava.base.Optional; import com.fr.workspace.WorkContext; import com.fr.workspace.Workspace; import com.fr.workspace.base.WorkspaceConstants; @@ -35,19 +36,28 @@ public class DesignerSocketIO { Disconnecting } - private static Socket socket = null; + private static Optional socketIO = Optional.absent(); private static Status status = Status.Disconnected; - //维护一个当前工作环境的uri列表 - private static String[] uri; - //维护一个关于uri列表的计数器 - private static int count; + private static final Emitter.Listener printLog = new Emitter.Listener() { + @Override + public void call(Object... objects) { + if (ArrayUtils.isNotEmpty(objects)) { + try { + LoggingEvent event = SerializerHelper.deserialize((byte[]) objects[0]); + DesignerLogger.log(event); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + } + }; public static void close() { - if (socket != null) { + if (socketIO.isPresent()) { status = Status.Disconnecting; - socket.close(); - socket = null; + socketIO.get().close(); + socketIO = Optional.absent(); } } @@ -56,42 +66,57 @@ public class DesignerSocketIO { if (current.isLocal()) { return; } - //每当更换工作环境,更新uri列表,同时更新计数器count - try { - uri = getSocketUri(); - } catch (IOException e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - count = 0; - //建立socket并注册监听 - createSocket(); - } - - private static void createSocket(){ - //根据uri和计数器建立连接,并注册监听 try { - if(count