正在显示
6 个修改的文件
包含
189 行增加
和
0 行删除
| @@ -3,6 +3,9 @@ package com.crossoverjie.cim.client.service; | @@ -3,6 +3,9 @@ package com.crossoverjie.cim.client.service; | ||
| 3 | import com.crossoverjie.cim.client.vo.req.GroupReqVO; | 3 | import com.crossoverjie.cim.client.vo.req.GroupReqVO; |
| 4 | import com.crossoverjie.cim.client.vo.req.LoginReqVO; | 4 | import com.crossoverjie.cim.client.vo.req.LoginReqVO; |
| 5 | import com.crossoverjie.cim.client.vo.res.CIMServerResVO; | 5 | import com.crossoverjie.cim.client.vo.res.CIMServerResVO; |
| 6 | +import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO; | ||
| 7 | + | ||
| 8 | +import java.util.List; | ||
| 6 | 9 | ||
| 7 | /** | 10 | /** |
| 8 | * Function: | 11 | * Function: |
| @@ -26,4 +29,10 @@ public interface RouteRequest { | @@ -26,4 +29,10 @@ public interface RouteRequest { | ||
| 26 | * @throws Exception | 29 | * @throws Exception |
| 27 | */ | 30 | */ |
| 28 | CIMServerResVO.ServerInfo getCIMServer(LoginReqVO loginReqVO) throws Exception; | 31 | CIMServerResVO.ServerInfo getCIMServer(LoginReqVO loginReqVO) throws Exception; |
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * | ||
| 35 | + * @return 获取所有在线用户 | ||
| 36 | + */ | ||
| 37 | + List<OnlineUsersResVO.DataBodyBean> onlineUsers()throws Exception ; | ||
| 29 | } | 38 | } |
| @@ -6,6 +6,7 @@ import com.crossoverjie.cim.client.service.MsgHandle; | @@ -6,6 +6,7 @@ import com.crossoverjie.cim.client.service.MsgHandle; | ||
| 6 | import com.crossoverjie.cim.client.service.RouteRequest; | 6 | import com.crossoverjie.cim.client.service.RouteRequest; |
| 7 | import com.crossoverjie.cim.client.vo.req.GroupReqVO; | 7 | import com.crossoverjie.cim.client.vo.req.GroupReqVO; |
| 8 | import com.crossoverjie.cim.client.vo.req.P2PReqVO; | 8 | import com.crossoverjie.cim.client.vo.req.P2PReqVO; |
| 9 | +import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO; | ||
| 9 | import com.crossoverjie.cim.common.enums.SystemCommandEnumType; | 10 | import com.crossoverjie.cim.common.enums.SystemCommandEnumType; |
| 10 | import com.crossoverjie.cim.common.util.StringUtil; | 11 | import com.crossoverjie.cim.common.util.StringUtil; |
| 11 | import org.slf4j.Logger; | 12 | import org.slf4j.Logger; |
| @@ -13,6 +14,7 @@ import org.slf4j.LoggerFactory; | @@ -13,6 +14,7 @@ import org.slf4j.LoggerFactory; | ||
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 14 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.stereotype.Service; | 15 | import org.springframework.stereotype.Service; |
| 15 | 16 | ||
| 17 | +import java.util.List; | ||
| 16 | import java.util.Map; | 18 | import java.util.Map; |
| 17 | import java.util.concurrent.ThreadPoolExecutor; | 19 | import java.util.concurrent.ThreadPoolExecutor; |
| 18 | import java.util.concurrent.TimeUnit; | 20 | import java.util.concurrent.TimeUnit; |
| @@ -91,6 +93,11 @@ public class MsgHandler implements MsgHandle { | @@ -91,6 +93,11 @@ public class MsgHandler implements MsgHandle { | ||
| 91 | shutdown(); | 93 | shutdown(); |
| 92 | } else if (SystemCommandEnumType.ALL.getCommandType().trim().equals(msg)){ | 94 | } else if (SystemCommandEnumType.ALL.getCommandType().trim().equals(msg)){ |
| 93 | printAllCommand(allStatusCode); | 95 | printAllCommand(allStatusCode); |
| 96 | + | ||
| 97 | + } else if (SystemCommandEnumType.ONLINE_USER.getCommandType().trim().equals(msg)){ | ||
| 98 | + //打印在线用户 | ||
| 99 | + printOnlineUsers(); | ||
| 100 | + | ||
| 94 | }else { | 101 | }else { |
| 95 | printAllCommand(allStatusCode); | 102 | printAllCommand(allStatusCode); |
| 96 | } | 103 | } |
| @@ -105,6 +112,24 @@ public class MsgHandler implements MsgHandle { | @@ -105,6 +112,24 @@ public class MsgHandler implements MsgHandle { | ||
| 105 | } | 112 | } |
| 106 | 113 | ||
| 107 | /** | 114 | /** |
| 115 | + * 打印在线用户 | ||
| 116 | + */ | ||
| 117 | + private void printOnlineUsers() { | ||
| 118 | + try { | ||
| 119 | + List<OnlineUsersResVO.DataBodyBean> onlineUsers = routeRequest.onlineUsers(); | ||
| 120 | + | ||
| 121 | + LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); | ||
| 122 | + for (OnlineUsersResVO.DataBodyBean onlineUser : onlineUsers) { | ||
| 123 | + LOGGER.info("userId={}=====userName={}",onlineUser.getUserId(),onlineUser.getUserName()); | ||
| 124 | + } | ||
| 125 | + LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); | ||
| 126 | + | ||
| 127 | + } catch (Exception e) { | ||
| 128 | + LOGGER.error("Exception" ,e); | ||
| 129 | + } | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + /** | ||
| 108 | * 关闭系统 | 133 | * 关闭系统 |
| 109 | */ | 134 | */ |
| 110 | private void shutdown() { | 135 | private void shutdown() { |
| @@ -7,6 +7,7 @@ import com.crossoverjie.cim.client.service.RouteRequest; | @@ -7,6 +7,7 @@ import com.crossoverjie.cim.client.service.RouteRequest; | ||
| 7 | import com.crossoverjie.cim.client.vo.req.GroupReqVO; | 7 | import com.crossoverjie.cim.client.vo.req.GroupReqVO; |
| 8 | import com.crossoverjie.cim.client.vo.req.LoginReqVO; | 8 | import com.crossoverjie.cim.client.vo.req.LoginReqVO; |
| 9 | import com.crossoverjie.cim.client.vo.res.CIMServerResVO; | 9 | import com.crossoverjie.cim.client.vo.res.CIMServerResVO; |
| 10 | +import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO; | ||
| 10 | import com.crossoverjie.cim.common.enums.StatusEnum; | 11 | import com.crossoverjie.cim.common.enums.StatusEnum; |
| 11 | import okhttp3.*; | 12 | import okhttp3.*; |
| 12 | import org.slf4j.Logger; | 13 | import org.slf4j.Logger; |
| @@ -16,6 +17,7 @@ import org.springframework.beans.factory.annotation.Value; | @@ -16,6 +17,7 @@ import org.springframework.beans.factory.annotation.Value; | ||
| 16 | import org.springframework.stereotype.Service; | 17 | import org.springframework.stereotype.Service; |
| 17 | 18 | ||
| 18 | import java.io.IOException; | 19 | import java.io.IOException; |
| 20 | +import java.util.List; | ||
| 19 | 21 | ||
| 20 | /** | 22 | /** |
| 21 | * Function: | 23 | * Function: |
| @@ -40,6 +42,11 @@ public class RouteRequestImpl implements RouteRequest { | @@ -40,6 +42,11 @@ public class RouteRequestImpl implements RouteRequest { | ||
| 40 | @Value("${cim.server.route.request.url}") | 42 | @Value("${cim.server.route.request.url}") |
| 41 | private String serverRouteRequestUrl; | 43 | private String serverRouteRequestUrl; |
| 42 | 44 | ||
| 45 | + @Value("${cim.server.online.user.url}") | ||
| 46 | + private String onlineUserUrl; | ||
| 47 | + | ||
| 48 | + | ||
| 49 | + | ||
| 43 | @Autowired | 50 | @Autowired |
| 44 | private AppConfiguration appConfiguration ; | 51 | private AppConfiguration appConfiguration ; |
| 45 | 52 | ||
| @@ -95,4 +102,29 @@ public class RouteRequestImpl implements RouteRequest { | @@ -95,4 +102,29 @@ public class RouteRequestImpl implements RouteRequest { | ||
| 95 | 102 | ||
| 96 | return cimServerResVO.getDataBody(); | 103 | return cimServerResVO.getDataBody(); |
| 97 | } | 104 | } |
| 105 | + | ||
| 106 | + @Override | ||
| 107 | + public List<OnlineUsersResVO.DataBodyBean> onlineUsers() throws Exception{ | ||
| 108 | + | ||
| 109 | + JSONObject jsonObject = new JSONObject(); | ||
| 110 | + RequestBody requestBody = RequestBody.create(mediaType,jsonObject.toString()); | ||
| 111 | + | ||
| 112 | + Request request = new Request.Builder() | ||
| 113 | + .url(onlineUserUrl) | ||
| 114 | + .post(requestBody) | ||
| 115 | + .build(); | ||
| 116 | + | ||
| 117 | + Response response = okHttpClient.newCall(request).execute() ; | ||
| 118 | + if (!response.isSuccessful()){ | ||
| 119 | + throw new IOException("Unexpected code " + response); | ||
| 120 | + } | ||
| 121 | + if (!response.isSuccessful()){ | ||
| 122 | + throw new IOException("Unexpected code " + response); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + String json = response.body().string() ; | ||
| 126 | + OnlineUsersResVO onlineUsersResVO = JSON.parseObject(json, OnlineUsersResVO.class); | ||
| 127 | + | ||
| 128 | + return onlineUsersResVO.getDataBody(); | ||
| 129 | + } | ||
| 98 | } | 130 | } |
| 1 | +package com.crossoverjie.cim.client.vo.res; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * Function: | ||
| 7 | + * | ||
| 8 | + * @author crossoverJie | ||
| 9 | + * Date: 2018/12/26 23:17 | ||
| 10 | + * @since JDK 1.8 | ||
| 11 | + */ | ||
| 12 | +public class OnlineUsersResVO { | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * code : 9000 | ||
| 17 | + * message : 成功 | ||
| 18 | + * reqNo : null | ||
| 19 | + * dataBody : [{"userId":1545574841528,"userName":"zhangsan"},{"userId":1545574871143,"userName":"crossoverJie"}] | ||
| 20 | + */ | ||
| 21 | + | ||
| 22 | + private String code; | ||
| 23 | + private String message; | ||
| 24 | + private Object reqNo; | ||
| 25 | + private List<DataBodyBean> dataBody; | ||
| 26 | + | ||
| 27 | + public String getCode() { | ||
| 28 | + return code; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public void setCode(String code) { | ||
| 32 | + this.code = code; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public String getMessage() { | ||
| 36 | + return message; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public void setMessage(String message) { | ||
| 40 | + this.message = message; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public Object getReqNo() { | ||
| 44 | + return reqNo; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public void setReqNo(Object reqNo) { | ||
| 48 | + this.reqNo = reqNo; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public List<DataBodyBean> getDataBody() { | ||
| 52 | + return dataBody; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public void setDataBody(List<DataBodyBean> dataBody) { | ||
| 56 | + this.dataBody = dataBody; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public static class DataBodyBean { | ||
| 60 | + /** | ||
| 61 | + * userId : 1545574841528 | ||
| 62 | + * userName : zhangsan | ||
| 63 | + */ | ||
| 64 | + | ||
| 65 | + private long userId; | ||
| 66 | + private String userName; | ||
| 67 | + | ||
| 68 | + public long getUserId() { | ||
| 69 | + return userId; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public void setUserId(long userId) { | ||
| 73 | + this.userId = userId; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public String getUserName() { | ||
| 77 | + return userName; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public void setUserName(String userName) { | ||
| 81 | + this.userName = userName; | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | +} |
| @@ -16,6 +16,9 @@ cim.group.route.request.url=http://45.78.28.220:8083/groupRoute | @@ -16,6 +16,9 @@ cim.group.route.request.url=http://45.78.28.220:8083/groupRoute | ||
| 16 | # 登录并获取服务器ip+port | 16 | # 登录并获取服务器ip+port |
| 17 | cim.server.route.request.url=http://45.78.28.220:8083/login | 17 | cim.server.route.request.url=http://45.78.28.220:8083/login |
| 18 | 18 | ||
| 19 | +# 在线用户 | ||
| 20 | +cim.server.online.user.url=http://45.78.28.220:8083/onlineUser | ||
| 21 | + | ||
| 19 | 22 | ||
| 20 | ###=======本地模拟======### | 23 | ###=======本地模拟======### |
| 21 | ## 群发消息 | 24 | ## 群发消息 |
| @@ -24,6 +27,9 @@ cim.server.route.request.url=http://45.78.28.220:8083/login | @@ -24,6 +27,9 @@ cim.server.route.request.url=http://45.78.28.220:8083/login | ||
| 24 | ## 登录并获取服务器ip+port | 27 | ## 登录并获取服务器ip+port |
| 25 | #cim.server.route.request.url=http://localhost:8083/login | 28 | #cim.server.route.request.url=http://localhost:8083/login |
| 26 | 29 | ||
| 30 | +# 在线用户 | ||
| 31 | +#cim.server.online.user=http://localhost:8083/onlineUser | ||
| 32 | + | ||
| 27 | # 客户端唯一ID | 33 | # 客户端唯一ID |
| 28 | cim.user.id=1545574841528 | 34 | cim.user.id=1545574841528 |
| 29 | cim.user.userName=zhangsan | 35 | cim.user.userName=zhangsan |
| @@ -3,7 +3,13 @@ package com.crossoverjie.cim.server.test; | @@ -3,7 +3,13 @@ package com.crossoverjie.cim.server.test; | ||
| 3 | 3 | ||
| 4 | import com.alibaba.fastjson.JSON; | 4 | import com.alibaba.fastjson.JSON; |
| 5 | import com.crossoverjie.cim.client.vo.res.CIMServerResVO; | 5 | import com.crossoverjie.cim.client.vo.res.CIMServerResVO; |
| 6 | +import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO; | ||
| 6 | import org.junit.Test; | 7 | import org.junit.Test; |
| 8 | +import org.slf4j.Logger; | ||
| 9 | +import org.slf4j.LoggerFactory; | ||
| 10 | + | ||
| 11 | +import java.util.ArrayList; | ||
| 12 | +import java.util.List; | ||
| 7 | 13 | ||
| 8 | /** | 14 | /** |
| 9 | * Function: | 15 | * Function: |
| @@ -14,6 +20,7 @@ import org.junit.Test; | @@ -14,6 +20,7 @@ import org.junit.Test; | ||
| 14 | */ | 20 | */ |
| 15 | public class CommonTest { | 21 | public class CommonTest { |
| 16 | 22 | ||
| 23 | + private final static Logger LOGGER = LoggerFactory.getLogger(CommonTest.class); | ||
| 17 | @Test | 24 | @Test |
| 18 | public void test() { | 25 | public void test() { |
| 19 | 26 | ||
| @@ -27,4 +34,30 @@ public class CommonTest { | @@ -27,4 +34,30 @@ public class CommonTest { | ||
| 27 | String[] split = text.split(" "); | 34 | String[] split = text.split(" "); |
| 28 | System.out.println(split.length); | 35 | System.out.println(split.length); |
| 29 | } | 36 | } |
| 37 | + | ||
| 38 | + @Test | ||
| 39 | + public void onlineUser(){ | ||
| 40 | + List<OnlineUsersResVO.DataBodyBean> onlineUsers = new ArrayList<>(64) ; | ||
| 41 | + | ||
| 42 | + OnlineUsersResVO.DataBodyBean bodyBean = new OnlineUsersResVO.DataBodyBean() ; | ||
| 43 | + | ||
| 44 | + bodyBean.setUserId(100L); | ||
| 45 | + bodyBean.setUserName("zhangsan"); | ||
| 46 | + onlineUsers.add(bodyBean) ; | ||
| 47 | + | ||
| 48 | + bodyBean = new OnlineUsersResVO.DataBodyBean(); | ||
| 49 | + bodyBean.setUserId(200L); | ||
| 50 | + bodyBean.setUserName("crossoverJie"); | ||
| 51 | + onlineUsers.add(bodyBean) ; | ||
| 52 | + | ||
| 53 | + LOGGER.info("list={}",JSON.toJSONString(onlineUsers)); | ||
| 54 | + | ||
| 55 | + LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); | ||
| 56 | + | ||
| 57 | + for (OnlineUsersResVO.DataBodyBean onlineUser : onlineUsers) { | ||
| 58 | + | ||
| 59 | + LOGGER.info("userId={}=====userName={}",onlineUser.getUserId(),onlineUser.getUserName()); | ||
| 60 | + } | ||
| 61 | + LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); | ||
| 62 | + } | ||
| 30 | } | 63 | } |
-
请 注册 或 登录 后发表评论