AsyncWebScocketMsgSend.java
1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.glsx.usercenter.component;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.websocket.EncodeException;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
/**
*
* @Title AsyncWebScocketMsgSend.java
* @Package com.glsx.usercenter.component
* @Description TODO 异步websocke消息发送
* @author zhanghj
* @date 2019年8月16日 下午4:11:55
* @version 1.0.0
*/
@Component
public class AsyncWebScocketMsgSend {
/**
* 群发自定义消息
* @throws EncodeException
* */
@Async
public void sendInfo(JSONArray orderList) {
ConcurrentHashMap<Integer, MyWebSocket> webSocketSet = MyWebSocket.webSocketSet;
for (Map.Entry<Integer, MyWebSocket> param : webSocketSet.entrySet()) {
for (int i = 0; i < orderList.size(); i++) {
try {
JSONObject orderObj = orderList.getJSONObject(i);
Integer managerId = orderObj.getInteger("managerId");
if (param.getKey().equals(managerId)) {
MyWebSocket myWebSocket = param.getValue();
myWebSocket.sendMessage(orderObj);
}
} catch (Exception e) {
continue;
}
}
}
}
}