| | |
| | | /** 私有频道连接状态 */ |
| | | private final AtomicBoolean isPrivateConnected = new AtomicBoolean(false); |
| | | |
| | | /** 连接中标记,防重入 */ |
| | | private final AtomicBoolean isConnecting = new AtomicBoolean(false); |
| | | /** 公开频道连接中标记,防重入 */ |
| | | private final AtomicBoolean isPublicConnecting = new AtomicBoolean(false); |
| | | |
| | | /** 私有频道连接中标记,防重入 */ |
| | | private final AtomicBoolean isPrivateConnecting = new AtomicBoolean(false); |
| | | |
| | | /** 初始化标记,防重复 init */ |
| | | private final AtomicBoolean isInitialized = new AtomicBoolean(false); |
| | |
| | | String wsUrl = isPrivate ? config.getWsPrivateUrl() : config.getWsPublicUrl(); |
| | | String label = isPrivate ? "私有" : "公开"; |
| | | |
| | | if (isConnecting.get() || !isConnecting.compareAndSet(false, true)) { |
| | | AtomicBoolean connectingFlag = isPrivate ? isPrivateConnecting : isPublicConnecting; |
| | | if (connectingFlag.get() || !connectingFlag.compareAndSet(false, true)) { |
| | | log.info("[OKX-WS] 连接进行中,跳过重复{} WS请求", label); |
| | | return; |
| | | } |
| | |
| | | @Override |
| | | public void onOpen(ServerHandshake handshake) { |
| | | log.info("[OKX-WS] {} WS连接成功", label); |
| | | isConnecting.set(false); |
| | | connectingFlag.set(false); |
| | | |
| | | if (isPrivate) { |
| | | isPrivateConnected.set(true); |
| | |
| | | } else { |
| | | isPublicConnected.set(false); |
| | | } |
| | | isConnecting.set(false); |
| | | connectingFlag.set(false); |
| | | cancelPongTimeout(); |
| | | |
| | | if (sharedExecutor != null && !sharedExecutor.isShutdown() && !sharedExecutor.isTerminated()) { |
| | |
| | | @Override |
| | | public void onError(Exception ex) { |
| | | log.error("[OKX-WS] {} WS发生错误", label, ex); |
| | | connectingFlag.set(false); |
| | | if (isPrivate) { |
| | | isPrivateConnected.set(false); |
| | | } else { |
| | |
| | | } |
| | | } catch (URISyntaxException e) { |
| | | log.error("[OKX-WS] URI格式错误: {}", wsUrl, e); |
| | | isConnecting.set(false); |
| | | connectingFlag.set(false); |
| | | } |
| | | } |
| | | |