| | |
| | | package com.yami.trading.api.websocket; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.yami.trading.bean.item.domain.Item; |
| | | import com.yami.trading.common.util.ApplicationContextUtils; |
| | | import com.yami.trading.service.item.ItemService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | import javax.websocket.server.ServerEndpoint; |
| | | import java.io.IOException; |
| | | import java.util.Calendar; |
| | | import java.util.List; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | /** |
| | |
| | | public static ConcurrentHashMap<String, WebSocketSession> tradeMap = new ConcurrentHashMap<String, WebSocketSession>(); |
| | | public static ConcurrentHashMap<String, WebSocketSession> depthMap = new ConcurrentHashMap<String, WebSocketSession>(); |
| | | |
| | | |
| | | |
| | | /** |
| | | * 连接建立成功调用的方法 |
| | | */ |
| | | @OnOpen |
| | | public void onOpen(@PathParam(value = "type") String type, |
| | | @PathParam(value = "param") String param, Session session) { |
| | | //停牌断开连接 |
| | | /*if (WebSocketEnum.SOCKET_ENUM_DEPTH.getCode().equals(type)) { |
| | | List<Item> items = ApplicationContextUtils.getApplicationContext().getBean(ItemService.class).list(); |
| | | if (CollectionUtil.isNotEmpty(items)) { |
| | | Item item = items.stream().filter(i -> param.equalsIgnoreCase(i.getSymbol())).findFirst().orElse(null); |
| | | if (item != null) { |
| | | if (item.getStatus() != null && item.getStatus() == 0) { |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | | }*/ |
| | | |
| | | WebSocketSession webSocketSession = new WebSocketSession(session, getTimeInMillis(), type, param); |
| | | // 加入set中 |
| | |
| | | try { |
| | | if (WebSocketEnum.SOCKET_ENUM_REALTIME.getCode().equals(type)) { |
| | | if (realtimeMap.get(key) != null) { |
| | | |
| | | realtimeMap.get(key).sendMessage(message); |
| | | } else { |
| | | System.out.println("realtimeMap中没有此key,不推送消息"); |