作者 crossoverJie
提交者 GitHub

Merge pull request #5 from crossoverJie/cim

cim
正在显示 70 个修改的文件 包含 3456 行增加324 行删除

要显示太多修改。

为保证性能只显示 70 of 70+ 个文件。

@@ -5,10 +5,10 @@ @@ -5,10 +5,10 @@
5 <modelVersion>4.0.0</modelVersion> 5 <modelVersion>4.0.0</modelVersion>
6 <parent> 6 <parent>
7 <groupId>com.crossoverjie.netty</groupId> 7 <groupId>com.crossoverjie.netty</groupId>
8 - <artifactId>netty-action</artifactId> 8 + <artifactId>cim</artifactId>
9 <version>1.0.0-SNAPSHOT</version> 9 <version>1.0.0-SNAPSHOT</version>
10 </parent> 10 </parent>
11 - <artifactId>netty-action-heartbeat-client</artifactId> 11 + <artifactId>cim-client</artifactId>
12 <packaging>jar</packaging> 12 <packaging>jar</packaging>
13 13
14 <properties> 14 <properties>
@@ -30,7 +30,7 @@ @@ -30,7 +30,7 @@
30 30
31 <dependency> 31 <dependency>
32 <groupId>com.crossoverjie.netty</groupId> 32 <groupId>com.crossoverjie.netty</groupId>
33 - <artifactId>netty-action-common</artifactId> 33 + <artifactId>cim-common</artifactId>
34 </dependency> 34 </dependency>
35 35
36 36
1 -package com.crossoverjie.netty.action.client; 1 +package com.crossoverjie.cim.client;
2 2
  3 +import com.crossoverjie.cim.client.scanner.Scan;
3 import org.slf4j.Logger; 4 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory; 5 import org.slf4j.LoggerFactory;
5 import org.springframework.boot.CommandLineRunner; 6 import org.springframework.boot.CommandLineRunner;
@@ -10,18 +11,20 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -10,18 +11,20 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
10 * @author crossoverJie 11 * @author crossoverJie
11 */ 12 */
12 @SpringBootApplication 13 @SpringBootApplication
13 -public class HeartbeatClientApplication implements CommandLineRunner{  
14 -  
15 - private final static Logger LOGGER = LoggerFactory.getLogger(HeartbeatClientApplication.class);  
16 - 14 +public class CIMClientApplication implements CommandLineRunner{
17 15
  16 + private final static Logger LOGGER = LoggerFactory.getLogger(CIMClientApplication.class);
18 17
19 public static void main(String[] args) { 18 public static void main(String[] args) {
20 - SpringApplication.run(HeartbeatClientApplication.class, args);  
21 - LOGGER.info("启动 Client 成功"); 19 + SpringApplication.run(CIMClientApplication.class, args);
  20 + LOGGER.info("启动 Client 服务成功");
22 } 21 }
23 22
24 @Override 23 @Override
25 public void run(String... args) throws Exception { 24 public void run(String... args) throws Exception {
  25 + Scan scan = new Scan() ;
  26 + Thread thread = new Thread(scan);
  27 + thread.setName("scan-thread");
  28 + thread.start();
26 } 29 }
27 } 30 }
1 -package com.crossoverjie.netty.action.client;  
2 -  
3 -import com.alibaba.fastjson.JSON;  
4 -import com.crossoverjie.netty.action.client.init.CustomerHandleInitializer;  
5 -import com.crossoverjie.netty.action.client.vo.req.GoogleProtocolVO;  
6 -import com.crossoverjie.netty.action.common.pojo.CustomProtocol;  
7 -import com.crossoverjie.netty.action.common.protocol.BaseRequestProto; 1 +package com.crossoverjie.cim.client.client;
  2 +
  3 +import com.crossoverjie.cim.client.init.CIMClientHandleInitializer;
  4 +import com.crossoverjie.cim.client.service.RouteRequest;
  5 +import com.crossoverjie.cim.client.vo.req.GoogleProtocolVO;
  6 +import com.crossoverjie.cim.client.vo.req.LoginReqVO;
  7 +import com.crossoverjie.cim.client.vo.res.CIMServerResVO;
  8 +import com.crossoverjie.cim.common.constant.Constants;
  9 +import com.crossoverjie.cim.common.protocol.CIMRequestProto;
8 import io.netty.bootstrap.Bootstrap; 10 import io.netty.bootstrap.Bootstrap;
9 import io.netty.buffer.ByteBuf; 11 import io.netty.buffer.ByteBuf;
10 import io.netty.buffer.Unpooled; 12 import io.netty.buffer.Unpooled;
@@ -16,6 +18,7 @@ import io.netty.channel.socket.SocketChannel; @@ -16,6 +18,7 @@ import io.netty.channel.socket.SocketChannel;
16 import io.netty.channel.socket.nio.NioSocketChannel; 18 import io.netty.channel.socket.nio.NioSocketChannel;
17 import org.slf4j.Logger; 19 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory; 20 import org.slf4j.LoggerFactory;
  21 +import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.beans.factory.annotation.Value; 22 import org.springframework.beans.factory.annotation.Value;
20 import org.springframework.stereotype.Component; 23 import org.springframework.stereotype.Component;
21 24
@@ -29,55 +32,93 @@ import javax.annotation.PostConstruct; @@ -29,55 +32,93 @@ import javax.annotation.PostConstruct;
29 * @since JDK 1.8 32 * @since JDK 1.8
30 */ 33 */
31 @Component 34 @Component
32 -public class HeartbeatClient { 35 +public class CIMClient {
33 36
34 - private final static Logger LOGGER = LoggerFactory.getLogger(HeartbeatClient.class); 37 + private final static Logger LOGGER = LoggerFactory.getLogger(CIMClient.class);
35 38
36 private EventLoopGroup group = new NioEventLoopGroup(); 39 private EventLoopGroup group = new NioEventLoopGroup();
37 40
  41 + @Value("${cim.user.id}")
  42 + private long userId;
38 43
39 - @Value("${netty.server.port}")  
40 - private int nettyPort;  
41 -  
42 - @Value("${netty.server.host}")  
43 - private String host; 44 + @Value("${cim.user.userName}")
  45 + private String userName;
44 46
45 private SocketChannel channel; 47 private SocketChannel channel;
46 48
  49 + @Autowired
  50 + private RouteRequest routeRequest;
  51 +
47 @PostConstruct 52 @PostConstruct
48 - public void start() throws InterruptedException { 53 + public void start() throws Exception {
  54 +
  55 + //登录 + 获取可以使用的服务器 ip+port
  56 + CIMServerResVO.ServerInfo cimServer = userLogin();
  57 +
  58 + //启动客户端
  59 + startClient(cimServer);
  60 +
  61 + //向服务端注册
  62 + loginCIMServer();
  63 +
  64 +
  65 + }
  66 +
  67 + /**
  68 + * 启动客户端
  69 + *
  70 + * @param cimServer
  71 + * @throws InterruptedException
  72 + */
  73 + private void startClient(CIMServerResVO.ServerInfo cimServer) throws InterruptedException {
49 Bootstrap bootstrap = new Bootstrap(); 74 Bootstrap bootstrap = new Bootstrap();
50 bootstrap.group(group) 75 bootstrap.group(group)
51 .channel(NioSocketChannel.class) 76 .channel(NioSocketChannel.class)
52 - .handler(new CustomerHandleInitializer()) 77 + .handler(new CIMClientHandleInitializer())
53 ; 78 ;
54 79
55 - ChannelFuture future = bootstrap.connect(host, nettyPort).sync(); 80 + ChannelFuture future = bootstrap.connect(cimServer.getIp(), cimServer.getCimServerPort()).sync();
56 if (future.isSuccess()) { 81 if (future.isSuccess()) {
57 - LOGGER.info("启动 Netty 成功"); 82 + LOGGER.info("启动 cim client 成功");
58 } 83 }
59 channel = (SocketChannel) future.channel(); 84 channel = (SocketChannel) future.channel();
60 } 85 }
61 86
62 /** 87 /**
63 - * 发送消息 88 + * 登录+路由服务器
64 * 89 *
65 - * @param customProtocol 90 + * @return 路由服务器信息
  91 + * @throws Exception
66 */ 92 */
67 - public void sendMsg(CustomProtocol customProtocol) {  
68 - ChannelFuture future = channel.writeAndFlush(customProtocol);  
69 - future.addListener((ChannelFutureListener) channelFuture ->  
70 - LOGGER.info("客户端手动发消息成功={}", JSON.toJSONString(customProtocol))); 93 + private CIMServerResVO.ServerInfo userLogin() throws Exception {
  94 + LoginReqVO loginReqVO = new LoginReqVO(userId, userName);
  95 + CIMServerResVO.ServerInfo cimServer = routeRequest.getCIMServer(loginReqVO);
  96 + LOGGER.info("cimServer=[{}]", cimServer.toString());
  97 + return cimServer;
  98 + }
71 99
  100 + /**
  101 + * 向服务器注册
  102 + */
  103 + private void loginCIMServer() {
  104 + CIMRequestProto.CIMReqProtocol login = CIMRequestProto.CIMReqProtocol.newBuilder()
  105 + .setRequestId(userId)
  106 + .setReqMsg(userName)
  107 + .setType(Constants.CommandType.LOGIN)
  108 + .build();
  109 + ChannelFuture future = channel.writeAndFlush(login);
  110 + future.addListener((ChannelFutureListener) channelFuture ->
  111 + LOGGER.info("注册成功={}", login.toString()));
72 } 112 }
  113 +
73 /** 114 /**
74 * 发送消息字符串 115 * 发送消息字符串
75 * 116 *
76 * @param msg 117 * @param msg
77 */ 118 */
78 public void sendStringMsg(String msg) { 119 public void sendStringMsg(String msg) {
79 - ByteBuf message = Unpooled.buffer(msg.getBytes().length) ;  
80 - message.writeBytes(msg.getBytes()) ; 120 + ByteBuf message = Unpooled.buffer(msg.getBytes().length);
  121 + message.writeBytes(msg.getBytes());
81 ChannelFuture future = channel.writeAndFlush(message); 122 ChannelFuture future = channel.writeAndFlush(message);
82 future.addListener((ChannelFutureListener) channelFuture -> 123 future.addListener((ChannelFutureListener) channelFuture ->
83 LOGGER.info("客户端手动发消息成功={}", msg)); 124 LOGGER.info("客户端手动发消息成功={}", msg));
@@ -91,9 +132,10 @@ public class HeartbeatClient { @@ -91,9 +132,10 @@ public class HeartbeatClient {
91 */ 132 */
92 public void sendGoogleProtocolMsg(GoogleProtocolVO googleProtocolVO) { 133 public void sendGoogleProtocolMsg(GoogleProtocolVO googleProtocolVO) {
93 134
94 - BaseRequestProto.RequestProtocol protocol = BaseRequestProto.RequestProtocol.newBuilder() 135 + CIMRequestProto.CIMReqProtocol protocol = CIMRequestProto.CIMReqProtocol.newBuilder()
95 .setRequestId(googleProtocolVO.getRequestId()) 136 .setRequestId(googleProtocolVO.getRequestId())
96 .setReqMsg(googleProtocolVO.getMsg()) 137 .setReqMsg(googleProtocolVO.getMsg())
  138 + .setType(Constants.CommandType.MSG)
97 .build(); 139 .build();
98 140
99 141
@@ -102,4 +144,12 @@ public class HeartbeatClient { @@ -102,4 +144,12 @@ public class HeartbeatClient {
102 LOGGER.info("客户端手动发送 Google Protocol 成功={}", googleProtocolVO.toString())); 144 LOGGER.info("客户端手动发送 Google Protocol 成功={}", googleProtocolVO.toString()));
103 145
104 } 146 }
  147 +
  148 + /**
  149 + * 关闭
  150 + * @throws InterruptedException
  151 + */
  152 + public void close() throws InterruptedException {
  153 + channel.close() ;
  154 + }
105 } 155 }
  1 +package com.crossoverjie.cim.client.config;
  2 +
  3 +import org.springframework.beans.factory.annotation.Value;
  4 +import org.springframework.stereotype.Component;
  5 +
  6 +/**
  7 + * Function:
  8 + *
  9 + * @author crossoverJie
  10 + * Date: 2018/8/24 01:43
  11 + * @since JDK 1.8
  12 + */
  13 +@Component
  14 +public class AppConfiguration {
  15 +
  16 + @Value("${cim.user.id}")
  17 + private Long userId;
  18 +
  19 + @Value("${cim.user.userName}")
  20 + private String userName;
  21 +
  22 + public Long getUserId() {
  23 + return userId;
  24 + }
  25 +
  26 + public void setUserId(Long userId) {
  27 + this.userId = userId;
  28 + }
  29 +
  30 + public String getUserName() {
  31 + return userName;
  32 + }
  33 +
  34 + public void setUserName(String userName) {
  35 + this.userName = userName;
  36 + }
  37 +}
  1 +package com.crossoverjie.cim.client.config;
  2 +
  3 +import com.crossoverjie.cim.client.handle.MsgHandleCaller;
  4 +import com.crossoverjie.cim.common.constant.Constants;
  5 +import com.crossoverjie.cim.common.protocol.CIMRequestProto;
  6 +import com.google.common.util.concurrent.ThreadFactoryBuilder;
  7 +import okhttp3.OkHttpClient;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.beans.factory.annotation.Value;
  11 +import org.springframework.context.annotation.Bean;
  12 +import org.springframework.context.annotation.Configuration;
  13 +
  14 +import java.util.concurrent.*;
  15 +
  16 +/**
  17 + * Function:bean 配置
  18 + *
  19 + * @author crossoverJie
  20 + * Date: 24/05/2018 15:55
  21 + * @since JDK 1.8
  22 + */
  23 +@Configuration
  24 +public class BeanConfig {
  25 +
  26 + private final static Logger LOGGER = LoggerFactory.getLogger(BeanConfig.class);
  27 +
  28 +
  29 + @Value("${cim.user.id}")
  30 + private long userId;
  31 +
  32 + @Value("${cim.callback.thread.queue.size}")
  33 + private int queueSize;
  34 +
  35 + @Value("${cim.callback.thread.pool.size}")
  36 + private int poolSize;
  37 +
  38 +
  39 + /**
  40 + * 创建心跳单例
  41 + * @return
  42 + */
  43 + @Bean(value = "heartBeat")
  44 + public CIMRequestProto.CIMReqProtocol heartBeat() {
  45 + CIMRequestProto.CIMReqProtocol heart = CIMRequestProto.CIMReqProtocol.newBuilder()
  46 + .setRequestId(userId)
  47 + .setReqMsg("ping")
  48 + .setType(Constants.CommandType.PING)
  49 + .build();
  50 + return heart;
  51 + }
  52 +
  53 +
  54 + /**
  55 + * http client
  56 + * @return okHttp
  57 + */
  58 + @Bean
  59 + public OkHttpClient okHttpClient() {
  60 + OkHttpClient.Builder builder = new OkHttpClient.Builder();
  61 + builder.connectTimeout(30, TimeUnit.SECONDS)
  62 + .readTimeout(10, TimeUnit.SECONDS)
  63 + .writeTimeout(10,TimeUnit.SECONDS)
  64 + .retryOnConnectionFailure(true);
  65 + return builder.build();
  66 + }
  67 +
  68 +
  69 + /**
  70 + * 创建回调线程池
  71 + * @return
  72 + */
  73 + @Bean("callBackThreadPool")
  74 + public ThreadPoolExecutor buildCallerThread(){
  75 + BlockingQueue<Runnable> queue = new LinkedBlockingQueue(queueSize);
  76 + ThreadFactory product = new ThreadFactoryBuilder()
  77 + .setNameFormat("msg-callback-%d")
  78 + .setDaemon(true)
  79 + .build();
  80 + ThreadPoolExecutor productExecutor = new ThreadPoolExecutor(poolSize, poolSize, 1, TimeUnit.MILLISECONDS, queue,product);
  81 + return productExecutor ;
  82 + }
  83 +
  84 + /**
  85 + * 回调 bean
  86 + * @return
  87 + */
  88 + @Bean
  89 + public MsgHandleCaller buildCaller(){
  90 + MsgHandleCaller caller = new MsgHandleCaller(msg -> {
  91 + //处理业务逻辑,或者自定义实现接口
  92 + }) ;
  93 +
  94 + return caller ;
  95 + }
  96 +
  97 +}
1 -package com.crossoverjie.netty.action.client.config; 1 +package com.crossoverjie.cim.client.config;
2 2
3 import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; 3 import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
4 import org.springframework.context.annotation.Bean; 4 import org.springframework.context.annotation.Bean;
1 -package com.crossoverjie.netty.action.client.controller;  
2 -  
3 -import com.crossoverjie.netty.action.client.HeartbeatClient;  
4 -import com.crossoverjie.netty.action.client.vo.req.GoogleProtocolVO;  
5 -import com.crossoverjie.netty.action.client.vo.req.SendMsgReqVO;  
6 -import com.crossoverjie.netty.action.client.vo.req.StringReqVO;  
7 -import com.crossoverjie.netty.action.client.vo.res.SendMsgResVO;  
8 -import com.crossoverjie.netty.action.common.constant.Constants;  
9 -import com.crossoverjie.netty.action.common.enums.StatusEnum;  
10 -import com.crossoverjie.netty.action.common.pojo.CustomProtocol;  
11 -import com.crossoverjie.netty.action.common.res.BaseResponse;  
12 -import com.crossoverjie.netty.action.common.res.NULLBody; 1 +package com.crossoverjie.cim.client.controller;
  2 +
  3 +import com.crossoverjie.cim.client.client.CIMClient;
  4 +import com.crossoverjie.cim.client.service.RouteRequest;
  5 +import com.crossoverjie.cim.client.vo.req.GoogleProtocolVO;
  6 +import com.crossoverjie.cim.client.vo.req.GroupReqVO;
  7 +import com.crossoverjie.cim.client.vo.req.SendMsgReqVO;
  8 +import com.crossoverjie.cim.client.vo.req.StringReqVO;
  9 +import com.crossoverjie.cim.client.vo.res.SendMsgResVO;
  10 +import com.crossoverjie.cim.common.constant.Constants;
  11 +import com.crossoverjie.cim.common.enums.StatusEnum;
  12 +import com.crossoverjie.cim.common.res.BaseResponse;
  13 +import com.crossoverjie.cim.common.res.NULLBody;
13 import io.swagger.annotations.ApiOperation; 14 import io.swagger.annotations.ApiOperation;
14 import org.springframework.beans.factory.annotation.Autowired; 15 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.boot.actuate.metrics.CounterService; 16 import org.springframework.boot.actuate.metrics.CounterService;
@@ -37,30 +38,13 @@ public class IndexController { @@ -37,30 +38,13 @@ public class IndexController {
37 private CounterService counterService; 38 private CounterService counterService;
38 39
39 @Autowired 40 @Autowired
40 - private HeartbeatClient heartbeatClient ; 41 + private CIMClient heartbeatClient ;
41 42
42 - /**  
43 - * 向服务端发消息  
44 - * @param sendMsgReqVO  
45 - * @return  
46 - */  
47 - @ApiOperation("客户端发送消息")  
48 - @RequestMapping(value = "sendMsg",method = RequestMethod.POST)  
49 - @ResponseBody()  
50 - public BaseResponse<SendMsgResVO> sendMsg(@RequestBody SendMsgReqVO sendMsgReqVO){  
51 - BaseResponse<SendMsgResVO> res = new BaseResponse();  
52 - heartbeatClient.sendMsg(new CustomProtocol(sendMsgReqVO.getId(),sendMsgReqVO.getMsg())) ;  
53 43
54 - // 利用 actuator 来自增  
55 - counterService.increment(Constants.COUNTER_CLIENT_PUSH_COUNT);  
56 44
57 - SendMsgResVO sendMsgResVO = new SendMsgResVO() ;  
58 - sendMsgResVO.setMsg("OK") ;  
59 - res.setCode(StatusEnum.SUCCESS.getCode()) ;  
60 - res.setMessage(StatusEnum.SUCCESS.getMessage()) ;  
61 - res.setDataBody(sendMsgResVO) ;  
62 - return res ;  
63 - } 45 + @Autowired
  46 + private RouteRequest routeRequest ;
  47 +
64 48
65 /** 49 /**
66 * 向服务端发消息 字符串 50 * 向服务端发消息 字符串
@@ -111,4 +95,27 @@ public class IndexController { @@ -111,4 +95,27 @@ public class IndexController {
111 res.setMessage(StatusEnum.SUCCESS.getMessage()) ; 95 res.setMessage(StatusEnum.SUCCESS.getMessage()) ;
112 return res ; 96 return res ;
113 } 97 }
  98 +
  99 +
  100 +
  101 + /**
  102 + * 群发消息
  103 + * @param sendMsgReqVO
  104 + * @return
  105 + */
  106 + @ApiOperation("群发消息")
  107 + @RequestMapping(value = "sendGroupMsg",method = RequestMethod.POST)
  108 + @ResponseBody
  109 + public BaseResponse sendGroupMsg(@RequestBody SendMsgReqVO sendMsgReqVO) throws Exception {
  110 + BaseResponse<NULLBody> res = new BaseResponse();
  111 +
  112 + GroupReqVO groupReqVO = new GroupReqVO(sendMsgReqVO.getUserId(),sendMsgReqVO.getMsg()) ;
  113 + routeRequest.sendGroupMsg(groupReqVO) ;
  114 +
  115 + counterService.increment(Constants.COUNTER_SERVER_PUSH_COUNT);
  116 +
  117 + res.setCode(StatusEnum.SUCCESS.getCode()) ;
  118 + res.setMessage(StatusEnum.SUCCESS.getMessage()) ;
  119 + return res ;
  120 + }
114 } 121 }
1 -package com.crossoverjie.netty.action.client.handle; 1 +package com.crossoverjie.cim.client.handle;
2 2
3 -import com.crossoverjie.netty.action.common.protocol.BaseResponseProto; 3 +import com.crossoverjie.cim.client.util.SpringBeanFactory;
  4 +import com.crossoverjie.cim.common.protocol.CIMRequestProto;
  5 +import com.crossoverjie.cim.common.protocol.CIMResponseProto;
  6 +import io.netty.channel.ChannelHandler;
4 import io.netty.channel.ChannelHandlerContext; 7 import io.netty.channel.ChannelHandlerContext;
5 import io.netty.channel.SimpleChannelInboundHandler; 8 import io.netty.channel.SimpleChannelInboundHandler;
  9 +import io.netty.handler.timeout.IdleState;
  10 +import io.netty.handler.timeout.IdleStateEvent;
6 import org.slf4j.Logger; 11 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory; 12 import org.slf4j.LoggerFactory;
8 13
  14 +import java.util.concurrent.ThreadPoolExecutor;
  15 +
9 /** 16 /**
10 * Function: 17 * Function:
11 * 18 *
@@ -13,27 +20,31 @@ import org.slf4j.LoggerFactory; @@ -13,27 +20,31 @@ import org.slf4j.LoggerFactory;
13 * Date: 16/02/2018 18:09 20 * Date: 16/02/2018 18:09
14 * @since JDK 1.8 21 * @since JDK 1.8
15 */ 22 */
16 -public class EchoClientHandle extends SimpleChannelInboundHandler<BaseResponseProto.ResponseProtocol> { 23 +@ChannelHandler.Sharable
  24 +public class CIMClientHandle extends SimpleChannelInboundHandler<CIMResponseProto.CIMResProtocol> {
  25 +
  26 + private final static Logger LOGGER = LoggerFactory.getLogger(CIMClientHandle.class);
17 27
18 - private final static Logger LOGGER = LoggerFactory.getLogger(EchoClientHandle.class); 28 + private MsgHandleCaller caller ;
19 29
  30 + private ThreadPoolExecutor threadPoolExecutor ;
20 31
21 32
22 @Override 33 @Override
23 public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { 34 public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
24 35
25 - /*if (evt instanceof IdleStateEvent){ 36 + if (evt instanceof IdleStateEvent){
26 IdleStateEvent idleStateEvent = (IdleStateEvent) evt ; 37 IdleStateEvent idleStateEvent = (IdleStateEvent) evt ;
27 38
28 if (idleStateEvent.state() == IdleState.WRITER_IDLE){ 39 if (idleStateEvent.state() == IdleState.WRITER_IDLE){
29 - LOGGER.info("已经 10 秒没有发送信息!"); 40 + //LOGGER.info("已经 10 秒没有发送信息!");
30 //向服务端发送消息 41 //向服务端发送消息
31 - CustomProtocol heartBeat = SpringBeanFactory.getBean("heartBeat", CustomProtocol.class);  
32 - ctx.writeAndFlush(heartBeat).addListener(ChannelFutureListener.CLOSE_ON_FAILURE) ; 42 + CIMRequestProto.CIMReqProtocol heartBeat = SpringBeanFactory.getBean("heartBeat", CIMRequestProto.CIMReqProtocol.class);
  43 + ctx.writeAndFlush(heartBeat) ;
33 } 44 }
34 45
35 46
36 - }*/ 47 + }
37 48
38 super.userEventTriggered(ctx, evt); 49 super.userEventTriggered(ctx, evt);
39 } 50 }
@@ -42,16 +53,32 @@ public class EchoClientHandle extends SimpleChannelInboundHandler<BaseResponsePr @@ -42,16 +53,32 @@ public class EchoClientHandle extends SimpleChannelInboundHandler<BaseResponsePr
42 public void channelActive(ChannelHandlerContext ctx) throws Exception { 53 public void channelActive(ChannelHandlerContext ctx) throws Exception {
43 54
44 //客户端和服务端建立连接时调用 55 //客户端和服务端建立连接时调用
45 - LOGGER.info("已经建立了联系。。"); 56 + LOGGER.info("cim server connect success!");
46 } 57 }
47 58
48 @Override 59 @Override
49 - protected void channelRead0(ChannelHandlerContext channelHandlerContext, BaseResponseProto.ResponseProtocol responseProtocol) throws Exception { 60 + protected void channelRead0(ChannelHandlerContext channelHandlerContext, CIMResponseProto.CIMResProtocol responseProtocol) throws Exception {
50 61
51 //从服务端收到消息时被调用 62 //从服务端收到消息时被调用
52 //LOGGER.info("客户端收到消息={}",in.toString(CharsetUtil.UTF_8)) ; 63 //LOGGER.info("客户端收到消息={}",in.toString(CharsetUtil.UTF_8)) ;
53 64
54 - LOGGER.info("客户端收到消息={}" ,responseProtocol.getResMsg()); 65 + //回调消息
  66 + callBackMsg(responseProtocol.getResMsg());
  67 +
  68 + LOGGER.info(responseProtocol.getResMsg());
  69 + }
  70 +
  71 + /**
  72 + * 回调消息
  73 + * @param msg
  74 + */
  75 + private void callBackMsg(String msg) {
  76 + threadPoolExecutor = SpringBeanFactory.getBean("callBackThreadPool",ThreadPoolExecutor.class) ;
  77 + threadPoolExecutor.execute(() -> {
  78 + caller = SpringBeanFactory.getBean(MsgHandleCaller.class) ;
  79 + caller.getMsgHandleListener().handle(msg);
  80 + });
  81 +
55 } 82 }
56 83
57 @Override 84 @Override
  1 +package com.crossoverjie.cim.client.handle;
  2 +
  3 +import com.crossoverjie.cim.client.service.CustomMsgHandleListener;
  4 +
  5 +/**
  6 + * Function:消息回调 bean
  7 + *
  8 + * @author crossoverJie
  9 + * Date: 2018/12/26 17:37
  10 + * @since JDK 1.8
  11 + */
  12 +public class MsgHandleCaller {
  13 +
  14 + /**
  15 + * 回调接口
  16 + */
  17 + private CustomMsgHandleListener msgHandleListener ;
  18 +
  19 + public MsgHandleCaller(CustomMsgHandleListener msgHandleListener) {
  20 + this.msgHandleListener = msgHandleListener;
  21 + }
  22 +
  23 + public CustomMsgHandleListener getMsgHandleListener() {
  24 + return msgHandleListener;
  25 + }
  26 +
  27 + public void setMsgHandleListener(CustomMsgHandleListener msgHandleListener) {
  28 + this.msgHandleListener = msgHandleListener;
  29 + }
  30 +}
1 -package com.crossoverjie.netty.action.client.init; 1 +package com.crossoverjie.cim.client.init;
2 2
3 -import com.crossoverjie.netty.action.client.handle.EchoClientHandle;  
4 -import com.crossoverjie.netty.action.common.protocol.BaseResponseProto; 3 +import com.crossoverjie.cim.client.handle.CIMClientHandle;
  4 +import com.crossoverjie.cim.common.protocol.CIMResponseProto;
5 import io.netty.channel.Channel; 5 import io.netty.channel.Channel;
6 import io.netty.channel.ChannelInitializer; 6 import io.netty.channel.ChannelInitializer;
7 import io.netty.handler.codec.protobuf.ProtobufDecoder; 7 import io.netty.handler.codec.protobuf.ProtobufDecoder;
@@ -17,12 +17,15 @@ import io.netty.handler.timeout.IdleStateHandler; @@ -17,12 +17,15 @@ import io.netty.handler.timeout.IdleStateHandler;
17 * Date: 23/02/2018 22:47 17 * Date: 23/02/2018 22:47
18 * @since JDK 1.8 18 * @since JDK 1.8
19 */ 19 */
20 -public class CustomerHandleInitializer extends ChannelInitializer<Channel> { 20 +public class CIMClientHandleInitializer extends ChannelInitializer<Channel> {
  21 +
  22 + private final CIMClientHandle cimClientHandle = new CIMClientHandle();
  23 +
21 @Override 24 @Override
22 protected void initChannel(Channel ch) throws Exception { 25 protected void initChannel(Channel ch) throws Exception {
23 ch.pipeline() 26 ch.pipeline()
24 - //10 秒没发送消息 将IdleStateHandler 添加到 ChannelPipeline 中  
25 - .addLast(new IdleStateHandler(0, 10, 0)) 27 + //60 秒没发送消息 将IdleStateHandler 添加到 ChannelPipeline 中
  28 + .addLast(new IdleStateHandler(0, 60, 0))
26 29
27 //心跳解码 30 //心跳解码
28 //.addLast(new HeartbeatEncode()) 31 //.addLast(new HeartbeatEncode())
@@ -30,14 +33,12 @@ public class CustomerHandleInitializer extends ChannelInitializer<Channel> { @@ -30,14 +33,12 @@ public class CustomerHandleInitializer extends ChannelInitializer<Channel> {
30 // google Protobuf 编解码 33 // google Protobuf 编解码
31 //拆包解码 34 //拆包解码
32 .addLast(new ProtobufVarint32FrameDecoder()) 35 .addLast(new ProtobufVarint32FrameDecoder())
33 - .addLast(new ProtobufDecoder(BaseResponseProto.ResponseProtocol.getDefaultInstance())) 36 + .addLast(new ProtobufDecoder(CIMResponseProto.CIMResProtocol.getDefaultInstance()))
34 // 37 //
35 //拆包编码 38 //拆包编码
36 .addLast(new ProtobufVarint32LengthFieldPrepender()) 39 .addLast(new ProtobufVarint32LengthFieldPrepender())
37 .addLast(new ProtobufEncoder()) 40 .addLast(new ProtobufEncoder())
38 -  
39 -  
40 - .addLast(new EchoClientHandle()) 41 + .addLast(cimClientHandle)
41 ; 42 ;
42 } 43 }
43 } 44 }
  1 +package com.crossoverjie.cim.client.scanner;
  2 +
  3 +import com.crossoverjie.cim.client.config.AppConfiguration;
  4 +import com.crossoverjie.cim.client.service.MsgHandle;
  5 +import com.crossoverjie.cim.client.util.SpringBeanFactory;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +
  9 +import java.util.Scanner;
  10 +
  11 +/**
  12 + * Function:
  13 + *
  14 + * @author crossoverJie
  15 + * Date: 2018/12/21 16:44
  16 + * @since JDK 1.8
  17 + */
  18 +public class Scan implements Runnable {
  19 +
  20 + private final static Logger LOGGER = LoggerFactory.getLogger(Scan.class);
  21 +
  22 + /**
  23 + * 系统参数
  24 + */
  25 + private AppConfiguration configuration;
  26 +
  27 + private MsgHandle msgHandle ;
  28 +
  29 + public Scan() {
  30 + this.configuration = SpringBeanFactory.getBean(AppConfiguration.class);
  31 + this.msgHandle = SpringBeanFactory.getBean(MsgHandle.class) ;
  32 + }
  33 +
  34 + @Override
  35 + public void run() {
  36 + Scanner sc = new Scanner(System.in);
  37 + while (true) {
  38 + String msg = sc.nextLine();
  39 +
  40 + //检查消息
  41 + if (msgHandle.checkMsg(msg)) {
  42 + continue;
  43 + }
  44 +
  45 + //系统内置命令
  46 + if (msgHandle.innerCommand(msg)){
  47 + continue;
  48 + }
  49 +
  50 + //真正的发送消息
  51 + msgHandle.sendMsg(msg) ;
  52 +
  53 +
  54 + LOGGER.info("{}:【{}】", configuration.getUserName(), msg);
  55 + }
  56 + }
  57 +
  58 +}
  1 +package com.crossoverjie.cim.client.service;
  2 +
  3 +/**
  4 + * Function: 自定义消息回调
  5 + *
  6 + * @author crossoverJie
  7 + * Date: 2018/12/26 17:24
  8 + * @since JDK 1.8
  9 + */
  10 +public interface CustomMsgHandleListener {
  11 +
  12 + /**
  13 + * 消息回调
  14 + * @param msg
  15 + */
  16 + void handle(String msg);
  17 +}
  1 +package com.crossoverjie.cim.client.service;
  2 +
  3 +import com.crossoverjie.cim.client.vo.req.GroupReqVO;
  4 +import com.crossoverjie.cim.client.vo.req.P2PReqVO;
  5 +
  6 +/**
  7 + * Function:消息处理器
  8 + *
  9 + * @author crossoverJie
  10 + * Date: 2018/12/26 11:11
  11 + * @since JDK 1.8
  12 + */
  13 +public interface MsgHandle {
  14 +
  15 + /**
  16 + * 统一的发送接口,包含了 groupChat p2pChat
  17 + * @param msg
  18 + */
  19 + void sendMsg(String msg) ;
  20 +
  21 + /**
  22 + * 群聊
  23 + * @param groupReqVO 群聊消息 其中的 userId 为发送者的 userID
  24 + * @throws Exception
  25 + */
  26 + void groupChat(GroupReqVO groupReqVO) throws Exception ;
  27 +
  28 + /**
  29 + * 私聊
  30 + * @param p2PReqVO 私聊请求
  31 + * @throws Exception
  32 + */
  33 + void p2pChat(P2PReqVO p2PReqVO) throws Exception;
  34 +
  35 +
  36 + // TODO: 2018/12/26 后续对消息的处理可以优化为责任链模式
  37 + /**
  38 + * 校验消息
  39 + * @param msg
  40 + * @return 不能为空,后续可以加上一些敏感词
  41 + * @throws Exception
  42 + */
  43 + boolean checkMsg(String msg) ;
  44 +
  45 + /**
  46 + * 执行内部命令
  47 + * @param msg
  48 + * @return 是否应当跳过当前消息(包含了":" 就需要跳过)
  49 + */
  50 + boolean innerCommand(String msg) ;
  51 +}
  1 +package com.crossoverjie.cim.client.service;
  2 +
  3 +import com.crossoverjie.cim.client.vo.req.GroupReqVO;
  4 +import com.crossoverjie.cim.client.vo.req.LoginReqVO;
  5 +import com.crossoverjie.cim.client.vo.req.P2PReqVO;
  6 +import com.crossoverjie.cim.client.vo.res.CIMServerResVO;
  7 +import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO;
  8 +
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * Function:
  13 + *
  14 + * @author crossoverJie
  15 + * Date: 2018/12/22 22:26
  16 + * @since JDK 1.8
  17 + */
  18 +public interface RouteRequest {
  19 +
  20 + /**
  21 + * 群发消息
  22 + * @param groupReqVO 消息
  23 + * @throws Exception
  24 + */
  25 + void sendGroupMsg(GroupReqVO groupReqVO) throws Exception;
  26 +
  27 +
  28 + /**
  29 + * 私聊
  30 + * @param p2PReqVO
  31 + * @throws Exception
  32 + */
  33 + void sendP2PMsg(P2PReqVO p2PReqVO)throws Exception;
  34 +
  35 + /**
  36 + * 获取服务器
  37 + * @return 服务ip+port
  38 + * @param loginReqVO
  39 + * @throws Exception
  40 + */
  41 + CIMServerResVO.ServerInfo getCIMServer(LoginReqVO loginReqVO) throws Exception;
  42 +
  43 + /**
  44 + *
  45 + * @return 获取所有在线用户
  46 + */
  47 + List<OnlineUsersResVO.DataBodyBean> onlineUsers()throws Exception ;
  48 +
  49 +
  50 +}
  1 +package com.crossoverjie.cim.client.service.impl;
  2 +
  3 +import com.crossoverjie.cim.client.client.CIMClient;
  4 +import com.crossoverjie.cim.client.config.AppConfiguration;
  5 +import com.crossoverjie.cim.client.service.MsgHandle;
  6 +import com.crossoverjie.cim.client.service.RouteRequest;
  7 +import com.crossoverjie.cim.client.vo.req.GroupReqVO;
  8 +import com.crossoverjie.cim.client.vo.req.P2PReqVO;
  9 +import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO;
  10 +import com.crossoverjie.cim.common.enums.SystemCommandEnumType;
  11 +import com.crossoverjie.cim.common.util.StringUtil;
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.stereotype.Service;
  16 +
  17 +import java.util.List;
  18 +import java.util.Map;
  19 +import java.util.concurrent.ThreadPoolExecutor;
  20 +import java.util.concurrent.TimeUnit;
  21 +
  22 +/**
  23 + * Function:
  24 + *
  25 + * @author crossoverJie
  26 + * Date: 2018/12/26 11:15
  27 + * @since JDK 1.8
  28 + */
  29 +@Service
  30 +public class MsgHandler implements MsgHandle {
  31 + private final static Logger LOGGER = LoggerFactory.getLogger(MsgHandler.class);
  32 + @Autowired
  33 + private RouteRequest routeRequest ;
  34 +
  35 + @Autowired
  36 + private AppConfiguration configuration;
  37 +
  38 + @Autowired
  39 + private ThreadPoolExecutor executor ;
  40 +
  41 + @Autowired
  42 + private CIMClient cimClient ;
  43 +
  44 + @Override
  45 + public void sendMsg(String msg) {
  46 + String[] totalMsg = msg.split(";;");
  47 + if (totalMsg.length > 1) {
  48 + //私聊
  49 + P2PReqVO p2PReqVO = new P2PReqVO();
  50 + p2PReqVO.setUserId(configuration.getUserId());
  51 + p2PReqVO.setReceiveUserId(Long.parseLong(totalMsg[0]));
  52 + p2PReqVO.setMsg(totalMsg[1]);
  53 + try {
  54 + p2pChat(p2PReqVO);
  55 + } catch (Exception e) {
  56 + LOGGER.error("Exception",e);
  57 + }
  58 +
  59 + } else {
  60 + //群聊
  61 + GroupReqVO groupReqVO = new GroupReqVO(configuration.getUserId(), msg);
  62 + try {
  63 + groupChat(groupReqVO);
  64 + } catch (Exception e) {
  65 + LOGGER.error("Exception",e);
  66 + }
  67 + }
  68 + }
  69 +
  70 + @Override
  71 + public void groupChat(GroupReqVO groupReqVO) throws Exception {
  72 + routeRequest.sendGroupMsg(groupReqVO);
  73 + }
  74 +
  75 + @Override
  76 + public void p2pChat(P2PReqVO p2PReqVO) throws Exception {
  77 +
  78 + routeRequest.sendP2PMsg(p2PReqVO);
  79 +
  80 + }
  81 +
  82 + @Override
  83 + public boolean checkMsg(String msg) {
  84 + if (StringUtil.isEmpty(msg)){
  85 + LOGGER.warn("不能发送空消息!");
  86 + return true;
  87 + }
  88 + return false;
  89 + }
  90 +
  91 + @Override
  92 + public boolean innerCommand(String msg) {
  93 +
  94 + if (msg.startsWith(":")){
  95 + Map<String, String> allStatusCode = SystemCommandEnumType.getAllStatusCode();
  96 +
  97 + if (SystemCommandEnumType.QUIT.getCommandType().trim().equals(msg)){
  98 + //关闭系统
  99 + shutdown();
  100 + } else if (SystemCommandEnumType.ALL.getCommandType().trim().equals(msg)){
  101 + printAllCommand(allStatusCode);
  102 +
  103 + } else if (SystemCommandEnumType.ONLINE_USER.getCommandType().toLowerCase().trim().equals(msg.toLowerCase())){
  104 + //打印在线用户
  105 + printOnlineUsers();
  106 +
  107 + }else {
  108 + printAllCommand(allStatusCode);
  109 + }
  110 +
  111 + return true ;
  112 +
  113 + }else {
  114 + return false ;
  115 + }
  116 +
  117 +
  118 + }
  119 +
  120 + /**
  121 + * 打印在线用户
  122 + */
  123 + private void printOnlineUsers() {
  124 + try {
  125 + List<OnlineUsersResVO.DataBodyBean> onlineUsers = routeRequest.onlineUsers();
  126 +
  127 + LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  128 + for (OnlineUsersResVO.DataBodyBean onlineUser : onlineUsers) {
  129 + LOGGER.info("userId={}=====userName={}",onlineUser.getUserId(),onlineUser.getUserName());
  130 + }
  131 + LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  132 +
  133 + } catch (Exception e) {
  134 + LOGGER.error("Exception" ,e);
  135 + }
  136 + }
  137 +
  138 + /**
  139 + * 关闭系统
  140 + */
  141 + private void shutdown() {
  142 + LOGGER.info("系统关闭中。。。。");
  143 + executor.shutdown();
  144 + try {
  145 + while (!executor.awaitTermination(1, TimeUnit.SECONDS)) {
  146 + LOGGER.info("线程池关闭中。。。。");
  147 + }
  148 + cimClient.close();
  149 + } catch (InterruptedException e) {
  150 + LOGGER.error("InterruptedException",e);
  151 + }
  152 + System.exit(0);
  153 + }
  154 +
  155 + private void printAllCommand(Map<String, String> allStatusCode) {
  156 + LOGGER.warn("====================================");
  157 + for (Map.Entry<String, String> stringStringEntry : allStatusCode.entrySet()) {
  158 + String key = stringStringEntry.getKey();
  159 + String value = stringStringEntry.getValue();
  160 + LOGGER.warn(key + "----->" + value);
  161 + }
  162 + LOGGER.warn("====================================");
  163 + }
  164 +}
  1 +package com.crossoverjie.cim.client.service.impl;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import com.crossoverjie.cim.client.config.AppConfiguration;
  6 +import com.crossoverjie.cim.client.service.RouteRequest;
  7 +import com.crossoverjie.cim.client.vo.req.GroupReqVO;
  8 +import com.crossoverjie.cim.client.vo.req.LoginReqVO;
  9 +import com.crossoverjie.cim.client.vo.req.P2PReqVO;
  10 +import com.crossoverjie.cim.client.vo.res.CIMServerResVO;
  11 +import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO;
  12 +import com.crossoverjie.cim.common.enums.StatusEnum;
  13 +import com.crossoverjie.cim.common.res.BaseResponse;
  14 +import okhttp3.*;
  15 +import org.slf4j.Logger;
  16 +import org.slf4j.LoggerFactory;
  17 +import org.springframework.beans.factory.annotation.Autowired;
  18 +import org.springframework.beans.factory.annotation.Value;
  19 +import org.springframework.stereotype.Service;
  20 +
  21 +import java.io.IOException;
  22 +import java.util.List;
  23 +
  24 +/**
  25 + * Function:
  26 + *
  27 + * @author crossoverJie
  28 + * Date: 2018/12/22 22:27
  29 + * @since JDK 1.8
  30 + */
  31 +@Service
  32 +public class RouteRequestImpl implements RouteRequest {
  33 +
  34 + private final static Logger LOGGER = LoggerFactory.getLogger(RouteRequestImpl.class);
  35 +
  36 + @Autowired
  37 + private OkHttpClient okHttpClient ;
  38 +
  39 + private MediaType mediaType = MediaType.parse("application/json");
  40 +
  41 + @Value("${cim.group.route.request.url}")
  42 + private String groupRouteRequestUrl;
  43 +
  44 + @Value("${cim.p2p.route.request.url}")
  45 + private String p2pRouteRequestUrl;
  46 +
  47 + @Value("${cim.server.route.request.url}")
  48 + private String serverRouteRequestUrl;
  49 +
  50 + @Value("${cim.server.online.user.url}")
  51 + private String onlineUserUrl;
  52 +
  53 +
  54 +
  55 + @Autowired
  56 + private AppConfiguration appConfiguration ;
  57 +
  58 + @Override
  59 + public void sendGroupMsg(GroupReqVO groupReqVO) throws Exception {
  60 +
  61 + JSONObject jsonObject = new JSONObject();
  62 + jsonObject.put("msg",groupReqVO.getMsg());
  63 + jsonObject.put("userId",groupReqVO.getUserId());
  64 + RequestBody requestBody = RequestBody.create(mediaType,jsonObject.toString());
  65 +
  66 + Request request = new Request.Builder()
  67 + .url(groupRouteRequestUrl)
  68 + .post(requestBody)
  69 + .build();
  70 +
  71 + Response response = okHttpClient.newCall(request).execute() ;
  72 + if (!response.isSuccessful()){
  73 + throw new IOException("Unexpected code " + response);
  74 + }
  75 + }
  76 +
  77 + @Override
  78 + public void sendP2PMsg(P2PReqVO p2PReqVO) throws Exception {
  79 + JSONObject jsonObject = new JSONObject();
  80 + jsonObject.put("msg",p2PReqVO.getMsg());
  81 + jsonObject.put("userId",p2PReqVO.getUserId());
  82 + jsonObject.put("receiveUserId",p2PReqVO.getReceiveUserId());
  83 + RequestBody requestBody = RequestBody.create(mediaType,jsonObject.toString());
  84 +
  85 + Request request = new Request.Builder()
  86 + .url(p2pRouteRequestUrl)
  87 + .post(requestBody)
  88 + .build();
  89 +
  90 + Response response = okHttpClient.newCall(request).execute() ;
  91 + if (!response.isSuccessful()){
  92 + throw new IOException("Unexpected code " + response);
  93 + }
  94 +
  95 + String json = response.body().string() ;
  96 + BaseResponse baseResponse = JSON.parseObject(json, BaseResponse.class);
  97 +
  98 + //选择的账号不存在
  99 + if (baseResponse.getCode().equals(StatusEnum.OFF_LINE.getCode())){
  100 + LOGGER.error(p2PReqVO.getReceiveUserId() + ":" + StatusEnum.OFF_LINE.getMessage());
  101 + }
  102 + }
  103 +
  104 + @Override
  105 + public CIMServerResVO.ServerInfo getCIMServer(LoginReqVO loginReqVO) throws Exception {
  106 +
  107 + JSONObject jsonObject = new JSONObject();
  108 + jsonObject.put("userId",loginReqVO.getUserId());
  109 + jsonObject.put("userName",loginReqVO.getUserName());
  110 + RequestBody requestBody = RequestBody.create(mediaType,jsonObject.toString());
  111 +
  112 + Request request = new Request.Builder()
  113 + .url(serverRouteRequestUrl)
  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 +
  122 + String json = response.body().string();
  123 + CIMServerResVO cimServerResVO = JSON.parseObject(json, CIMServerResVO.class);
  124 +
  125 + //重复登录
  126 + if (cimServerResVO.getCode().equals(StatusEnum.REPEAT_LOGIN.getCode())){
  127 + LOGGER.error(appConfiguration.getUserName() + ":" + StatusEnum.REPEAT_LOGIN.getMessage());
  128 + System.exit(-1);
  129 + }
  130 +
  131 + if (!cimServerResVO.getCode().equals(StatusEnum.SUCCESS.getCode())){
  132 + throw new RuntimeException("route server exception code=" + cimServerResVO.getCode()) ;
  133 + }
  134 +
  135 + return cimServerResVO.getDataBody();
  136 + }
  137 +
  138 + @Override
  139 + public List<OnlineUsersResVO.DataBodyBean> onlineUsers() throws Exception{
  140 +
  141 + JSONObject jsonObject = new JSONObject();
  142 + RequestBody requestBody = RequestBody.create(mediaType,jsonObject.toString());
  143 +
  144 + Request request = new Request.Builder()
  145 + .url(onlineUserUrl)
  146 + .post(requestBody)
  147 + .build();
  148 +
  149 + Response response = okHttpClient.newCall(request).execute() ;
  150 + if (!response.isSuccessful()){
  151 + throw new IOException("Unexpected code " + response);
  152 + }
  153 + if (!response.isSuccessful()){
  154 + throw new IOException("Unexpected code " + response);
  155 + }
  156 +
  157 + String json = response.body().string() ;
  158 + OnlineUsersResVO onlineUsersResVO = JSON.parseObject(json, OnlineUsersResVO.class);
  159 +
  160 + return onlineUsersResVO.getDataBody();
  161 + }
  162 +}
1 -package com.crossoverjie.netty.action.client.util; 1 +package com.crossoverjie.cim.client.util;
2 2
3 import org.springframework.beans.BeansException; 3 import org.springframework.beans.BeansException;
4 import org.springframework.context.ApplicationContext; 4 import org.springframework.context.ApplicationContext;
1 -package com.crossoverjie.netty.action.client.vo.req; 1 +package com.crossoverjie.cim.client.vo.req;
2 2
3 -import com.crossoverjie.netty.action.common.req.BaseRequest; 3 +import com.crossoverjie.cim.common.req.BaseRequest;
4 import io.swagger.annotations.ApiModelProperty; 4 import io.swagger.annotations.ApiModelProperty;
5 5
6 import javax.validation.constraints.NotNull; 6 import javax.validation.constraints.NotNull;
  1 +package com.crossoverjie.cim.client.vo.req;
  2 +
  3 +import com.crossoverjie.cim.common.req.BaseRequest;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +
  6 +import javax.validation.constraints.NotNull;
  7 +
  8 +/**
  9 + * Function: 群发请求
  10 + *
  11 + * @author crossoverJie
  12 + * Date: 2018/05/21 15:56
  13 + * @since JDK 1.8
  14 + */
  15 +public class GroupReqVO extends BaseRequest {
  16 +
  17 + @NotNull(message = "userId 不能为空")
  18 + @ApiModelProperty(required = true, value = "消息发送者的 userId", example = "1545574049323")
  19 + private Long userId ;
  20 +
  21 +
  22 + @NotNull(message = "msg 不能为空")
  23 + @ApiModelProperty(required = true, value = "msg", example = "hello")
  24 + private String msg ;
  25 +
  26 + public GroupReqVO(Long userId, String msg) {
  27 + this.userId = userId;
  28 + this.msg = msg;
  29 + }
  30 +
  31 + public String getMsg() {
  32 + return msg;
  33 + }
  34 +
  35 + public void setMsg(String msg) {
  36 + this.msg = msg;
  37 + }
  38 +
  39 + public Long getUserId() {
  40 + return userId;
  41 + }
  42 +
  43 + public void setUserId(Long userId) {
  44 + this.userId = userId;
  45 + }
  46 +
  47 + @Override
  48 + public String toString() {
  49 + return "GroupReqVO{" +
  50 + "userId=" + userId +
  51 + ", msg='" + msg + '\'' +
  52 + "} " + super.toString();
  53 + }
  54 +}
  1 +package com.crossoverjie.cim.client.vo.req;
  2 +
  3 +import com.crossoverjie.cim.common.req.BaseRequest;
  4 +
  5 +/**
  6 + * Function:
  7 + *
  8 + * @author crossoverJie
  9 + * Date: 2018/12/23 22:30
  10 + * @since JDK 1.8
  11 + */
  12 +public class LoginReqVO extends BaseRequest{
  13 + private Long userId ;
  14 + private String userName ;
  15 +
  16 + public LoginReqVO(Long userId, String userName) {
  17 + this.userId = userId;
  18 + this.userName = userName;
  19 + }
  20 +
  21 + public Long getUserId() {
  22 + return userId;
  23 + }
  24 +
  25 + public void setUserId(Long userId) {
  26 + this.userId = userId;
  27 + }
  28 +
  29 + public String getUserName() {
  30 + return userName;
  31 + }
  32 +
  33 + public void setUserName(String userName) {
  34 + this.userName = userName;
  35 + }
  36 +
  37 + @Override
  38 + public String toString() {
  39 + return "LoginReqVO{" +
  40 + "userId=" + userId +
  41 + ", userName='" + userName + '\'' +
  42 + "} " + super.toString();
  43 + }
  44 +}
  1 +package com.crossoverjie.cim.client.vo.req;
  2 +
  3 +import com.crossoverjie.cim.common.req.BaseRequest;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +
  6 +import javax.validation.constraints.NotNull;
  7 +
  8 +/**
  9 + * Function: 单聊请求
  10 + *
  11 + * @author crossoverJie
  12 + * Date: 2018/05/21 15:56
  13 + * @since JDK 1.8
  14 + */
  15 +public class P2PReqVO extends BaseRequest {
  16 +
  17 + @NotNull(message = "userId 不能为空")
  18 + @ApiModelProperty(required = true, value = "消息发送者的 userId", example = "1545574049323")
  19 + private Long userId ;
  20 +
  21 +
  22 + @NotNull(message = "userId 不能为空")
  23 + @ApiModelProperty(required = true, value = "消息接收者的 userId", example = "1545574049323")
  24 + private Long receiveUserId ;
  25 +
  26 +
  27 +
  28 +
  29 + @NotNull(message = "msg 不能为空")
  30 + @ApiModelProperty(required = true, value = "msg", example = "hello")
  31 + private String msg ;
  32 +
  33 + public P2PReqVO() {
  34 + }
  35 +
  36 + public P2PReqVO(Long userId, Long receiveUserId, String msg) {
  37 + this.userId = userId;
  38 + this.receiveUserId = receiveUserId;
  39 + this.msg = msg;
  40 + }
  41 +
  42 + public Long getReceiveUserId() {
  43 + return receiveUserId;
  44 + }
  45 +
  46 + public void setReceiveUserId(Long receiveUserId) {
  47 + this.receiveUserId = receiveUserId;
  48 + }
  49 +
  50 + public String getMsg() {
  51 + return msg;
  52 + }
  53 +
  54 + public void setMsg(String msg) {
  55 + this.msg = msg;
  56 + }
  57 +
  58 + public Long getUserId() {
  59 + return userId;
  60 + }
  61 +
  62 + public void setUserId(Long userId) {
  63 + this.userId = userId;
  64 + }
  65 +
  66 + @Override
  67 + public String toString() {
  68 + return "GroupReqVO{" +
  69 + "userId=" + userId +
  70 + ", msg='" + msg + '\'' +
  71 + "} " + super.toString();
  72 + }
  73 +}
1 -package com.crossoverjie.netty.action.vo.req; 1 +package com.crossoverjie.cim.client.vo.req;
2 2
3 -import com.crossoverjie.netty.action.common.req.BaseRequest; 3 +import com.crossoverjie.cim.common.req.BaseRequest;
4 import io.swagger.annotations.ApiModelProperty; 4 import io.swagger.annotations.ApiModelProperty;
5 5
6 import javax.validation.constraints.NotNull; 6 import javax.validation.constraints.NotNull;
@@ -18,9 +18,9 @@ public class SendMsgReqVO extends BaseRequest { @@ -18,9 +18,9 @@ public class SendMsgReqVO extends BaseRequest {
18 @ApiModelProperty(required = true, value = "msg", example = "hello") 18 @ApiModelProperty(required = true, value = "msg", example = "hello")
19 private String msg ; 19 private String msg ;
20 20
21 - @NotNull(message = "id 不能为空")  
22 - @ApiModelProperty(required = true, value = "id", example = "11")  
23 - private long id ; 21 + @NotNull(message = "userId 不能为空")
  22 + @ApiModelProperty(required = true, value = "userId", example = "11")
  23 + private Long userId ;
24 24
25 public String getMsg() { 25 public String getMsg() {
26 return msg; 26 return msg;
@@ -30,11 +30,11 @@ public class SendMsgReqVO extends BaseRequest { @@ -30,11 +30,11 @@ public class SendMsgReqVO extends BaseRequest {
30 this.msg = msg; 30 this.msg = msg;
31 } 31 }
32 32
33 - public long getId() {  
34 - return id; 33 + public long getUserId() {
  34 + return userId;
35 } 35 }
36 36
37 - public void setId(long id) {  
38 - this.id = id; 37 + public void setUserId(long userId) {
  38 + this.userId = userId;
39 } 39 }
40 } 40 }
1 -package com.crossoverjie.netty.action.client.vo.req; 1 +package com.crossoverjie.cim.client.vo.req;
2 2
3 -import com.crossoverjie.netty.action.common.req.BaseRequest; 3 +import com.crossoverjie.cim.common.req.BaseRequest;
4 import io.swagger.annotations.ApiModelProperty; 4 import io.swagger.annotations.ApiModelProperty;
5 5
6 import javax.validation.constraints.NotNull; 6 import javax.validation.constraints.NotNull;
  1 +package com.crossoverjie.cim.client.vo.res;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +/**
  6 + * Function:
  7 + *
  8 + * @author crossoverJie
  9 + * Date: 2018/12/23 00:43
  10 + * @since JDK 1.8
  11 + */
  12 +public class CIMServerResVO implements Serializable {
  13 +
  14 + /**
  15 + * code : 9000
  16 + * message : 成功
  17 + * reqNo : null
  18 + * dataBody : {"ip":"127.0.0.1","port":8081}
  19 + */
  20 +
  21 + private String code;
  22 + private String message;
  23 + private Object reqNo;
  24 + private ServerInfo dataBody;
  25 +
  26 + public String getCode() {
  27 + return code;
  28 + }
  29 +
  30 + public void setCode(String code) {
  31 + this.code = code;
  32 + }
  33 +
  34 + public String getMessage() {
  35 + return message;
  36 + }
  37 +
  38 + public void setMessage(String message) {
  39 + this.message = message;
  40 + }
  41 +
  42 + public Object getReqNo() {
  43 + return reqNo;
  44 + }
  45 +
  46 + public void setReqNo(Object reqNo) {
  47 + this.reqNo = reqNo;
  48 + }
  49 +
  50 + public ServerInfo getDataBody() {
  51 + return dataBody;
  52 + }
  53 +
  54 + public void setDataBody(ServerInfo dataBody) {
  55 + this.dataBody = dataBody;
  56 + }
  57 +
  58 + public static class ServerInfo {
  59 + /**
  60 + * ip : 127.0.0.1
  61 + * port : 8081
  62 + */
  63 + private String ip ;
  64 + private Integer cimServerPort;
  65 + private Integer httpPort;
  66 +
  67 + public String getIp() {
  68 + return ip;
  69 + }
  70 +
  71 + public void setIp(String ip) {
  72 + this.ip = ip;
  73 + }
  74 +
  75 + public Integer getCimServerPort() {
  76 + return cimServerPort;
  77 + }
  78 +
  79 + public void setCimServerPort(Integer cimServerPort) {
  80 + this.cimServerPort = cimServerPort;
  81 + }
  82 +
  83 + public Integer getHttpPort() {
  84 + return httpPort;
  85 + }
  86 +
  87 + public void setHttpPort(Integer httpPort) {
  88 + this.httpPort = httpPort;
  89 + }
  90 +
  91 + @Override
  92 + public String toString() {
  93 + return "ServerInfo{" +
  94 + "ip='" + ip + '\'' +
  95 + ", cimServerPort=" + cimServerPort +
  96 + ", httpPort=" + httpPort +
  97 + '}';
  98 + }
  99 + }
  100 +
  101 +
  102 + @Override
  103 + public String toString() {
  104 + return "CIMServerResVO{" +
  105 + "code='" + code + '\'' +
  106 + ", message='" + message + '\'' +
  107 + ", reqNo=" + reqNo +
  108 + ", dataBody=" + dataBody +
  109 + '}';
  110 + }
  111 +}
  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 +}
  1 +spring.application.name=netty-heartbeat-client
  2 +
  3 +# web port
  4 +server.port=8082
  5 +
  6 +# 是否打开swagger
  7 +swagger.enable = true
  8 +
  9 +logging.level.root=info
  10 +
  11 +
  12 +###=======生产模拟======###
  13 +# 群发消息
  14 +cim.group.route.request.url=http://45.78.28.220:8083/groupRoute
  15 +
  16 +# 私聊消息
  17 +cim.p2p.route.request.url=http://45.78.28.220:8083/p2pRoute
  18 +
  19 +# 登录并获取服务器ip+port
  20 +cim.server.route.request.url=http://45.78.28.220:8083/login
  21 +
  22 +# 在线用户
  23 +cim.server.online.user.url=http://45.78.28.220:8083/onlineUser
  24 +
  25 +
  26 +###=======本地模拟======###
  27 +## 群发消息
  28 +#cim.group.route.request.url=http://localhost:8083/groupRoute
  29 +#
  30 +## 私聊消息
  31 +#cim.p2p.route.request.url=http://localhost:8083/p2pRoute
  32 +#
  33 +## 登录并获取服务器ip+port
  34 +#cim.server.route.request.url=http://localhost:8083/login
  35 +#
  36 +## 在线用户
  37 +#cim.server.online.user=http://localhost:8083/onlineUser
  38 +
  39 +# 客户端唯一ID
  40 +cim.user.id=1545574841528
  41 +cim.user.userName=zhangsan
  42 +
  43 +# 回调线程队列大小
  44 +cim.callback.thread.queue.size = 2
  45 +# 回调线程池大小
  46 +cim.callback.thread.pool.size = 2
  47 +
  48 +# 关闭健康检查权限
  49 +management.security.enabled=false
  50 +# SpringAdmin 地址
  51 +spring.boot.admin.url=http://127.0.0.1:8888
  1 +
  2 + ▄████▄ ██▓ ███▄ ▄███▓
  3 +▒██▀ ▀█ ▓██▒▓██▒▀█▀ ██▒
  4 +▒▓█ ▄ ▒██▒▓██ ▓██░
  5 +▒▓▓▄ ▄██▒░██░▒██ ▒██
  6 +▒ ▓███▀ ░░██░▒██▒ ░██▒
  7 +░ ░▒ ▒ ░░▓ ░ ▒░ ░ ░
  8 + ░ ▒ ▒ ░░ ░ ░
  9 +░ ▒ ░░ ░
  10 +░ ░ ░ ░
  11 +
  12 + Power by @crossoverJie
  13 +
  14 +
  15 +
  1 +package com.crossoverjie.cim.server.test;
  2 +
  3 +
  4 +import com.alibaba.fastjson.JSON;
  5 +import com.crossoverjie.cim.client.vo.res.CIMServerResVO;
  6 +import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO;
  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;
  13 +
  14 +/**
  15 + * Function:
  16 + *
  17 + * @author crossoverJie
  18 + * Date: 22/05/2018 18:44
  19 + * @since JDK 1.8
  20 + */
  21 +public class CommonTest {
  22 +
  23 + private final static Logger LOGGER = LoggerFactory.getLogger(CommonTest.class);
  24 + @Test
  25 + public void test() {
  26 +
  27 + String json = "{\"code\":\"9000\",\"message\":\"成功\",\"reqNo\":null,\"dataBody\":{\"ip\":\"127.0.0.1\",\"port\":8081}}" ;
  28 +
  29 + CIMServerResVO cimServerResVO = JSON.parseObject(json, CIMServerResVO.class);
  30 +
  31 + System.out.println(cimServerResVO.toString());
  32 +
  33 + String text = "nihaoaaa" ;
  34 + String[] split = text.split(" ");
  35 + System.out.println(split.length);
  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 + }
  63 +}
  1 +package com.crossoverjie.cim.server.test;
  2 +
  3 +import com.crossoverjie.cim.client.CIMClientApplication;
  4 +import com.crossoverjie.cim.client.service.RouteRequest;
  5 +import com.crossoverjie.cim.client.vo.req.LoginReqVO;
  6 +import com.crossoverjie.cim.client.vo.res.CIMServerResVO;
  7 +import org.junit.Test;
  8 +import org.junit.runner.RunWith;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.beans.factory.annotation.Value;
  13 +import org.springframework.boot.test.context.SpringBootTest;
  14 +import org.springframework.test.context.junit4.SpringRunner;
  15 +
  16 +/**
  17 + * Function:
  18 + *
  19 + * @author crossoverJie
  20 + * Date: 2018/12/23 22:39
  21 + * @since JDK 1.8
  22 + */
  23 +@SpringBootTest(classes = CIMClientApplication.class)
  24 +@RunWith(SpringRunner.class)
  25 +public class RouteTest {
  26 +
  27 + private final static Logger LOGGER = LoggerFactory.getLogger(RouteTest.class);
  28 +
  29 + @Value("${cim.user.id}")
  30 + private long userId;
  31 +
  32 + @Value("${cim.user.userName}")
  33 + private String userName;
  34 +
  35 + @Autowired
  36 + private RouteRequest routeRequest ;
  37 +
  38 + @Test
  39 + public void test() throws Exception {
  40 + LoginReqVO vo = new LoginReqVO(userId,userName) ;
  41 + CIMServerResVO.ServerInfo cimServer = routeRequest.getCIMServer(vo);
  42 + LOGGER.info("cimServer=[{}]",cimServer.toString());
  43 + }
  44 +}
@@ -3,13 +3,14 @@ @@ -3,13 +3,14 @@
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5 <parent> 5 <parent>
6 - <artifactId>netty-action</artifactId> 6 + <artifactId>cim</artifactId>
7 <groupId>com.crossoverjie.netty</groupId> 7 <groupId>com.crossoverjie.netty</groupId>
8 <version>1.0.0-SNAPSHOT</version> 8 <version>1.0.0-SNAPSHOT</version>
9 </parent> 9 </parent>
10 <modelVersion>4.0.0</modelVersion> 10 <modelVersion>4.0.0</modelVersion>
  11 + <version>1.0.1-SNAPSHOT</version>
11 12
12 - <artifactId>netty-action-common</artifactId> 13 + <artifactId>cim-common</artifactId>
13 14
14 15
15 <dependencies> 16 <dependencies>
@@ -19,6 +20,11 @@ @@ -19,6 +20,11 @@
19 </dependency> 20 </dependency>
20 21
21 <dependency> 22 <dependency>
  23 + <groupId>com.squareup.okhttp3</groupId>
  24 + <artifactId>okhttp</artifactId>
  25 + </dependency>
  26 +
  27 + <dependency>
22 <groupId>io.springfox</groupId> 28 <groupId>io.springfox</groupId>
23 <artifactId>springfox-swagger2</artifactId> 29 <artifactId>springfox-swagger2</artifactId>
24 <scope>compile</scope> 30 <scope>compile</scope>
1 -package com.crossoverjie.netty.action.common.constant; 1 +package com.crossoverjie.cim.common.constant;
2 2
3 /** 3 /**
4 * Function:常量 4 * Function:常量
@@ -22,4 +22,24 @@ public class Constants { @@ -22,4 +22,24 @@ public class Constants {
22 public static final String COUNTER_CLIENT_PUSH_COUNT = "counter.client.push.count" ; 22 public static final String COUNTER_CLIENT_PUSH_COUNT = "counter.client.push.count" ;
23 23
24 24
  25 + /**
  26 + * 自定义报文类型
  27 + */
  28 + public static class CommandType{
  29 + /**
  30 + * 登录
  31 + */
  32 + public static final int LOGIN = 1 ;
  33 + /**
  34 + * 业务消息
  35 + */
  36 + public static final int MSG = 2 ;
  37 +
  38 + /**
  39 + * ping
  40 + */
  41 + public static final int PING = 3 ;
  42 + }
  43 +
  44 +
25 } 45 }
1 -package com.crossoverjie.netty.action.common.enums; 1 +package com.crossoverjie.cim.common.enums;
2 2
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 import java.util.List; 4 import java.util.List;
@@ -14,8 +14,11 @@ public enum StatusEnum { @@ -14,8 +14,11 @@ public enum StatusEnum {
14 /** 失败 */ 14 /** 失败 */
15 FAIL("4000", "失败"), 15 FAIL("4000", "失败"),
16 16
17 - /** 重复请求 */  
18 - REPEAT_REQUEST("5000", "重复请求"), 17 + /** 重复登录 */
  18 + REPEAT_LOGIN("5000", "账号重复登录,请退出一个账号!"),
  19 +
  20 + /** 账号不在线 */
  21 + OFF_LINE("7000", "你选择的账号不在线,请重新选择!"),
19 22
20 /** 请求限流 */ 23 /** 请求限流 */
21 REQUEST_LIMIT("6000", "请求限流"), 24 REQUEST_LIMIT("6000", "请求限流"),
  1 +package com.crossoverjie.cim.common.enums;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.HashMap;
  5 +import java.util.List;
  6 +import java.util.Map;
  7 +
  8 +/**
  9 + * Function:
  10 + *
  11 + * @author crossoverJie
  12 + * Date: 2018/12/26 18:38
  13 + * @since JDK 1.8
  14 + */
  15 +public enum SystemCommandEnumType {
  16 +
  17 + ALL(":all ","获取所有命令"),
  18 + ONLINE_USER(":olu","获取所有在线用户"),
  19 + QUIT(":q ","退出程序")
  20 +
  21 + ;
  22 +
  23 + /** 枚举值码 */
  24 + private final String commandType;
  25 +
  26 + /** 枚举描述 */
  27 + private final String desc;
  28 +
  29 +
  30 + /**
  31 + * 构建一个 。
  32 + * @param commandType 枚举值码。
  33 + * @param desc 枚举描述。
  34 + */
  35 + private SystemCommandEnumType(String commandType, String desc) {
  36 + this.commandType = commandType;
  37 + this.desc = desc;
  38 + }
  39 +
  40 + /**
  41 + * 得到枚举值码。
  42 + * @return 枚举值码。
  43 + */
  44 + public String getCommandType() {
  45 + return commandType;
  46 + }
  47 +
  48 + /**
  49 + * 得到枚举描述。
  50 + * @return 枚举描述。
  51 + */
  52 + public String getDesc() {
  53 + return desc;
  54 + }
  55 +
  56 + /**
  57 + * 得到枚举值码。
  58 + * @return 枚举值码。
  59 + */
  60 + public String code() {
  61 + return commandType;
  62 + }
  63 +
  64 + /**
  65 + * 得到枚举描述。
  66 + * @return 枚举描述。
  67 + */
  68 + public String message() {
  69 + return desc;
  70 + }
  71 +
  72 + /**
  73 + * 获取全部枚举值码。
  74 + *
  75 + * @return 全部枚举值码。
  76 + */
  77 + public static Map<String,String> getAllStatusCode() {
  78 + List<String> list = new ArrayList<String>();
  79 + Map<String,String> map = new HashMap<String, String>(16) ;
  80 + for (SystemCommandEnumType status : values()) {
  81 + list.add(status.code());
  82 + map.put(status.getCommandType(),status.getDesc()) ;
  83 + }
  84 + return map;
  85 + }
  86 +
  87 +}
  1 +package com.crossoverjie.cim.common.exception;
  2 +
  3 +
  4 +import com.crossoverjie.cim.common.enums.StatusEnum;
  5 +
  6 +/**
  7 + * Function:
  8 + *
  9 + * @author crossoverJie
  10 + * Date: 2018/8/25 15:26
  11 + * @since JDK 1.8
  12 + */
  13 +public class CIMException extends GenericException {
  14 +
  15 +
  16 + public CIMException(String errorCode, String errorMessage) {
  17 + super(errorMessage);
  18 + this.errorCode = errorCode;
  19 + this.errorMessage = errorMessage;
  20 + }
  21 +
  22 + public CIMException(Exception e, String errorCode, String errorMessage) {
  23 + super(e, errorMessage);
  24 + this.errorCode = errorCode;
  25 + this.errorMessage = errorMessage;
  26 + }
  27 +
  28 + public CIMException(String message) {
  29 + super(message);
  30 + this.errorMessage = message;
  31 + }
  32 +
  33 + public CIMException(StatusEnum statusEnum) {
  34 + super(statusEnum.getMessage());
  35 + this.errorMessage = statusEnum.message();
  36 + this.errorCode = statusEnum.getCode();
  37 + }
  38 +
  39 + public CIMException(StatusEnum statusEnum, String message) {
  40 + super(message);
  41 + this.errorMessage = message;
  42 + this.errorCode = statusEnum.getCode();
  43 + }
  44 +
  45 + public CIMException(Exception oriEx) {
  46 + super(oriEx);
  47 + }
  48 +
  49 + public CIMException(Throwable oriEx) {
  50 + super(oriEx);
  51 + }
  52 +
  53 + public CIMException(String message, Exception oriEx) {
  54 + super(message, oriEx);
  55 + this.errorMessage = message;
  56 + }
  57 +
  58 + public CIMException(String message, Throwable oriEx) {
  59 + super(message, oriEx);
  60 + this.errorMessage = message;
  61 + }
  62 +
  63 +
  64 + public static boolean isResetByPeer(String msg) {
  65 + if ("Connection reset by peer".equals(msg)) {
  66 + return true;
  67 + }
  68 + return false;
  69 + }
  70 +
  71 +}
  1 +package com.crossoverjie.cim.common.exception;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +/**
  6 + * Function:
  7 + *
  8 + * @author crossoverJie
  9 + * Date: 2018/8/25 15:27
  10 + * @since JDK 1.8
  11 + */
  12 +public class GenericException extends RuntimeException implements Serializable {
  13 + private static final long serialVersionUID = 1L;
  14 + String errorCode;
  15 + String errorMessage;
  16 +
  17 + public GenericException() {
  18 + }
  19 +
  20 + public GenericException(String message) {
  21 + super(message);
  22 + }
  23 +
  24 + public GenericException(Exception oriEx) {
  25 + super(oriEx);
  26 + }
  27 +
  28 + public GenericException(Exception oriEx, String message) {
  29 + super(message, oriEx);
  30 + }
  31 +
  32 + public GenericException(Throwable oriEx) {
  33 + super(oriEx);
  34 + }
  35 +
  36 + public GenericException(String message, Exception oriEx) {
  37 + super(message, oriEx);
  38 + }
  39 +
  40 + public GenericException(String message, Throwable oriEx) {
  41 + super(message, oriEx);
  42 + }
  43 +
  44 + public String getErrorCode() {
  45 + return this.errorCode;
  46 + }
  47 +
  48 + public void setErrorCode(String errorCode) {
  49 + this.errorCode = errorCode;
  50 + }
  51 +
  52 + public String getErrorMessage() {
  53 + return this.errorMessage;
  54 + }
  55 +
  56 + public void setErrorMessage(String errorMessage) {
  57 + this.errorMessage = errorMessage;
  58 + }
  59 +}
  1 +package com.crossoverjie.cim.common.pojo;
  2 +
  3 +/**
  4 + * Function: 用户信息
  5 + *
  6 + * @author crossoverJie
  7 + * Date: 2018/12/24 02:33
  8 + * @since JDK 1.8
  9 + */
  10 +public class CIMUserInfo {
  11 + private Long userId ;
  12 + private String userName ;
  13 +
  14 + public CIMUserInfo(Long userId, String userName) {
  15 + this.userId = userId;
  16 + this.userName = userName;
  17 + }
  18 +
  19 + public Long getUserId() {
  20 + return userId;
  21 + }
  22 +
  23 + public void setUserId(Long userId) {
  24 + this.userId = userId;
  25 + }
  26 +
  27 + public String getUserName() {
  28 + return userName;
  29 + }
  30 +
  31 + public void setUserName(String userName) {
  32 + this.userName = userName;
  33 + }
  34 +
  35 + @Override
  36 + public String toString() {
  37 + return "CIMUserInfo{" +
  38 + "userId=" + userId +
  39 + ", userName='" + userName + '\'' +
  40 + '}';
  41 + }
  42 +}
1 // Generated by the protocol buffer compiler. DO NOT EDIT! 1 // Generated by the protocol buffer compiler. DO NOT EDIT!
2 // source: BaseRequestProto.proto 2 // source: BaseRequestProto.proto
3 3
4 -package com.crossoverjie.netty.action.common.protocol; 4 +package com.crossoverjie.cim.common.protocol;
5 5
6 -public final class BaseRequestProto {  
7 - private BaseRequestProto() {} 6 +public final class CIMRequestProto {
  7 + private CIMRequestProto() {}
8 public static void registerAllExtensions( 8 public static void registerAllExtensions(
9 com.google.protobuf.ExtensionRegistryLite registry) { 9 com.google.protobuf.ExtensionRegistryLite registry) {
10 } 10 }
@@ -14,18 +14,18 @@ public final class BaseRequestProto { @@ -14,18 +14,18 @@ public final class BaseRequestProto {
14 registerAllExtensions( 14 registerAllExtensions(
15 (com.google.protobuf.ExtensionRegistryLite) registry); 15 (com.google.protobuf.ExtensionRegistryLite) registry);
16 } 16 }
17 - public interface RequestProtocolOrBuilder extends  
18 - // @@protoc_insertion_point(interface_extends:protocol.RequestProtocol) 17 + public interface CIMReqProtocolOrBuilder extends
  18 + // @@protoc_insertion_point(interface_extends:protocol.CIMReqProtocol)
19 com.google.protobuf.MessageOrBuilder { 19 com.google.protobuf.MessageOrBuilder {
20 20
21 /** 21 /**
22 - * <code>required int32 requestId = 2;</code> 22 + * <code>required int64 requestId = 2;</code>
23 */ 23 */
24 boolean hasRequestId(); 24 boolean hasRequestId();
25 /** 25 /**
26 - * <code>required int32 requestId = 2;</code> 26 + * <code>required int64 requestId = 2;</code>
27 */ 27 */
28 - int getRequestId(); 28 + long getRequestId();
29 29
30 /** 30 /**
31 * <code>required string reqMsg = 1;</code> 31 * <code>required string reqMsg = 1;</code>
@@ -40,22 +40,32 @@ public final class BaseRequestProto { @@ -40,22 +40,32 @@ public final class BaseRequestProto {
40 */ 40 */
41 com.google.protobuf.ByteString 41 com.google.protobuf.ByteString
42 getReqMsgBytes(); 42 getReqMsgBytes();
  43 +
  44 + /**
  45 + * <code>required int32 type = 3;</code>
  46 + */
  47 + boolean hasType();
  48 + /**
  49 + * <code>required int32 type = 3;</code>
  50 + */
  51 + int getType();
43 } 52 }
44 /** 53 /**
45 - * Protobuf type {@code protocol.RequestProtocol} 54 + * Protobuf type {@code protocol.CIMReqProtocol}
46 */ 55 */
47 - public static final class RequestProtocol extends 56 + public static final class CIMReqProtocol extends
48 com.google.protobuf.GeneratedMessageV3 implements 57 com.google.protobuf.GeneratedMessageV3 implements
49 - // @@protoc_insertion_point(message_implements:protocol.RequestProtocol)  
50 - RequestProtocolOrBuilder { 58 + // @@protoc_insertion_point(message_implements:protocol.CIMReqProtocol)
  59 + CIMReqProtocolOrBuilder {
51 private static final long serialVersionUID = 0L; 60 private static final long serialVersionUID = 0L;
52 - // Use RequestProtocol.newBuilder() to construct.  
53 - private RequestProtocol(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) { 61 + // Use CIMReqProtocol.newBuilder() to construct.
  62 + private CIMReqProtocol(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
54 super(builder); 63 super(builder);
55 } 64 }
56 - private RequestProtocol() {  
57 - requestId_ = 0; 65 + private CIMReqProtocol() {
  66 + requestId_ = 0L;
58 reqMsg_ = ""; 67 reqMsg_ = "";
  68 + type_ = 0;
59 } 69 }
60 70
61 @Override 71 @Override
@@ -63,7 +73,7 @@ public final class BaseRequestProto { @@ -63,7 +73,7 @@ public final class BaseRequestProto {
63 getUnknownFields() { 73 getUnknownFields() {
64 return this.unknownFields; 74 return this.unknownFields;
65 } 75 }
66 - private RequestProtocol( 76 + private CIMReqProtocol(
67 com.google.protobuf.CodedInputStream input, 77 com.google.protobuf.CodedInputStream input,
68 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 78 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
69 throws com.google.protobuf.InvalidProtocolBufferException { 79 throws com.google.protobuf.InvalidProtocolBufferException {
@@ -97,7 +107,12 @@ public final class BaseRequestProto { @@ -97,7 +107,12 @@ public final class BaseRequestProto {
97 } 107 }
98 case 16: { 108 case 16: {
99 bitField0_ |= 0x00000001; 109 bitField0_ |= 0x00000001;
100 - requestId_ = input.readInt32(); 110 + requestId_ = input.readInt64();
  111 + break;
  112 + }
  113 + case 24: {
  114 + bitField0_ |= 0x00000004;
  115 + type_ = input.readInt32();
101 break; 116 break;
102 } 117 }
103 } 118 }
@@ -114,29 +129,29 @@ public final class BaseRequestProto { @@ -114,29 +129,29 @@ public final class BaseRequestProto {
114 } 129 }
115 public static final com.google.protobuf.Descriptors.Descriptor 130 public static final com.google.protobuf.Descriptors.Descriptor
116 getDescriptor() { 131 getDescriptor() {
117 - return BaseRequestProto.internal_static_protocol_RequestProtocol_descriptor; 132 + return CIMRequestProto.internal_static_protocol_CIMReqProtocol_descriptor;
118 } 133 }
119 134
120 protected FieldAccessorTable 135 protected FieldAccessorTable
121 internalGetFieldAccessorTable() { 136 internalGetFieldAccessorTable() {
122 - return BaseRequestProto.internal_static_protocol_RequestProtocol_fieldAccessorTable 137 + return CIMRequestProto.internal_static_protocol_CIMReqProtocol_fieldAccessorTable
123 .ensureFieldAccessorsInitialized( 138 .ensureFieldAccessorsInitialized(
124 - RequestProtocol.class, Builder.class); 139 + CIMReqProtocol.class, Builder.class);
125 } 140 }
126 141
127 private int bitField0_; 142 private int bitField0_;
128 public static final int REQUESTID_FIELD_NUMBER = 2; 143 public static final int REQUESTID_FIELD_NUMBER = 2;
129 - private int requestId_; 144 + private long requestId_;
130 /** 145 /**
131 - * <code>required int32 requestId = 2;</code> 146 + * <code>required int64 requestId = 2;</code>
132 */ 147 */
133 public boolean hasRequestId() { 148 public boolean hasRequestId() {
134 return ((bitField0_ & 0x00000001) == 0x00000001); 149 return ((bitField0_ & 0x00000001) == 0x00000001);
135 } 150 }
136 /** 151 /**
137 - * <code>required int32 requestId = 2;</code> 152 + * <code>required int64 requestId = 2;</code>
138 */ 153 */
139 - public int getRequestId() { 154 + public long getRequestId() {
140 return requestId_; 155 return requestId_;
141 } 156 }
142 157
@@ -182,6 +197,21 @@ public final class BaseRequestProto { @@ -182,6 +197,21 @@ public final class BaseRequestProto {
182 } 197 }
183 } 198 }
184 199
  200 + public static final int TYPE_FIELD_NUMBER = 3;
  201 + private int type_;
  202 + /**
  203 + * <code>required int32 type = 3;</code>
  204 + */
  205 + public boolean hasType() {
  206 + return ((bitField0_ & 0x00000004) == 0x00000004);
  207 + }
  208 + /**
  209 + * <code>required int32 type = 3;</code>
  210 + */
  211 + public int getType() {
  212 + return type_;
  213 + }
  214 +
185 private byte memoizedIsInitialized = -1; 215 private byte memoizedIsInitialized = -1;
186 public final boolean isInitialized() { 216 public final boolean isInitialized() {
187 byte isInitialized = memoizedIsInitialized; 217 byte isInitialized = memoizedIsInitialized;
@@ -196,6 +226,10 @@ public final class BaseRequestProto { @@ -196,6 +226,10 @@ public final class BaseRequestProto {
196 memoizedIsInitialized = 0; 226 memoizedIsInitialized = 0;
197 return false; 227 return false;
198 } 228 }
  229 + if (!hasType()) {
  230 + memoizedIsInitialized = 0;
  231 + return false;
  232 + }
199 memoizedIsInitialized = 1; 233 memoizedIsInitialized = 1;
200 return true; 234 return true;
201 } 235 }
@@ -206,7 +240,10 @@ public final class BaseRequestProto { @@ -206,7 +240,10 @@ public final class BaseRequestProto {
206 com.google.protobuf.GeneratedMessageV3.writeString(output, 1, reqMsg_); 240 com.google.protobuf.GeneratedMessageV3.writeString(output, 1, reqMsg_);
207 } 241 }
208 if (((bitField0_ & 0x00000001) == 0x00000001)) { 242 if (((bitField0_ & 0x00000001) == 0x00000001)) {
209 - output.writeInt32(2, requestId_); 243 + output.writeInt64(2, requestId_);
  244 + }
  245 + if (((bitField0_ & 0x00000004) == 0x00000004)) {
  246 + output.writeInt32(3, type_);
210 } 247 }
211 unknownFields.writeTo(output); 248 unknownFields.writeTo(output);
212 } 249 }
@@ -221,7 +258,11 @@ public final class BaseRequestProto { @@ -221,7 +258,11 @@ public final class BaseRequestProto {
221 } 258 }
222 if (((bitField0_ & 0x00000001) == 0x00000001)) { 259 if (((bitField0_ & 0x00000001) == 0x00000001)) {
223 size += com.google.protobuf.CodedOutputStream 260 size += com.google.protobuf.CodedOutputStream
224 - .computeInt32Size(2, requestId_); 261 + .computeInt64Size(2, requestId_);
  262 + }
  263 + if (((bitField0_ & 0x00000004) == 0x00000004)) {
  264 + size += com.google.protobuf.CodedOutputStream
  265 + .computeInt32Size(3, type_);
225 } 266 }
226 size += unknownFields.getSerializedSize(); 267 size += unknownFields.getSerializedSize();
227 memoizedSize = size; 268 memoizedSize = size;
@@ -233,10 +274,10 @@ public final class BaseRequestProto { @@ -233,10 +274,10 @@ public final class BaseRequestProto {
233 if (obj == this) { 274 if (obj == this) {
234 return true; 275 return true;
235 } 276 }
236 - if (!(obj instanceof RequestProtocol)) { 277 + if (!(obj instanceof CIMReqProtocol)) {
237 return super.equals(obj); 278 return super.equals(obj);
238 } 279 }
239 - RequestProtocol other = (RequestProtocol) obj; 280 + CIMReqProtocol other = (CIMReqProtocol) obj;
240 281
241 boolean result = true; 282 boolean result = true;
242 result = result && (hasRequestId() == other.hasRequestId()); 283 result = result && (hasRequestId() == other.hasRequestId());
@@ -249,6 +290,11 @@ public final class BaseRequestProto { @@ -249,6 +290,11 @@ public final class BaseRequestProto {
249 result = result && getReqMsg() 290 result = result && getReqMsg()
250 .equals(other.getReqMsg()); 291 .equals(other.getReqMsg());
251 } 292 }
  293 + result = result && (hasType() == other.hasType());
  294 + if (hasType()) {
  295 + result = result && (getType()
  296 + == other.getType());
  297 + }
252 result = result && unknownFields.equals(other.unknownFields); 298 result = result && unknownFields.equals(other.unknownFields);
253 return result; 299 return result;
254 } 300 }
@@ -262,80 +308,85 @@ public final class BaseRequestProto { @@ -262,80 +308,85 @@ public final class BaseRequestProto {
262 hash = (19 * hash) + getDescriptor().hashCode(); 308 hash = (19 * hash) + getDescriptor().hashCode();
263 if (hasRequestId()) { 309 if (hasRequestId()) {
264 hash = (37 * hash) + REQUESTID_FIELD_NUMBER; 310 hash = (37 * hash) + REQUESTID_FIELD_NUMBER;
265 - hash = (53 * hash) + getRequestId(); 311 + hash = (53 * hash) + com.google.protobuf.Internal.hashLong(
  312 + getRequestId());
266 } 313 }
267 if (hasReqMsg()) { 314 if (hasReqMsg()) {
268 hash = (37 * hash) + REQMSG_FIELD_NUMBER; 315 hash = (37 * hash) + REQMSG_FIELD_NUMBER;
269 hash = (53 * hash) + getReqMsg().hashCode(); 316 hash = (53 * hash) + getReqMsg().hashCode();
270 } 317 }
  318 + if (hasType()) {
  319 + hash = (37 * hash) + TYPE_FIELD_NUMBER;
  320 + hash = (53 * hash) + getType();
  321 + }
271 hash = (29 * hash) + unknownFields.hashCode(); 322 hash = (29 * hash) + unknownFields.hashCode();
272 memoizedHashCode = hash; 323 memoizedHashCode = hash;
273 return hash; 324 return hash;
274 } 325 }
275 326
276 - public static RequestProtocol parseFrom( 327 + public static CIMReqProtocol parseFrom(
277 java.nio.ByteBuffer data) 328 java.nio.ByteBuffer data)
278 throws com.google.protobuf.InvalidProtocolBufferException { 329 throws com.google.protobuf.InvalidProtocolBufferException {
279 return PARSER.parseFrom(data); 330 return PARSER.parseFrom(data);
280 } 331 }
281 - public static RequestProtocol parseFrom( 332 + public static CIMReqProtocol parseFrom(
282 java.nio.ByteBuffer data, 333 java.nio.ByteBuffer data,
283 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 334 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
284 throws com.google.protobuf.InvalidProtocolBufferException { 335 throws com.google.protobuf.InvalidProtocolBufferException {
285 return PARSER.parseFrom(data, extensionRegistry); 336 return PARSER.parseFrom(data, extensionRegistry);
286 } 337 }
287 - public static RequestProtocol parseFrom( 338 + public static CIMReqProtocol parseFrom(
288 com.google.protobuf.ByteString data) 339 com.google.protobuf.ByteString data)
289 throws com.google.protobuf.InvalidProtocolBufferException { 340 throws com.google.protobuf.InvalidProtocolBufferException {
290 return PARSER.parseFrom(data); 341 return PARSER.parseFrom(data);
291 } 342 }
292 - public static RequestProtocol parseFrom( 343 + public static CIMReqProtocol parseFrom(
293 com.google.protobuf.ByteString data, 344 com.google.protobuf.ByteString data,
294 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 345 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
295 throws com.google.protobuf.InvalidProtocolBufferException { 346 throws com.google.protobuf.InvalidProtocolBufferException {
296 return PARSER.parseFrom(data, extensionRegistry); 347 return PARSER.parseFrom(data, extensionRegistry);
297 } 348 }
298 - public static RequestProtocol parseFrom(byte[] data) 349 + public static CIMReqProtocol parseFrom(byte[] data)
299 throws com.google.protobuf.InvalidProtocolBufferException { 350 throws com.google.protobuf.InvalidProtocolBufferException {
300 return PARSER.parseFrom(data); 351 return PARSER.parseFrom(data);
301 } 352 }
302 - public static RequestProtocol parseFrom( 353 + public static CIMReqProtocol parseFrom(
303 byte[] data, 354 byte[] data,
304 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 355 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
305 throws com.google.protobuf.InvalidProtocolBufferException { 356 throws com.google.protobuf.InvalidProtocolBufferException {
306 return PARSER.parseFrom(data, extensionRegistry); 357 return PARSER.parseFrom(data, extensionRegistry);
307 } 358 }
308 - public static RequestProtocol parseFrom(java.io.InputStream input) 359 + public static CIMReqProtocol parseFrom(java.io.InputStream input)
309 throws java.io.IOException { 360 throws java.io.IOException {
310 return com.google.protobuf.GeneratedMessageV3 361 return com.google.protobuf.GeneratedMessageV3
311 .parseWithIOException(PARSER, input); 362 .parseWithIOException(PARSER, input);
312 } 363 }
313 - public static RequestProtocol parseFrom( 364 + public static CIMReqProtocol parseFrom(
314 java.io.InputStream input, 365 java.io.InputStream input,
315 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 366 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
316 throws java.io.IOException { 367 throws java.io.IOException {
317 return com.google.protobuf.GeneratedMessageV3 368 return com.google.protobuf.GeneratedMessageV3
318 .parseWithIOException(PARSER, input, extensionRegistry); 369 .parseWithIOException(PARSER, input, extensionRegistry);
319 } 370 }
320 - public static RequestProtocol parseDelimitedFrom(java.io.InputStream input) 371 + public static CIMReqProtocol parseDelimitedFrom(java.io.InputStream input)
321 throws java.io.IOException { 372 throws java.io.IOException {
322 return com.google.protobuf.GeneratedMessageV3 373 return com.google.protobuf.GeneratedMessageV3
323 .parseDelimitedWithIOException(PARSER, input); 374 .parseDelimitedWithIOException(PARSER, input);
324 } 375 }
325 - public static RequestProtocol parseDelimitedFrom( 376 + public static CIMReqProtocol parseDelimitedFrom(
326 java.io.InputStream input, 377 java.io.InputStream input,
327 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 378 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
328 throws java.io.IOException { 379 throws java.io.IOException {
329 return com.google.protobuf.GeneratedMessageV3 380 return com.google.protobuf.GeneratedMessageV3
330 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); 381 .parseDelimitedWithIOException(PARSER, input, extensionRegistry);
331 } 382 }
332 - public static RequestProtocol parseFrom( 383 + public static CIMReqProtocol parseFrom(
333 com.google.protobuf.CodedInputStream input) 384 com.google.protobuf.CodedInputStream input)
334 throws java.io.IOException { 385 throws java.io.IOException {
335 return com.google.protobuf.GeneratedMessageV3 386 return com.google.protobuf.GeneratedMessageV3
336 .parseWithIOException(PARSER, input); 387 .parseWithIOException(PARSER, input);
337 } 388 }
338 - public static RequestProtocol parseFrom( 389 + public static CIMReqProtocol parseFrom(
339 com.google.protobuf.CodedInputStream input, 390 com.google.protobuf.CodedInputStream input,
340 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 391 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
341 throws java.io.IOException { 392 throws java.io.IOException {
@@ -347,7 +398,7 @@ public final class BaseRequestProto { @@ -347,7 +398,7 @@ public final class BaseRequestProto {
347 public static Builder newBuilder() { 398 public static Builder newBuilder() {
348 return DEFAULT_INSTANCE.toBuilder(); 399 return DEFAULT_INSTANCE.toBuilder();
349 } 400 }
350 - public static Builder newBuilder(RequestProtocol prototype) { 401 + public static Builder newBuilder(CIMReqProtocol prototype) {
351 return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); 402 return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
352 } 403 }
353 public Builder toBuilder() { 404 public Builder toBuilder() {
@@ -362,25 +413,25 @@ public final class BaseRequestProto { @@ -362,25 +413,25 @@ public final class BaseRequestProto {
362 return builder; 413 return builder;
363 } 414 }
364 /** 415 /**
365 - * Protobuf type {@code protocol.RequestProtocol} 416 + * Protobuf type {@code protocol.CIMReqProtocol}
366 */ 417 */
367 public static final class Builder extends 418 public static final class Builder extends
368 com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements 419 com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
369 - // @@protoc_insertion_point(builder_implements:protocol.RequestProtocol)  
370 - RequestProtocolOrBuilder { 420 + // @@protoc_insertion_point(builder_implements:protocol.CIMReqProtocol)
  421 + CIMReqProtocolOrBuilder {
371 public static final com.google.protobuf.Descriptors.Descriptor 422 public static final com.google.protobuf.Descriptors.Descriptor
372 getDescriptor() { 423 getDescriptor() {
373 - return BaseRequestProto.internal_static_protocol_RequestProtocol_descriptor; 424 + return CIMRequestProto.internal_static_protocol_CIMReqProtocol_descriptor;
374 } 425 }
375 426
376 protected FieldAccessorTable 427 protected FieldAccessorTable
377 internalGetFieldAccessorTable() { 428 internalGetFieldAccessorTable() {
378 - return BaseRequestProto.internal_static_protocol_RequestProtocol_fieldAccessorTable 429 + return CIMRequestProto.internal_static_protocol_CIMReqProtocol_fieldAccessorTable
379 .ensureFieldAccessorsInitialized( 430 .ensureFieldAccessorsInitialized(
380 - RequestProtocol.class, Builder.class); 431 + CIMReqProtocol.class, Builder.class);
381 } 432 }
382 433
383 - // Construct using com.crossoverjie.netty.action.protocol.BaseRequestProto.RequestProtocol.newBuilder() 434 + // Construct using com.crossoverjie.cim.common.protocol.CIMRequestProto.CIMReqProtocol.newBuilder()
384 private Builder() { 435 private Builder() {
385 maybeForceBuilderInitialization(); 436 maybeForceBuilderInitialization();
386 } 437 }
@@ -397,32 +448,34 @@ public final class BaseRequestProto { @@ -397,32 +448,34 @@ public final class BaseRequestProto {
397 } 448 }
398 public Builder clear() { 449 public Builder clear() {
399 super.clear(); 450 super.clear();
400 - requestId_ = 0; 451 + requestId_ = 0L;
401 bitField0_ = (bitField0_ & ~0x00000001); 452 bitField0_ = (bitField0_ & ~0x00000001);
402 reqMsg_ = ""; 453 reqMsg_ = "";
403 bitField0_ = (bitField0_ & ~0x00000002); 454 bitField0_ = (bitField0_ & ~0x00000002);
  455 + type_ = 0;
  456 + bitField0_ = (bitField0_ & ~0x00000004);
404 return this; 457 return this;
405 } 458 }
406 459
407 public com.google.protobuf.Descriptors.Descriptor 460 public com.google.protobuf.Descriptors.Descriptor
408 getDescriptorForType() { 461 getDescriptorForType() {
409 - return BaseRequestProto.internal_static_protocol_RequestProtocol_descriptor; 462 + return CIMRequestProto.internal_static_protocol_CIMReqProtocol_descriptor;
410 } 463 }
411 464
412 - public RequestProtocol getDefaultInstanceForType() {  
413 - return RequestProtocol.getDefaultInstance(); 465 + public CIMReqProtocol getDefaultInstanceForType() {
  466 + return CIMReqProtocol.getDefaultInstance();
414 } 467 }
415 468
416 - public RequestProtocol build() {  
417 - RequestProtocol result = buildPartial(); 469 + public CIMReqProtocol build() {
  470 + CIMReqProtocol result = buildPartial();
418 if (!result.isInitialized()) { 471 if (!result.isInitialized()) {
419 throw newUninitializedMessageException(result); 472 throw newUninitializedMessageException(result);
420 } 473 }
421 return result; 474 return result;
422 } 475 }
423 476
424 - public RequestProtocol buildPartial() {  
425 - RequestProtocol result = new RequestProtocol(this); 477 + public CIMReqProtocol buildPartial() {
  478 + CIMReqProtocol result = new CIMReqProtocol(this);
426 int from_bitField0_ = bitField0_; 479 int from_bitField0_ = bitField0_;
427 int to_bitField0_ = 0; 480 int to_bitField0_ = 0;
428 if (((from_bitField0_ & 0x00000001) == 0x00000001)) { 481 if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
@@ -433,6 +486,10 @@ public final class BaseRequestProto { @@ -433,6 +486,10 @@ public final class BaseRequestProto {
433 to_bitField0_ |= 0x00000002; 486 to_bitField0_ |= 0x00000002;
434 } 487 }
435 result.reqMsg_ = reqMsg_; 488 result.reqMsg_ = reqMsg_;
  489 + if (((from_bitField0_ & 0x00000004) == 0x00000004)) {
  490 + to_bitField0_ |= 0x00000004;
  491 + }
  492 + result.type_ = type_;
436 result.bitField0_ = to_bitField0_; 493 result.bitField0_ = to_bitField0_;
437 onBuilt(); 494 onBuilt();
438 return result; 495 return result;
@@ -465,16 +522,16 @@ public final class BaseRequestProto { @@ -465,16 +522,16 @@ public final class BaseRequestProto {
465 return (Builder) super.addRepeatedField(field, value); 522 return (Builder) super.addRepeatedField(field, value);
466 } 523 }
467 public Builder mergeFrom(com.google.protobuf.Message other) { 524 public Builder mergeFrom(com.google.protobuf.Message other) {
468 - if (other instanceof RequestProtocol) {  
469 - return mergeFrom((RequestProtocol)other); 525 + if (other instanceof CIMReqProtocol) {
  526 + return mergeFrom((CIMReqProtocol)other);
470 } else { 527 } else {
471 super.mergeFrom(other); 528 super.mergeFrom(other);
472 return this; 529 return this;
473 } 530 }
474 } 531 }
475 532
476 - public Builder mergeFrom(RequestProtocol other) {  
477 - if (other == RequestProtocol.getDefaultInstance()) return this; 533 + public Builder mergeFrom(CIMReqProtocol other) {
  534 + if (other == CIMReqProtocol.getDefaultInstance()) return this;
478 if (other.hasRequestId()) { 535 if (other.hasRequestId()) {
479 setRequestId(other.getRequestId()); 536 setRequestId(other.getRequestId());
480 } 537 }
@@ -483,6 +540,9 @@ public final class BaseRequestProto { @@ -483,6 +540,9 @@ public final class BaseRequestProto {
483 reqMsg_ = other.reqMsg_; 540 reqMsg_ = other.reqMsg_;
484 onChanged(); 541 onChanged();
485 } 542 }
  543 + if (other.hasType()) {
  544 + setType(other.getType());
  545 + }
486 this.mergeUnknownFields(other.unknownFields); 546 this.mergeUnknownFields(other.unknownFields);
487 onChanged(); 547 onChanged();
488 return this; 548 return this;
@@ -495,6 +555,9 @@ public final class BaseRequestProto { @@ -495,6 +555,9 @@ public final class BaseRequestProto {
495 if (!hasReqMsg()) { 555 if (!hasReqMsg()) {
496 return false; 556 return false;
497 } 557 }
  558 + if (!hasType()) {
  559 + return false;
  560 + }
498 return true; 561 return true;
499 } 562 }
500 563
@@ -502,11 +565,11 @@ public final class BaseRequestProto { @@ -502,11 +565,11 @@ public final class BaseRequestProto {
502 com.google.protobuf.CodedInputStream input, 565 com.google.protobuf.CodedInputStream input,
503 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 566 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
504 throws java.io.IOException { 567 throws java.io.IOException {
505 - RequestProtocol parsedMessage = null; 568 + CIMReqProtocol parsedMessage = null;
506 try { 569 try {
507 parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); 570 parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
508 } catch (com.google.protobuf.InvalidProtocolBufferException e) { 571 } catch (com.google.protobuf.InvalidProtocolBufferException e) {
509 - parsedMessage = (RequestProtocol) e.getUnfinishedMessage(); 572 + parsedMessage = (CIMReqProtocol) e.getUnfinishedMessage();
510 throw e.unwrapIOException(); 573 throw e.unwrapIOException();
511 } finally { 574 } finally {
512 if (parsedMessage != null) { 575 if (parsedMessage != null) {
@@ -517,34 +580,34 @@ public final class BaseRequestProto { @@ -517,34 +580,34 @@ public final class BaseRequestProto {
517 } 580 }
518 private int bitField0_; 581 private int bitField0_;
519 582
520 - private int requestId_ ; 583 + private long requestId_ ;
521 /** 584 /**
522 - * <code>required int32 requestId = 2;</code> 585 + * <code>required int64 requestId = 2;</code>
523 */ 586 */
524 public boolean hasRequestId() { 587 public boolean hasRequestId() {
525 return ((bitField0_ & 0x00000001) == 0x00000001); 588 return ((bitField0_ & 0x00000001) == 0x00000001);
526 } 589 }
527 /** 590 /**
528 - * <code>required int32 requestId = 2;</code> 591 + * <code>required int64 requestId = 2;</code>
529 */ 592 */
530 - public int getRequestId() { 593 + public long getRequestId() {
531 return requestId_; 594 return requestId_;
532 } 595 }
533 /** 596 /**
534 - * <code>required int32 requestId = 2;</code> 597 + * <code>required int64 requestId = 2;</code>
535 */ 598 */
536 - public Builder setRequestId(int value) { 599 + public Builder setRequestId(long value) {
537 bitField0_ |= 0x00000001; 600 bitField0_ |= 0x00000001;
538 requestId_ = value; 601 requestId_ = value;
539 onChanged(); 602 onChanged();
540 return this; 603 return this;
541 } 604 }
542 /** 605 /**
543 - * <code>required int32 requestId = 2;</code> 606 + * <code>required int64 requestId = 2;</code>
544 */ 607 */
545 public Builder clearRequestId() { 608 public Builder clearRequestId() {
546 bitField0_ = (bitField0_ & ~0x00000001); 609 bitField0_ = (bitField0_ & ~0x00000001);
547 - requestId_ = 0; 610 + requestId_ = 0L;
548 onChanged(); 611 onChanged();
549 return this; 612 return this;
550 } 613 }
@@ -624,6 +687,38 @@ public final class BaseRequestProto { @@ -624,6 +687,38 @@ public final class BaseRequestProto {
624 onChanged(); 687 onChanged();
625 return this; 688 return this;
626 } 689 }
  690 +
  691 + private int type_ ;
  692 + /**
  693 + * <code>required int32 type = 3;</code>
  694 + */
  695 + public boolean hasType() {
  696 + return ((bitField0_ & 0x00000004) == 0x00000004);
  697 + }
  698 + /**
  699 + * <code>required int32 type = 3;</code>
  700 + */
  701 + public int getType() {
  702 + return type_;
  703 + }
  704 + /**
  705 + * <code>required int32 type = 3;</code>
  706 + */
  707 + public Builder setType(int value) {
  708 + bitField0_ |= 0x00000004;
  709 + type_ = value;
  710 + onChanged();
  711 + return this;
  712 + }
  713 + /**
  714 + * <code>required int32 type = 3;</code>
  715 + */
  716 + public Builder clearType() {
  717 + bitField0_ = (bitField0_ & ~0x00000004);
  718 + type_ = 0;
  719 + onChanged();
  720 + return this;
  721 + }
627 public final Builder setUnknownFields( 722 public final Builder setUnknownFields(
628 final com.google.protobuf.UnknownFieldSet unknownFields) { 723 final com.google.protobuf.UnknownFieldSet unknownFields) {
629 return super.setUnknownFields(unknownFields); 724 return super.setUnknownFields(unknownFields);
@@ -635,49 +730,49 @@ public final class BaseRequestProto { @@ -635,49 +730,49 @@ public final class BaseRequestProto {
635 } 730 }
636 731
637 732
638 - // @@protoc_insertion_point(builder_scope:protocol.RequestProtocol) 733 + // @@protoc_insertion_point(builder_scope:protocol.CIMReqProtocol)
639 } 734 }
640 735
641 - // @@protoc_insertion_point(class_scope:protocol.RequestProtocol)  
642 - private static final RequestProtocol DEFAULT_INSTANCE; 736 + // @@protoc_insertion_point(class_scope:protocol.CIMReqProtocol)
  737 + private static final CIMReqProtocol DEFAULT_INSTANCE;
643 static { 738 static {
644 - DEFAULT_INSTANCE = new RequestProtocol(); 739 + DEFAULT_INSTANCE = new CIMReqProtocol();
645 } 740 }
646 741
647 - public static RequestProtocol getDefaultInstance() { 742 + public static CIMReqProtocol getDefaultInstance() {
648 return DEFAULT_INSTANCE; 743 return DEFAULT_INSTANCE;
649 } 744 }
650 745
651 - @Deprecated public static final com.google.protobuf.Parser<RequestProtocol>  
652 - PARSER = new com.google.protobuf.AbstractParser<RequestProtocol>() {  
653 - public RequestProtocol parsePartialFrom( 746 + @Deprecated public static final com.google.protobuf.Parser<CIMReqProtocol>
  747 + PARSER = new com.google.protobuf.AbstractParser<CIMReqProtocol>() {
  748 + public CIMReqProtocol parsePartialFrom(
654 com.google.protobuf.CodedInputStream input, 749 com.google.protobuf.CodedInputStream input,
655 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 750 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
656 throws com.google.protobuf.InvalidProtocolBufferException { 751 throws com.google.protobuf.InvalidProtocolBufferException {
657 - return new RequestProtocol(input, extensionRegistry); 752 + return new CIMReqProtocol(input, extensionRegistry);
658 } 753 }
659 }; 754 };
660 755
661 - public static com.google.protobuf.Parser<RequestProtocol> parser() { 756 + public static com.google.protobuf.Parser<CIMReqProtocol> parser() {
662 return PARSER; 757 return PARSER;
663 } 758 }
664 759
665 @Override 760 @Override
666 - public com.google.protobuf.Parser<RequestProtocol> getParserForType() { 761 + public com.google.protobuf.Parser<CIMReqProtocol> getParserForType() {
667 return PARSER; 762 return PARSER;
668 } 763 }
669 764
670 - public RequestProtocol getDefaultInstanceForType() { 765 + public CIMReqProtocol getDefaultInstanceForType() {
671 return DEFAULT_INSTANCE; 766 return DEFAULT_INSTANCE;
672 } 767 }
673 768
674 } 769 }
675 770
676 private static final com.google.protobuf.Descriptors.Descriptor 771 private static final com.google.protobuf.Descriptors.Descriptor
677 - internal_static_protocol_RequestProtocol_descriptor; 772 + internal_static_protocol_CIMReqProtocol_descriptor;
678 private static final 773 private static final
679 com.google.protobuf.GeneratedMessageV3.FieldAccessorTable 774 com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
680 - internal_static_protocol_RequestProtocol_fieldAccessorTable; 775 + internal_static_protocol_CIMReqProtocol_fieldAccessorTable;
681 776
682 public static com.google.protobuf.Descriptors.FileDescriptor 777 public static com.google.protobuf.Descriptors.FileDescriptor
683 getDescriptor() { 778 getDescriptor() {
@@ -687,10 +782,10 @@ public final class BaseRequestProto { @@ -687,10 +782,10 @@ public final class BaseRequestProto {
687 descriptor; 782 descriptor;
688 static { 783 static {
689 String[] descriptorData = { 784 String[] descriptorData = {
690 - "\n\026BaseRequestProto.proto\022\010protocol\"4\n\017Re" +  
691 - "questProtocol\022\021\n\trequestId\030\002 \002(\005\022\016\n\006reqM" +  
692 - "sg\030\001 \002(\tB:\n&com.crossoverjie.netty.actio" +  
693 - "n.protocolB\020BaseRequestProto" 785 + "\n\026BaseRequestProto.proto\022\010protocol\"A\n\016CI" +
  786 + "MReqProtocol\022\021\n\trequestId\030\002 \002(\003\022\016\n\006reqMs" +
  787 + "g\030\001 \002(\t\022\014\n\004type\030\003 \002(\005B7\n$com.crossoverji" +
  788 + "e.cim.common.protocolB\017CIMRequestProto"
694 }; 789 };
695 com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = 790 com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
696 new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { 791 new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
@@ -704,12 +799,12 @@ public final class BaseRequestProto { @@ -704,12 +799,12 @@ public final class BaseRequestProto {
704 .internalBuildGeneratedFileFrom(descriptorData, 799 .internalBuildGeneratedFileFrom(descriptorData,
705 new com.google.protobuf.Descriptors.FileDescriptor[] { 800 new com.google.protobuf.Descriptors.FileDescriptor[] {
706 }, assigner); 801 }, assigner);
707 - internal_static_protocol_RequestProtocol_descriptor = 802 + internal_static_protocol_CIMReqProtocol_descriptor =
708 getDescriptor().getMessageTypes().get(0); 803 getDescriptor().getMessageTypes().get(0);
709 - internal_static_protocol_RequestProtocol_fieldAccessorTable = new 804 + internal_static_protocol_CIMReqProtocol_fieldAccessorTable = new
710 com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( 805 com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
711 - internal_static_protocol_RequestProtocol_descriptor,  
712 - new String[] { "RequestId", "ReqMsg", }); 806 + internal_static_protocol_CIMReqProtocol_descriptor,
  807 + new String[] { "RequestId", "ReqMsg", "Type", });
713 } 808 }
714 809
715 // @@protoc_insertion_point(outer_class_scope) 810 // @@protoc_insertion_point(outer_class_scope)
1 // Generated by the protocol buffer compiler. DO NOT EDIT! 1 // Generated by the protocol buffer compiler. DO NOT EDIT!
2 // source: BaseResponseProto.proto 2 // source: BaseResponseProto.proto
3 3
4 -package com.crossoverjie.netty.action.common.protocol; 4 +package com.crossoverjie.cim.common.protocol;
5 5
6 -public final class BaseResponseProto {  
7 - private BaseResponseProto() {} 6 +public final class CIMResponseProto {
  7 + private CIMResponseProto() {}
8 public static void registerAllExtensions( 8 public static void registerAllExtensions(
9 com.google.protobuf.ExtensionRegistryLite registry) { 9 com.google.protobuf.ExtensionRegistryLite registry) {
10 } 10 }
@@ -14,18 +14,18 @@ public final class BaseResponseProto { @@ -14,18 +14,18 @@ public final class BaseResponseProto {
14 registerAllExtensions( 14 registerAllExtensions(
15 (com.google.protobuf.ExtensionRegistryLite) registry); 15 (com.google.protobuf.ExtensionRegistryLite) registry);
16 } 16 }
17 - public interface ResponseProtocolOrBuilder extends  
18 - // @@protoc_insertion_point(interface_extends:protocol.ResponseProtocol) 17 + public interface CIMResProtocolOrBuilder extends
  18 + // @@protoc_insertion_point(interface_extends:protocol.CIMResProtocol)
19 com.google.protobuf.MessageOrBuilder { 19 com.google.protobuf.MessageOrBuilder {
20 20
21 /** 21 /**
22 - * <code>required int32 responseId = 2;</code> 22 + * <code>required int64 responseId = 2;</code>
23 */ 23 */
24 boolean hasResponseId(); 24 boolean hasResponseId();
25 /** 25 /**
26 - * <code>required int32 responseId = 2;</code> 26 + * <code>required int64 responseId = 2;</code>
27 */ 27 */
28 - int getResponseId(); 28 + long getResponseId();
29 29
30 /** 30 /**
31 * <code>required string resMsg = 1;</code> 31 * <code>required string resMsg = 1;</code>
@@ -42,19 +42,19 @@ public final class BaseResponseProto { @@ -42,19 +42,19 @@ public final class BaseResponseProto {
42 getResMsgBytes(); 42 getResMsgBytes();
43 } 43 }
44 /** 44 /**
45 - * Protobuf type {@code protocol.ResponseProtocol} 45 + * Protobuf type {@code protocol.CIMResProtocol}
46 */ 46 */
47 - public static final class ResponseProtocol extends 47 + public static final class CIMResProtocol extends
48 com.google.protobuf.GeneratedMessageV3 implements 48 com.google.protobuf.GeneratedMessageV3 implements
49 - // @@protoc_insertion_point(message_implements:protocol.ResponseProtocol)  
50 - ResponseProtocolOrBuilder { 49 + // @@protoc_insertion_point(message_implements:protocol.CIMResProtocol)
  50 + CIMResProtocolOrBuilder {
51 private static final long serialVersionUID = 0L; 51 private static final long serialVersionUID = 0L;
52 - // Use ResponseProtocol.newBuilder() to construct.  
53 - private ResponseProtocol(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) { 52 + // Use CIMResProtocol.newBuilder() to construct.
  53 + private CIMResProtocol(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
54 super(builder); 54 super(builder);
55 } 55 }
56 - private ResponseProtocol() {  
57 - responseId_ = 0; 56 + private CIMResProtocol() {
  57 + responseId_ = 0L;
58 resMsg_ = ""; 58 resMsg_ = "";
59 } 59 }
60 60
@@ -63,7 +63,7 @@ public final class BaseResponseProto { @@ -63,7 +63,7 @@ public final class BaseResponseProto {
63 getUnknownFields() { 63 getUnknownFields() {
64 return this.unknownFields; 64 return this.unknownFields;
65 } 65 }
66 - private ResponseProtocol( 66 + private CIMResProtocol(
67 com.google.protobuf.CodedInputStream input, 67 com.google.protobuf.CodedInputStream input,
68 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 68 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
69 throws com.google.protobuf.InvalidProtocolBufferException { 69 throws com.google.protobuf.InvalidProtocolBufferException {
@@ -97,7 +97,7 @@ public final class BaseResponseProto { @@ -97,7 +97,7 @@ public final class BaseResponseProto {
97 } 97 }
98 case 16: { 98 case 16: {
99 bitField0_ |= 0x00000001; 99 bitField0_ |= 0x00000001;
100 - responseId_ = input.readInt32(); 100 + responseId_ = input.readInt64();
101 break; 101 break;
102 } 102 }
103 } 103 }
@@ -114,29 +114,29 @@ public final class BaseResponseProto { @@ -114,29 +114,29 @@ public final class BaseResponseProto {
114 } 114 }
115 public static final com.google.protobuf.Descriptors.Descriptor 115 public static final com.google.protobuf.Descriptors.Descriptor
116 getDescriptor() { 116 getDescriptor() {
117 - return BaseResponseProto.internal_static_protocol_ResponseProtocol_descriptor; 117 + return CIMResponseProto.internal_static_protocol_CIMResProtocol_descriptor;
118 } 118 }
119 119
120 protected FieldAccessorTable 120 protected FieldAccessorTable
121 internalGetFieldAccessorTable() { 121 internalGetFieldAccessorTable() {
122 - return BaseResponseProto.internal_static_protocol_ResponseProtocol_fieldAccessorTable 122 + return CIMResponseProto.internal_static_protocol_CIMResProtocol_fieldAccessorTable
123 .ensureFieldAccessorsInitialized( 123 .ensureFieldAccessorsInitialized(
124 - ResponseProtocol.class, Builder.class); 124 + CIMResProtocol.class, Builder.class);
125 } 125 }
126 126
127 private int bitField0_; 127 private int bitField0_;
128 public static final int RESPONSEID_FIELD_NUMBER = 2; 128 public static final int RESPONSEID_FIELD_NUMBER = 2;
129 - private int responseId_; 129 + private long responseId_;
130 /** 130 /**
131 - * <code>required int32 responseId = 2;</code> 131 + * <code>required int64 responseId = 2;</code>
132 */ 132 */
133 public boolean hasResponseId() { 133 public boolean hasResponseId() {
134 return ((bitField0_ & 0x00000001) == 0x00000001); 134 return ((bitField0_ & 0x00000001) == 0x00000001);
135 } 135 }
136 /** 136 /**
137 - * <code>required int32 responseId = 2;</code> 137 + * <code>required int64 responseId = 2;</code>
138 */ 138 */
139 - public int getResponseId() { 139 + public long getResponseId() {
140 return responseId_; 140 return responseId_;
141 } 141 }
142 142
@@ -206,7 +206,7 @@ public final class BaseResponseProto { @@ -206,7 +206,7 @@ public final class BaseResponseProto {
206 com.google.protobuf.GeneratedMessageV3.writeString(output, 1, resMsg_); 206 com.google.protobuf.GeneratedMessageV3.writeString(output, 1, resMsg_);
207 } 207 }
208 if (((bitField0_ & 0x00000001) == 0x00000001)) { 208 if (((bitField0_ & 0x00000001) == 0x00000001)) {
209 - output.writeInt32(2, responseId_); 209 + output.writeInt64(2, responseId_);
210 } 210 }
211 unknownFields.writeTo(output); 211 unknownFields.writeTo(output);
212 } 212 }
@@ -221,7 +221,7 @@ public final class BaseResponseProto { @@ -221,7 +221,7 @@ public final class BaseResponseProto {
221 } 221 }
222 if (((bitField0_ & 0x00000001) == 0x00000001)) { 222 if (((bitField0_ & 0x00000001) == 0x00000001)) {
223 size += com.google.protobuf.CodedOutputStream 223 size += com.google.protobuf.CodedOutputStream
224 - .computeInt32Size(2, responseId_); 224 + .computeInt64Size(2, responseId_);
225 } 225 }
226 size += unknownFields.getSerializedSize(); 226 size += unknownFields.getSerializedSize();
227 memoizedSize = size; 227 memoizedSize = size;
@@ -233,10 +233,10 @@ public final class BaseResponseProto { @@ -233,10 +233,10 @@ public final class BaseResponseProto {
233 if (obj == this) { 233 if (obj == this) {
234 return true; 234 return true;
235 } 235 }
236 - if (!(obj instanceof ResponseProtocol)) { 236 + if (!(obj instanceof CIMResProtocol)) {
237 return super.equals(obj); 237 return super.equals(obj);
238 } 238 }
239 - ResponseProtocol other = (ResponseProtocol) obj; 239 + CIMResProtocol other = (CIMResProtocol) obj;
240 240
241 boolean result = true; 241 boolean result = true;
242 result = result && (hasResponseId() == other.hasResponseId()); 242 result = result && (hasResponseId() == other.hasResponseId());
@@ -262,7 +262,8 @@ public final class BaseResponseProto { @@ -262,7 +262,8 @@ public final class BaseResponseProto {
262 hash = (19 * hash) + getDescriptor().hashCode(); 262 hash = (19 * hash) + getDescriptor().hashCode();
263 if (hasResponseId()) { 263 if (hasResponseId()) {
264 hash = (37 * hash) + RESPONSEID_FIELD_NUMBER; 264 hash = (37 * hash) + RESPONSEID_FIELD_NUMBER;
265 - hash = (53 * hash) + getResponseId(); 265 + hash = (53 * hash) + com.google.protobuf.Internal.hashLong(
  266 + getResponseId());
266 } 267 }
267 if (hasResMsg()) { 268 if (hasResMsg()) {
268 hash = (37 * hash) + RESMSG_FIELD_NUMBER; 269 hash = (37 * hash) + RESMSG_FIELD_NUMBER;
@@ -273,69 +274,69 @@ public final class BaseResponseProto { @@ -273,69 +274,69 @@ public final class BaseResponseProto {
273 return hash; 274 return hash;
274 } 275 }
275 276
276 - public static ResponseProtocol parseFrom( 277 + public static CIMResProtocol parseFrom(
277 java.nio.ByteBuffer data) 278 java.nio.ByteBuffer data)
278 throws com.google.protobuf.InvalidProtocolBufferException { 279 throws com.google.protobuf.InvalidProtocolBufferException {
279 return PARSER.parseFrom(data); 280 return PARSER.parseFrom(data);
280 } 281 }
281 - public static ResponseProtocol parseFrom( 282 + public static CIMResProtocol parseFrom(
282 java.nio.ByteBuffer data, 283 java.nio.ByteBuffer data,
283 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 284 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
284 throws com.google.protobuf.InvalidProtocolBufferException { 285 throws com.google.protobuf.InvalidProtocolBufferException {
285 return PARSER.parseFrom(data, extensionRegistry); 286 return PARSER.parseFrom(data, extensionRegistry);
286 } 287 }
287 - public static ResponseProtocol parseFrom( 288 + public static CIMResProtocol parseFrom(
288 com.google.protobuf.ByteString data) 289 com.google.protobuf.ByteString data)
289 throws com.google.protobuf.InvalidProtocolBufferException { 290 throws com.google.protobuf.InvalidProtocolBufferException {
290 return PARSER.parseFrom(data); 291 return PARSER.parseFrom(data);
291 } 292 }
292 - public static ResponseProtocol parseFrom( 293 + public static CIMResProtocol parseFrom(
293 com.google.protobuf.ByteString data, 294 com.google.protobuf.ByteString data,
294 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 295 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
295 throws com.google.protobuf.InvalidProtocolBufferException { 296 throws com.google.protobuf.InvalidProtocolBufferException {
296 return PARSER.parseFrom(data, extensionRegistry); 297 return PARSER.parseFrom(data, extensionRegistry);
297 } 298 }
298 - public static ResponseProtocol parseFrom(byte[] data) 299 + public static CIMResProtocol parseFrom(byte[] data)
299 throws com.google.protobuf.InvalidProtocolBufferException { 300 throws com.google.protobuf.InvalidProtocolBufferException {
300 return PARSER.parseFrom(data); 301 return PARSER.parseFrom(data);
301 } 302 }
302 - public static ResponseProtocol parseFrom( 303 + public static CIMResProtocol parseFrom(
303 byte[] data, 304 byte[] data,
304 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 305 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
305 throws com.google.protobuf.InvalidProtocolBufferException { 306 throws com.google.protobuf.InvalidProtocolBufferException {
306 return PARSER.parseFrom(data, extensionRegistry); 307 return PARSER.parseFrom(data, extensionRegistry);
307 } 308 }
308 - public static ResponseProtocol parseFrom(java.io.InputStream input) 309 + public static CIMResProtocol parseFrom(java.io.InputStream input)
309 throws java.io.IOException { 310 throws java.io.IOException {
310 return com.google.protobuf.GeneratedMessageV3 311 return com.google.protobuf.GeneratedMessageV3
311 .parseWithIOException(PARSER, input); 312 .parseWithIOException(PARSER, input);
312 } 313 }
313 - public static ResponseProtocol parseFrom( 314 + public static CIMResProtocol parseFrom(
314 java.io.InputStream input, 315 java.io.InputStream input,
315 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 316 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
316 throws java.io.IOException { 317 throws java.io.IOException {
317 return com.google.protobuf.GeneratedMessageV3 318 return com.google.protobuf.GeneratedMessageV3
318 .parseWithIOException(PARSER, input, extensionRegistry); 319 .parseWithIOException(PARSER, input, extensionRegistry);
319 } 320 }
320 - public static ResponseProtocol parseDelimitedFrom(java.io.InputStream input) 321 + public static CIMResProtocol parseDelimitedFrom(java.io.InputStream input)
321 throws java.io.IOException { 322 throws java.io.IOException {
322 return com.google.protobuf.GeneratedMessageV3 323 return com.google.protobuf.GeneratedMessageV3
323 .parseDelimitedWithIOException(PARSER, input); 324 .parseDelimitedWithIOException(PARSER, input);
324 } 325 }
325 - public static ResponseProtocol parseDelimitedFrom( 326 + public static CIMResProtocol parseDelimitedFrom(
326 java.io.InputStream input, 327 java.io.InputStream input,
327 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 328 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
328 throws java.io.IOException { 329 throws java.io.IOException {
329 return com.google.protobuf.GeneratedMessageV3 330 return com.google.protobuf.GeneratedMessageV3
330 .parseDelimitedWithIOException(PARSER, input, extensionRegistry); 331 .parseDelimitedWithIOException(PARSER, input, extensionRegistry);
331 } 332 }
332 - public static ResponseProtocol parseFrom( 333 + public static CIMResProtocol parseFrom(
333 com.google.protobuf.CodedInputStream input) 334 com.google.protobuf.CodedInputStream input)
334 throws java.io.IOException { 335 throws java.io.IOException {
335 return com.google.protobuf.GeneratedMessageV3 336 return com.google.protobuf.GeneratedMessageV3
336 .parseWithIOException(PARSER, input); 337 .parseWithIOException(PARSER, input);
337 } 338 }
338 - public static ResponseProtocol parseFrom( 339 + public static CIMResProtocol parseFrom(
339 com.google.protobuf.CodedInputStream input, 340 com.google.protobuf.CodedInputStream input,
340 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 341 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
341 throws java.io.IOException { 342 throws java.io.IOException {
@@ -347,7 +348,7 @@ public final class BaseResponseProto { @@ -347,7 +348,7 @@ public final class BaseResponseProto {
347 public static Builder newBuilder() { 348 public static Builder newBuilder() {
348 return DEFAULT_INSTANCE.toBuilder(); 349 return DEFAULT_INSTANCE.toBuilder();
349 } 350 }
350 - public static Builder newBuilder(ResponseProtocol prototype) { 351 + public static Builder newBuilder(CIMResProtocol prototype) {
351 return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); 352 return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
352 } 353 }
353 public Builder toBuilder() { 354 public Builder toBuilder() {
@@ -362,25 +363,25 @@ public final class BaseResponseProto { @@ -362,25 +363,25 @@ public final class BaseResponseProto {
362 return builder; 363 return builder;
363 } 364 }
364 /** 365 /**
365 - * Protobuf type {@code protocol.ResponseProtocol} 366 + * Protobuf type {@code protocol.CIMResProtocol}
366 */ 367 */
367 public static final class Builder extends 368 public static final class Builder extends
368 com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements 369 com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
369 - // @@protoc_insertion_point(builder_implements:protocol.ResponseProtocol)  
370 - ResponseProtocolOrBuilder { 370 + // @@protoc_insertion_point(builder_implements:protocol.CIMResProtocol)
  371 + CIMResProtocolOrBuilder {
371 public static final com.google.protobuf.Descriptors.Descriptor 372 public static final com.google.protobuf.Descriptors.Descriptor
372 getDescriptor() { 373 getDescriptor() {
373 - return BaseResponseProto.internal_static_protocol_ResponseProtocol_descriptor; 374 + return CIMResponseProto.internal_static_protocol_CIMResProtocol_descriptor;
374 } 375 }
375 376
376 protected FieldAccessorTable 377 protected FieldAccessorTable
377 internalGetFieldAccessorTable() { 378 internalGetFieldAccessorTable() {
378 - return BaseResponseProto.internal_static_protocol_ResponseProtocol_fieldAccessorTable 379 + return CIMResponseProto.internal_static_protocol_CIMResProtocol_fieldAccessorTable
379 .ensureFieldAccessorsInitialized( 380 .ensureFieldAccessorsInitialized(
380 - ResponseProtocol.class, Builder.class); 381 + CIMResProtocol.class, Builder.class);
381 } 382 }
382 383
383 - // Construct using com.crossoverjie.netty.action.protocol.BaseResponseProto.ResponseProtocol.newBuilder() 384 + // Construct using com.crossoverjie.cim.common.protocol.CIMResponseProto.CIMResProtocol.newBuilder()
384 private Builder() { 385 private Builder() {
385 maybeForceBuilderInitialization(); 386 maybeForceBuilderInitialization();
386 } 387 }
@@ -397,7 +398,7 @@ public final class BaseResponseProto { @@ -397,7 +398,7 @@ public final class BaseResponseProto {
397 } 398 }
398 public Builder clear() { 399 public Builder clear() {
399 super.clear(); 400 super.clear();
400 - responseId_ = 0; 401 + responseId_ = 0L;
401 bitField0_ = (bitField0_ & ~0x00000001); 402 bitField0_ = (bitField0_ & ~0x00000001);
402 resMsg_ = ""; 403 resMsg_ = "";
403 bitField0_ = (bitField0_ & ~0x00000002); 404 bitField0_ = (bitField0_ & ~0x00000002);
@@ -406,23 +407,23 @@ public final class BaseResponseProto { @@ -406,23 +407,23 @@ public final class BaseResponseProto {
406 407
407 public com.google.protobuf.Descriptors.Descriptor 408 public com.google.protobuf.Descriptors.Descriptor
408 getDescriptorForType() { 409 getDescriptorForType() {
409 - return BaseResponseProto.internal_static_protocol_ResponseProtocol_descriptor; 410 + return CIMResponseProto.internal_static_protocol_CIMResProtocol_descriptor;
410 } 411 }
411 412
412 - public ResponseProtocol getDefaultInstanceForType() {  
413 - return ResponseProtocol.getDefaultInstance(); 413 + public CIMResProtocol getDefaultInstanceForType() {
  414 + return CIMResProtocol.getDefaultInstance();
414 } 415 }
415 416
416 - public ResponseProtocol build() {  
417 - ResponseProtocol result = buildPartial(); 417 + public CIMResProtocol build() {
  418 + CIMResProtocol result = buildPartial();
418 if (!result.isInitialized()) { 419 if (!result.isInitialized()) {
419 throw newUninitializedMessageException(result); 420 throw newUninitializedMessageException(result);
420 } 421 }
421 return result; 422 return result;
422 } 423 }
423 424
424 - public ResponseProtocol buildPartial() {  
425 - ResponseProtocol result = new ResponseProtocol(this); 425 + public CIMResProtocol buildPartial() {
  426 + CIMResProtocol result = new CIMResProtocol(this);
426 int from_bitField0_ = bitField0_; 427 int from_bitField0_ = bitField0_;
427 int to_bitField0_ = 0; 428 int to_bitField0_ = 0;
428 if (((from_bitField0_ & 0x00000001) == 0x00000001)) { 429 if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
@@ -465,16 +466,16 @@ public final class BaseResponseProto { @@ -465,16 +466,16 @@ public final class BaseResponseProto {
465 return (Builder) super.addRepeatedField(field, value); 466 return (Builder) super.addRepeatedField(field, value);
466 } 467 }
467 public Builder mergeFrom(com.google.protobuf.Message other) { 468 public Builder mergeFrom(com.google.protobuf.Message other) {
468 - if (other instanceof ResponseProtocol) {  
469 - return mergeFrom((ResponseProtocol)other); 469 + if (other instanceof CIMResProtocol) {
  470 + return mergeFrom((CIMResProtocol)other);
470 } else { 471 } else {
471 super.mergeFrom(other); 472 super.mergeFrom(other);
472 return this; 473 return this;
473 } 474 }
474 } 475 }
475 476
476 - public Builder mergeFrom(ResponseProtocol other) {  
477 - if (other == ResponseProtocol.getDefaultInstance()) return this; 477 + public Builder mergeFrom(CIMResProtocol other) {
  478 + if (other == CIMResProtocol.getDefaultInstance()) return this;
478 if (other.hasResponseId()) { 479 if (other.hasResponseId()) {
479 setResponseId(other.getResponseId()); 480 setResponseId(other.getResponseId());
480 } 481 }
@@ -502,11 +503,11 @@ public final class BaseResponseProto { @@ -502,11 +503,11 @@ public final class BaseResponseProto {
502 com.google.protobuf.CodedInputStream input, 503 com.google.protobuf.CodedInputStream input,
503 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 504 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
504 throws java.io.IOException { 505 throws java.io.IOException {
505 - ResponseProtocol parsedMessage = null; 506 + CIMResProtocol parsedMessage = null;
506 try { 507 try {
507 parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); 508 parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
508 } catch (com.google.protobuf.InvalidProtocolBufferException e) { 509 } catch (com.google.protobuf.InvalidProtocolBufferException e) {
509 - parsedMessage = (ResponseProtocol) e.getUnfinishedMessage(); 510 + parsedMessage = (CIMResProtocol) e.getUnfinishedMessage();
510 throw e.unwrapIOException(); 511 throw e.unwrapIOException();
511 } finally { 512 } finally {
512 if (parsedMessage != null) { 513 if (parsedMessage != null) {
@@ -517,34 +518,34 @@ public final class BaseResponseProto { @@ -517,34 +518,34 @@ public final class BaseResponseProto {
517 } 518 }
518 private int bitField0_; 519 private int bitField0_;
519 520
520 - private int responseId_ ; 521 + private long responseId_ ;
521 /** 522 /**
522 - * <code>required int32 responseId = 2;</code> 523 + * <code>required int64 responseId = 2;</code>
523 */ 524 */
524 public boolean hasResponseId() { 525 public boolean hasResponseId() {
525 return ((bitField0_ & 0x00000001) == 0x00000001); 526 return ((bitField0_ & 0x00000001) == 0x00000001);
526 } 527 }
527 /** 528 /**
528 - * <code>required int32 responseId = 2;</code> 529 + * <code>required int64 responseId = 2;</code>
529 */ 530 */
530 - public int getResponseId() { 531 + public long getResponseId() {
531 return responseId_; 532 return responseId_;
532 } 533 }
533 /** 534 /**
534 - * <code>required int32 responseId = 2;</code> 535 + * <code>required int64 responseId = 2;</code>
535 */ 536 */
536 - public Builder setResponseId(int value) { 537 + public Builder setResponseId(long value) {
537 bitField0_ |= 0x00000001; 538 bitField0_ |= 0x00000001;
538 responseId_ = value; 539 responseId_ = value;
539 onChanged(); 540 onChanged();
540 return this; 541 return this;
541 } 542 }
542 /** 543 /**
543 - * <code>required int32 responseId = 2;</code> 544 + * <code>required int64 responseId = 2;</code>
544 */ 545 */
545 public Builder clearResponseId() { 546 public Builder clearResponseId() {
546 bitField0_ = (bitField0_ & ~0x00000001); 547 bitField0_ = (bitField0_ & ~0x00000001);
547 - responseId_ = 0; 548 + responseId_ = 0L;
548 onChanged(); 549 onChanged();
549 return this; 550 return this;
550 } 551 }
@@ -635,49 +636,49 @@ public final class BaseResponseProto { @@ -635,49 +636,49 @@ public final class BaseResponseProto {
635 } 636 }
636 637
637 638
638 - // @@protoc_insertion_point(builder_scope:protocol.ResponseProtocol) 639 + // @@protoc_insertion_point(builder_scope:protocol.CIMResProtocol)
639 } 640 }
640 641
641 - // @@protoc_insertion_point(class_scope:protocol.ResponseProtocol)  
642 - private static final ResponseProtocol DEFAULT_INSTANCE; 642 + // @@protoc_insertion_point(class_scope:protocol.CIMResProtocol)
  643 + private static final CIMResProtocol DEFAULT_INSTANCE;
643 static { 644 static {
644 - DEFAULT_INSTANCE = new ResponseProtocol(); 645 + DEFAULT_INSTANCE = new CIMResProtocol();
645 } 646 }
646 647
647 - public static ResponseProtocol getDefaultInstance() { 648 + public static CIMResProtocol getDefaultInstance() {
648 return DEFAULT_INSTANCE; 649 return DEFAULT_INSTANCE;
649 } 650 }
650 651
651 - @Deprecated public static final com.google.protobuf.Parser<ResponseProtocol>  
652 - PARSER = new com.google.protobuf.AbstractParser<ResponseProtocol>() {  
653 - public ResponseProtocol parsePartialFrom( 652 + @Deprecated public static final com.google.protobuf.Parser<CIMResProtocol>
  653 + PARSER = new com.google.protobuf.AbstractParser<CIMResProtocol>() {
  654 + public CIMResProtocol parsePartialFrom(
654 com.google.protobuf.CodedInputStream input, 655 com.google.protobuf.CodedInputStream input,
655 com.google.protobuf.ExtensionRegistryLite extensionRegistry) 656 com.google.protobuf.ExtensionRegistryLite extensionRegistry)
656 throws com.google.protobuf.InvalidProtocolBufferException { 657 throws com.google.protobuf.InvalidProtocolBufferException {
657 - return new ResponseProtocol(input, extensionRegistry); 658 + return new CIMResProtocol(input, extensionRegistry);
658 } 659 }
659 }; 660 };
660 661
661 - public static com.google.protobuf.Parser<ResponseProtocol> parser() { 662 + public static com.google.protobuf.Parser<CIMResProtocol> parser() {
662 return PARSER; 663 return PARSER;
663 } 664 }
664 665
665 @Override 666 @Override
666 - public com.google.protobuf.Parser<ResponseProtocol> getParserForType() { 667 + public com.google.protobuf.Parser<CIMResProtocol> getParserForType() {
667 return PARSER; 668 return PARSER;
668 } 669 }
669 670
670 - public ResponseProtocol getDefaultInstanceForType() { 671 + public CIMResProtocol getDefaultInstanceForType() {
671 return DEFAULT_INSTANCE; 672 return DEFAULT_INSTANCE;
672 } 673 }
673 674
674 } 675 }
675 676
676 private static final com.google.protobuf.Descriptors.Descriptor 677 private static final com.google.protobuf.Descriptors.Descriptor
677 - internal_static_protocol_ResponseProtocol_descriptor; 678 + internal_static_protocol_CIMResProtocol_descriptor;
678 private static final 679 private static final
679 com.google.protobuf.GeneratedMessageV3.FieldAccessorTable 680 com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
680 - internal_static_protocol_ResponseProtocol_fieldAccessorTable; 681 + internal_static_protocol_CIMResProtocol_fieldAccessorTable;
681 682
682 public static com.google.protobuf.Descriptors.FileDescriptor 683 public static com.google.protobuf.Descriptors.FileDescriptor
683 getDescriptor() { 684 getDescriptor() {
@@ -687,10 +688,10 @@ public final class BaseResponseProto { @@ -687,10 +688,10 @@ public final class BaseResponseProto {
687 descriptor; 688 descriptor;
688 static { 689 static {
689 String[] descriptorData = { 690 String[] descriptorData = {
690 - "\n\027BaseResponseProto.proto\022\010protocol\"6\n\020R" +  
691 - "esponseProtocol\022\022\n\nresponseId\030\002 \002(\005\022\016\n\006r" +  
692 - "esMsg\030\001 \002(\tB;\n&com.crossoverjie.netty.ac" +  
693 - "tion.protocolB\021BaseResponseProto" 691 + "\n\027BaseResponseProto.proto\022\010protocol\"4\n\016C" +
  692 + "IMResProtocol\022\022\n\nresponseId\030\002 \002(\003\022\016\n\006res" +
  693 + "Msg\030\001 \002(\tB8\n$com.crossoverjie.cim.common" +
  694 + ".protocolB\020CIMResponseProto"
694 }; 695 };
695 com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = 696 com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
696 new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { 697 new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
@@ -704,11 +705,11 @@ public final class BaseResponseProto { @@ -704,11 +705,11 @@ public final class BaseResponseProto {
704 .internalBuildGeneratedFileFrom(descriptorData, 705 .internalBuildGeneratedFileFrom(descriptorData,
705 new com.google.protobuf.Descriptors.FileDescriptor[] { 706 new com.google.protobuf.Descriptors.FileDescriptor[] {
706 }, assigner); 707 }, assigner);
707 - internal_static_protocol_ResponseProtocol_descriptor = 708 + internal_static_protocol_CIMResProtocol_descriptor =
708 getDescriptor().getMessageTypes().get(0); 709 getDescriptor().getMessageTypes().get(0);
709 - internal_static_protocol_ResponseProtocol_fieldAccessorTable = new 710 + internal_static_protocol_CIMResProtocol_fieldAccessorTable = new
710 com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( 711 com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
711 - internal_static_protocol_ResponseProtocol_descriptor, 712 + internal_static_protocol_CIMResProtocol_descriptor,
712 new String[] { "ResponseId", "ResMsg", }); 713 new String[] { "ResponseId", "ResMsg", });
713 } 714 }
714 715
1 -package com.crossoverjie.netty.action.common.protocol; 1 +package com.crossoverjie.cim.common.protocol;
2 2
3 import com.google.protobuf.InvalidProtocolBufferException; 3 import com.google.protobuf.InvalidProtocolBufferException;
4 4
@@ -12,14 +12,14 @@ import com.google.protobuf.InvalidProtocolBufferException; @@ -12,14 +12,14 @@ import com.google.protobuf.InvalidProtocolBufferException;
12 public class ProtocolUtil { 12 public class ProtocolUtil {
13 13
14 public static void main(String[] args) throws InvalidProtocolBufferException { 14 public static void main(String[] args) throws InvalidProtocolBufferException {
15 - BaseRequestProto.RequestProtocol protocol = BaseRequestProto.RequestProtocol.newBuilder()  
16 - .setRequestId(123) 15 + CIMRequestProto.CIMReqProtocol protocol = CIMRequestProto.CIMReqProtocol.newBuilder()
  16 + .setRequestId(123L)
17 .setReqMsg("你好啊") 17 .setReqMsg("你好啊")
18 .build(); 18 .build();
19 19
20 byte[] encode = encode(protocol); 20 byte[] encode = encode(protocol);
21 21
22 - BaseRequestProto.RequestProtocol parseFrom = decode(encode); 22 + CIMRequestProto.CIMReqProtocol parseFrom = decode(encode);
23 23
24 System.out.println(protocol.toString()); 24 System.out.println(protocol.toString());
25 System.out.println(protocol.toString().equals(parseFrom.toString())); 25 System.out.println(protocol.toString().equals(parseFrom.toString()));
@@ -30,7 +30,7 @@ public class ProtocolUtil { @@ -30,7 +30,7 @@ public class ProtocolUtil {
30 * @param protocol 30 * @param protocol
31 * @return 31 * @return
32 */ 32 */
33 - public static byte[] encode(BaseRequestProto.RequestProtocol protocol){ 33 + public static byte[] encode(CIMRequestProto.CIMReqProtocol protocol){
34 return protocol.toByteArray() ; 34 return protocol.toByteArray() ;
35 } 35 }
36 36
@@ -40,7 +40,7 @@ public class ProtocolUtil { @@ -40,7 +40,7 @@ public class ProtocolUtil {
40 * @return 40 * @return
41 * @throws InvalidProtocolBufferException 41 * @throws InvalidProtocolBufferException
42 */ 42 */
43 - public static BaseRequestProto.RequestProtocol decode(byte[] bytes) throws InvalidProtocolBufferException {  
44 - return BaseRequestProto.RequestProtocol.parseFrom(bytes); 43 + public static CIMRequestProto.CIMReqProtocol decode(byte[] bytes) throws InvalidProtocolBufferException {
  44 + return CIMRequestProto.CIMReqProtocol.parseFrom(bytes);
45 } 45 }
46 } 46 }
1 -package com.crossoverjie.netty.action.common.req; 1 +package com.crossoverjie.cim.common.req;
2 2
3 import io.swagger.annotations.ApiModelProperty; 3 import io.swagger.annotations.ApiModelProperty;
4 4
1 -package com.crossoverjie.netty.action.common.res; 1 +package com.crossoverjie.cim.common.res;
2 2
3 3
4 4
5 -import com.crossoverjie.netty.action.common.util.StringUtil;  
6 -import com.crossoverjie.netty.action.common.enums.StatusEnum; 5 +import com.crossoverjie.cim.common.enums.StatusEnum;
  6 +import com.crossoverjie.cim.common.util.StringUtil;
7 7
8 import java.io.Serializable; 8 import java.io.Serializable;
9 9
1 -package com.crossoverjie.netty.action.common.res; 1 +package com.crossoverjie.cim.common.res;
2 2
3 /** 3 /**
4 * Function:空对象,用在泛型中,表示没有额外的请求参数或者返回参数 4 * Function:空对象,用在泛型中,表示没有额外的请求参数或者返回参数
1 -package com.crossoverjie.netty.action.common.util; 1 +package com.crossoverjie.cim.common.util;
2 2
3 import java.util.Random; 3 import java.util.Random;
4 import java.util.UUID; 4 import java.util.UUID;
1 -package com.crossoverjie.netty.action.common.util; 1 +package com.crossoverjie.cim.common.util;
2 2
3 /** 3 /**
4 * Function: 4 * Function:
  1 +package com.crossoverjie.cim.common.enums;
  2 +
  3 +import org.junit.Test;
  4 +
  5 +import java.util.Map;
  6 +
  7 +public class SystemCommandEnumTypeTest {
  8 +
  9 +
  10 + @Test
  11 + public void getAllStatusCode() throws Exception {
  12 + Map<String, String> allStatusCode = SystemCommandEnumType.getAllStatusCode();
  13 + for (Map.Entry<String, String> stringStringEntry : allStatusCode.entrySet()) {
  14 + String key = stringStringEntry.getKey();
  15 + String value = stringStringEntry.getValue();
  16 + System.out.println(key + "----->" + value);
  17 + }
  18 +
  19 + }
  20 +
  21 +}
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns="http://maven.apache.org/POM/4.0.0"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5 + <parent>
  6 + <artifactId>cim</artifactId>
  7 + <groupId>com.crossoverjie.netty</groupId>
  8 + <version>1.0.0-SNAPSHOT</version>
  9 + </parent>
  10 + <modelVersion>4.0.0</modelVersion>
  11 +
  12 + <artifactId>cim-forward-route</artifactId>
  13 + <packaging>jar</packaging>
  14 +
  15 + <properties>
  16 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  17 + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  18 + <java.version>1.8</java.version>
  19 + <swagger.version>2.5.0</swagger.version>
  20 + <logback.version>1.2.3</logback.version>
  21 + </properties>
  22 +
  23 +
  24 +
  25 + <dependencies>
  26 +
  27 + <dependency>
  28 + <groupId>com.crossoverjie.netty</groupId>
  29 + <artifactId>cim-common</artifactId>
  30 + <exclusions>
  31 + <exclusion>
  32 + <artifactId>log4j</artifactId>
  33 + <groupId>log4j</groupId>
  34 + </exclusion>
  35 + </exclusions>
  36 + </dependency>
  37 +
  38 + <dependency>
  39 + <groupId>org.springframework.boot</groupId>
  40 + <artifactId>spring-boot-starter-data-redis</artifactId>
  41 + </dependency>
  42 +
  43 +
  44 + <dependency>
  45 + <groupId>io.springfox</groupId>
  46 + <artifactId>springfox-swagger2</artifactId>
  47 + <scope>compile</scope>
  48 + </dependency>
  49 + <dependency>
  50 + <groupId>io.springfox</groupId>
  51 + <artifactId>springfox-swagger-ui</artifactId>
  52 + </dependency>
  53 +
  54 + <dependency>
  55 + <groupId>org.springframework.boot</groupId>
  56 + <artifactId>spring-boot-starter-web</artifactId>
  57 + </dependency>
  58 + <dependency>
  59 + <groupId>org.springframework.boot</groupId>
  60 + <artifactId>spring-boot-starter-test</artifactId>
  61 + <scope>test</scope>
  62 + </dependency>
  63 +
  64 + <dependency>
  65 + <groupId>org.springframework.boot</groupId>
  66 + <artifactId>spring-boot-configuration-processor</artifactId>
  67 + <optional>true</optional>
  68 + </dependency>
  69 +
  70 +
  71 + <dependency>
  72 + <groupId>org.springframework.boot</groupId>
  73 + <artifactId>spring-boot-starter-actuator</artifactId>
  74 + </dependency>
  75 +
  76 + <dependency>
  77 + <groupId>de.codecentric</groupId>
  78 + <artifactId>spring-boot-admin-starter-client</artifactId>
  79 + </dependency>
  80 +
  81 + <dependency>
  82 + <groupId>ch.qos.logback</groupId>
  83 + <artifactId>logback-classic</artifactId>
  84 + </dependency>
  85 +
  86 + <dependency>
  87 + <groupId>io.netty</groupId>
  88 + <artifactId>netty-all</artifactId>
  89 + <version>${netty.version}</version>
  90 + </dependency>
  91 +
  92 + <dependency>
  93 + <groupId>junit</groupId>
  94 + <artifactId>junit</artifactId>
  95 + </dependency>
  96 +
  97 + <dependency>
  98 + <groupId>com.alibaba</groupId>
  99 + <artifactId>fastjson</artifactId>
  100 + </dependency>
  101 +
  102 + <dependency>
  103 + <groupId>com.google.guava</groupId>
  104 + <artifactId>guava</artifactId>
  105 + </dependency>
  106 +
  107 + </dependencies>
  108 +
  109 + <build>
  110 + <plugins>
  111 + <!-- spring-boot-maven-plugin (提供了直接运行项目的插件:如果是通过parent方式继承spring-boot-starter-parent则不用此插件) -->
  112 + <plugin>
  113 + <groupId>org.springframework.boot</groupId>
  114 + <artifactId>spring-boot-maven-plugin</artifactId>
  115 + <executions>
  116 + <execution>
  117 + <goals>
  118 + <goal>repackage</goal>
  119 + </goals>
  120 + </execution>
  121 + </executions>
  122 + </plugin>
  123 + </plugins>
  124 + </build>
  125 +
  126 +</project>
1 -package com.crossoverjie.netty.action; 1 +package com.crossoverjie.cim.route;
2 2
  3 +import com.crossoverjie.cim.route.kit.ServerListListener;
3 import org.slf4j.Logger; 4 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory; 5 import org.slf4j.LoggerFactory;
  6 +import org.springframework.boot.CommandLineRunner;
5 import org.springframework.boot.SpringApplication; 7 import org.springframework.boot.SpringApplication;
6 import org.springframework.boot.autoconfigure.SpringBootApplication; 8 import org.springframework.boot.autoconfigure.SpringBootApplication;
7 9
@@ -9,13 +11,21 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -9,13 +11,21 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
9 * @author crossoverJie 11 * @author crossoverJie
10 */ 12 */
11 @SpringBootApplication 13 @SpringBootApplication
12 -public class HeartbeatServerApplication { 14 +public class RouteApplication implements CommandLineRunner{
13 15
14 - private final static Logger LOGGER = LoggerFactory.getLogger(HeartbeatServerApplication.class); 16 + private final static Logger LOGGER = LoggerFactory.getLogger(RouteApplication.class);
15 17
16 public static void main(String[] args) { 18 public static void main(String[] args) {
17 - SpringApplication.run(HeartbeatServerApplication.class, args);  
18 - LOGGER.info("启动 Server 成功"); 19 + SpringApplication.run(RouteApplication.class, args);
  20 + LOGGER.info("启动 route 成功");
19 } 21 }
20 22
  23 + @Override
  24 + public void run(String... args) throws Exception {
  25 +
  26 + //监听服务
  27 + Thread thread = new Thread(new ServerListListener());
  28 + thread.setName("zk-listener");
  29 + thread.start() ;
  30 + }
21 } 31 }
  1 +package com.crossoverjie.cim.route.cache;
  2 +
  3 +import com.crossoverjie.cim.route.kit.ZKit;
  4 +import com.google.common.cache.LoadingCache;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.stereotype.Component;
  7 +
  8 +import java.util.ArrayList;
  9 +import java.util.List;
  10 +import java.util.Map;
  11 +import java.util.concurrent.atomic.AtomicLong;
  12 +
  13 +/**
  14 + * Function: 服务器节点缓存
  15 + *
  16 + * @author crossoverJie
  17 + * Date: 2018/8/19 01:31
  18 + * @since JDK 1.8
  19 + */
  20 +@Component
  21 +public class ServerCache {
  22 +
  23 +
  24 + @Autowired
  25 + private LoadingCache<String, String> cache;
  26 +
  27 + @Autowired
  28 + private ZKit zkUtil;
  29 +
  30 + private AtomicLong index = new AtomicLong();
  31 +
  32 +
  33 + public void addCache(String key) {
  34 + cache.put(key, key);
  35 + }
  36 +
  37 +
  38 + /**
  39 + * 更新所有缓存/先删除 再新增
  40 + *
  41 + * @param currentChilds
  42 + */
  43 + public void updateCache(List<String> currentChilds) {
  44 + cache.invalidateAll();
  45 + for (String currentChild : currentChilds) {
  46 + String key = currentChild.split("-")[1];
  47 + addCache(key);
  48 + }
  49 + }
  50 +
  51 +
  52 + /**
  53 + * 获取所有的服务列表
  54 + *
  55 + * @return
  56 + */
  57 + public List<String> getAll() {
  58 +
  59 + List<String> list = new ArrayList<>();
  60 +
  61 + if (cache.size() == 0) {
  62 + List<String> allNode = zkUtil.getAllNode();
  63 + for (String node : allNode) {
  64 + String key = node.split("-")[1];
  65 + addCache(key);
  66 + }
  67 + }
  68 + for (Map.Entry<String, String> entry : cache.asMap().entrySet()) {
  69 + list.add(entry.getKey());
  70 + }
  71 + return list;
  72 +
  73 + }
  74 +
  75 + /**
  76 + * 选取服务器
  77 + *
  78 + * @return
  79 + */
  80 + public String selectServer() {
  81 + List<String> all = getAll();
  82 + if (all.size() == 0) {
  83 + throw new RuntimeException("CIM 服务器可用服务列表为空");
  84 + }
  85 + Long position = index.incrementAndGet() % all.size();
  86 + if (position < 0) {
  87 + position = 0L;
  88 + }
  89 +
  90 + return all.get(position.intValue());
  91 + }
  92 +}
  1 +package com.crossoverjie.cim.route.config;
  2 +
  3 +import org.springframework.beans.factory.annotation.Value;
  4 +import org.springframework.stereotype.Component;
  5 +
  6 +/**
  7 + * Function:
  8 + *
  9 + * @author crossoverJie
  10 + * Date: 2018/8/24 01:43
  11 + * @since JDK 1.8
  12 + */
  13 +@Component
  14 +public class AppConfiguration {
  15 +
  16 + @Value("${app.zk.root}")
  17 + private String zkRoot;
  18 +
  19 + @Value("${app.zk.addr}")
  20 + private String zkAddr;
  21 +
  22 +
  23 + @Value("${server.port}")
  24 + private int port;
  25 +
  26 + public int getPort() {
  27 + return port;
  28 + }
  29 +
  30 + public void setPort(int port) {
  31 + this.port = port;
  32 + }
  33 +
  34 + public String getZkRoot() {
  35 + return zkRoot;
  36 + }
  37 +
  38 + public void setZkRoot(String zkRoot) {
  39 + this.zkRoot = zkRoot;
  40 + }
  41 +
  42 + public String getZkAddr() {
  43 + return zkAddr;
  44 + }
  45 +
  46 + public void setZkAddr(String zkAddr) {
  47 + this.zkAddr = zkAddr;
  48 + }
  49 +
  50 +}
  1 +package com.crossoverjie.cim.route.config;
  2 +
  3 +import com.google.common.cache.CacheBuilder;
  4 +import com.google.common.cache.CacheLoader;
  5 +import com.google.common.cache.LoadingCache;
  6 +import okhttp3.OkHttpClient;
  7 +import org.I0Itec.zkclient.ZkClient;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.context.annotation.Bean;
  10 +import org.springframework.context.annotation.Configuration;
  11 +import org.springframework.data.redis.connection.RedisConnectionFactory;
  12 +import org.springframework.data.redis.core.RedisTemplate;
  13 +import org.springframework.data.redis.core.StringRedisTemplate;
  14 +import org.springframework.data.redis.serializer.StringRedisSerializer;
  15 +
  16 +import java.util.concurrent.TimeUnit;
  17 +
  18 +/**
  19 + * Function:
  20 + *
  21 + * @author crossoverJie
  22 + * Date: 2018/12/23 00:25
  23 + * @since JDK 1.8
  24 + */
  25 +@Configuration
  26 +public class BeanConfig {
  27 +
  28 + @Autowired
  29 + private AppConfiguration appConfiguration ;
  30 +
  31 + @Bean
  32 + public ZkClient buildZKClient(){
  33 + return new ZkClient(appConfiguration.getZkAddr(), 5000);
  34 + }
  35 +
  36 + @Bean
  37 + public LoadingCache<String,String> buildCache(){
  38 + return CacheBuilder.newBuilder()
  39 + .build(new CacheLoader<String, String>() {
  40 + @Override
  41 + public String load(String s) throws Exception {
  42 + return null;
  43 + }
  44 + });
  45 + }
  46 +
  47 +
  48 + /**
  49 + * Redis bean
  50 + * @param factory
  51 + * @return
  52 + */
  53 + @Bean
  54 + public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
  55 + StringRedisTemplate redisTemplate = new StringRedisTemplate(factory);
  56 + redisTemplate.setKeySerializer(new StringRedisSerializer());
  57 + redisTemplate.setValueSerializer(new StringRedisSerializer());
  58 + redisTemplate.afterPropertiesSet();
  59 + return redisTemplate;
  60 + }
  61 +
  62 +
  63 + /**
  64 + * http client
  65 + * @return okHttp
  66 + */
  67 + @Bean
  68 + public OkHttpClient okHttpClient() {
  69 + OkHttpClient.Builder builder = new OkHttpClient.Builder();
  70 + builder.connectTimeout(30, TimeUnit.SECONDS)
  71 + .readTimeout(10, TimeUnit.SECONDS)
  72 + .writeTimeout(10,TimeUnit.SECONDS)
  73 + .retryOnConnectionFailure(true);
  74 + return builder.build();
  75 + }
  76 +}
  1 +package com.crossoverjie.cim.route.config;
  2 +
  3 +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
  4 +import org.springframework.context.annotation.Bean;
  5 +import org.springframework.context.annotation.Configuration;
  6 +import springfox.documentation.builders.ApiInfoBuilder;
  7 +import springfox.documentation.builders.PathSelectors;
  8 +import springfox.documentation.builders.RequestHandlerSelectors;
  9 +import springfox.documentation.service.ApiInfo;
  10 +import springfox.documentation.spi.DocumentationType;
  11 +import springfox.documentation.spring.web.plugins.Docket;
  12 +import springfox.documentation.swagger2.annotations.EnableSwagger2;
  13 +
  14 +
  15 +@Configuration
  16 +@EnableSwagger2
  17 +/** 是否打开swagger **/
  18 +@ConditionalOnExpression("'${swagger.enable}' == 'true'")
  19 +public class SwaggerConfig {
  20 +
  21 +
  22 + @Bean
  23 + public Docket createRestApi() {
  24 + return new Docket(DocumentationType.SWAGGER_2)
  25 + .apiInfo(apiInfo())
  26 + .select()
  27 + .apis(RequestHandlerSelectors.basePackage("com.crossoverjie.cim.route.controller"))
  28 + .paths(PathSelectors.any())
  29 + .build();
  30 + }
  31 +
  32 + private ApiInfo apiInfo() {
  33 + return new ApiInfoBuilder()
  34 + .title("cim-forward-route")
  35 + .description("cim-forward-route api")
  36 + .termsOfServiceUrl("http://crossoverJie.top")
  37 + .contact("crossoverJie")
  38 + .version("1.0.0")
  39 + .build();
  40 + }
  41 +
  42 +}
  1 +package com.crossoverjie.cim.route.constant;
  2 +
  3 +/**
  4 + * Function:
  5 + *
  6 + * @author crossoverJie
  7 + * Date: 2018/9/10 14:07
  8 + * @since JDK 1.8
  9 + */
  10 +public final class Constant {
  11 +
  12 +
  13 + /**
  14 + * 账号前缀
  15 + */
  16 + public final static String ACCOUNT_PREFIX = "cim-account:";
  17 +
  18 + /**
  19 + * 路由信息前缀
  20 + */
  21 + public final static String ROUTE_PREFIX = "cim-route:";
  22 +
  23 + /**
  24 + * 登录状态前缀
  25 + */
  26 + public final static String LOGIN_STATUS_PREFIX = "login-status";
  27 +
  28 +
  29 +}
  1 +package com.crossoverjie.cim.route.controller;
  2 +
  3 +import com.crossoverjie.cim.common.enums.StatusEnum;
  4 +import com.crossoverjie.cim.common.exception.CIMException;
  5 +import com.crossoverjie.cim.common.pojo.CIMUserInfo;
  6 +import com.crossoverjie.cim.common.res.BaseResponse;
  7 +import com.crossoverjie.cim.common.res.NULLBody;
  8 +import com.crossoverjie.cim.route.cache.ServerCache;
  9 +import com.crossoverjie.cim.route.service.AccountService;
  10 +import com.crossoverjie.cim.route.service.UserInfoCacheService;
  11 +import com.crossoverjie.cim.route.vo.req.ChatReqVO;
  12 +import com.crossoverjie.cim.route.vo.req.LoginReqVO;
  13 +import com.crossoverjie.cim.route.vo.req.P2PReqVO;
  14 +import com.crossoverjie.cim.route.vo.req.RegisterInfoReqVO;
  15 +import com.crossoverjie.cim.route.vo.res.CIMServerResVO;
  16 +import com.crossoverjie.cim.route.vo.res.RegisterInfoResVO;
  17 +import io.swagger.annotations.ApiOperation;
  18 +import org.slf4j.Logger;
  19 +import org.slf4j.LoggerFactory;
  20 +import org.springframework.beans.factory.annotation.Autowired;
  21 +import org.springframework.stereotype.Controller;
  22 +import org.springframework.web.bind.annotation.RequestBody;
  23 +import org.springframework.web.bind.annotation.RequestMapping;
  24 +import org.springframework.web.bind.annotation.RequestMethod;
  25 +import org.springframework.web.bind.annotation.ResponseBody;
  26 +
  27 +import java.util.Map;
  28 +import java.util.Set;
  29 +
  30 +/**
  31 + * Function:
  32 + *
  33 + * @author crossoverJie
  34 + * Date: 22/05/2018 14:46
  35 + * @since JDK 1.8
  36 + */
  37 +@Controller
  38 +@RequestMapping("/")
  39 +public class RouteController {
  40 + private final static Logger LOGGER = LoggerFactory.getLogger(RouteController.class);
  41 +
  42 + @Autowired
  43 + private ServerCache serverCache;
  44 +
  45 + @Autowired
  46 + private AccountService accountService;
  47 +
  48 + @Autowired
  49 + private UserInfoCacheService userInfoCacheService ;
  50 +
  51 + @ApiOperation("群聊 API")
  52 + @RequestMapping(value = "groupRoute", method = RequestMethod.POST)
  53 + @ResponseBody()
  54 + public BaseResponse<NULLBody> groupRoute(@RequestBody ChatReqVO groupReqVO) throws Exception {
  55 + BaseResponse<NULLBody> res = new BaseResponse();
  56 +
  57 + LOGGER.info("msg=[{}]", groupReqVO.toString());
  58 +
  59 + //获取所有的推送列表
  60 + Map<Long, CIMServerResVO> serverResVOMap = accountService.loadRouteRelated();
  61 + for (Map.Entry<Long, CIMServerResVO> cimServerResVOEntry : serverResVOMap.entrySet()) {
  62 + Long userId = cimServerResVOEntry.getKey();
  63 + CIMServerResVO value = cimServerResVOEntry.getValue();
  64 + if (userId.equals(groupReqVO.getUserId())){
  65 + //过滤掉自己
  66 + CIMUserInfo cimUserInfo = userInfoCacheService.loadUserInfoByUserId(groupReqVO.getUserId());
  67 + LOGGER.warn("过滤掉了发送者 userId={}",cimUserInfo.toString());
  68 + continue;
  69 + }
  70 +
  71 + //推送消息
  72 + String url = "http://" + value.getIp() + ":" + value.getHttpPort() + "/sendMsg" ;
  73 + ChatReqVO chatVO = new ChatReqVO(userId,groupReqVO.getMsg()) ;
  74 +
  75 + accountService.pushMsg(url,groupReqVO.getUserId(),chatVO);
  76 +
  77 + }
  78 +
  79 + res.setCode(StatusEnum.SUCCESS.getCode());
  80 + res.setMessage(StatusEnum.SUCCESS.getMessage());
  81 + return res;
  82 + }
  83 +
  84 + // TODO: 2018/12/26 这些基于 HTTP 接口的远程通信都可以换为 SpringCloud
  85 +
  86 + /**
  87 + * 私聊路由
  88 + *
  89 + * @param p2pRequest
  90 + * @return
  91 + */
  92 + @ApiOperation("私聊 API")
  93 + @RequestMapping(value = "p2pRoute", method = RequestMethod.POST)
  94 + @ResponseBody()
  95 + public BaseResponse<NULLBody> p2pRoute(@RequestBody P2PReqVO p2pRequest) throws Exception {
  96 + BaseResponse<NULLBody> res = new BaseResponse();
  97 +
  98 + try {
  99 + //获取接收消息用户的路由信息
  100 + CIMServerResVO cimServerResVO = accountService.loadRouteRelatedByUserId(p2pRequest.getReceiveUserId());
  101 + //推送消息
  102 + String url = "http://" + cimServerResVO.getIp() + ":" + cimServerResVO.getHttpPort() + "/sendMsg" ;
  103 +
  104 + //p2pRequest.getReceiveUserId()==>消息接收者的 userID
  105 + ChatReqVO chatVO = new ChatReqVO(p2pRequest.getReceiveUserId(),p2pRequest.getMsg()) ;
  106 + accountService.pushMsg(url,p2pRequest.getUserId(),chatVO);
  107 +
  108 + res.setCode(StatusEnum.SUCCESS.getCode());
  109 + res.setMessage(StatusEnum.SUCCESS.getMessage());
  110 +
  111 + }catch (CIMException e){
  112 + res.setCode(e.getErrorCode());
  113 + res.setMessage(e.getErrorMessage());
  114 + }
  115 + return res;
  116 + }
  117 +
  118 +
  119 + @ApiOperation("客户端下线")
  120 + @RequestMapping(value = "offLine", method = RequestMethod.POST)
  121 + @ResponseBody()
  122 + public BaseResponse<NULLBody> offLine(@RequestBody ChatReqVO groupReqVO) throws Exception {
  123 + BaseResponse<NULLBody> res = new BaseResponse();
  124 +
  125 + CIMUserInfo cimUserInfo = userInfoCacheService.loadUserInfoByUserId(groupReqVO.getUserId());
  126 +
  127 + LOGGER.info("下线用户[{}]", cimUserInfo.toString());
  128 + accountService.offLine(groupReqVO.getUserId());
  129 +
  130 + res.setCode(StatusEnum.SUCCESS.getCode());
  131 + res.setMessage(StatusEnum.SUCCESS.getMessage());
  132 + return res;
  133 + }
  134 +
  135 + /**
  136 + * 获取一台 CIM server
  137 + *
  138 + * @return
  139 + */
  140 + @ApiOperation("登录并获取服务器")
  141 + @RequestMapping(value = "login", method = RequestMethod.POST)
  142 + @ResponseBody()
  143 + public BaseResponse<CIMServerResVO> login(@RequestBody LoginReqVO loginReqVO) throws Exception {
  144 + BaseResponse<CIMServerResVO> res = new BaseResponse();
  145 +
  146 + //登录校验
  147 + boolean login = accountService.login(loginReqVO);
  148 + if (login) {
  149 + String server = serverCache.selectServer();
  150 + String[] serverInfo = server.split(":");
  151 + CIMServerResVO vo = new CIMServerResVO(serverInfo[0], Integer.parseInt(serverInfo[1]),Integer.parseInt(serverInfo[2]));
  152 +
  153 + //保存路由信息
  154 + accountService.saveRouteInfo(loginReqVO,server);
  155 +
  156 + res.setDataBody(vo);
  157 + res.setCode(StatusEnum.SUCCESS.getCode());
  158 + res.setMessage(StatusEnum.SUCCESS.getMessage());
  159 + } else {
  160 + res.setCode(StatusEnum.REPEAT_LOGIN.getCode());
  161 + res.setMessage(StatusEnum.REPEAT_LOGIN.getMessage());
  162 + }
  163 +
  164 + return res;
  165 + }
  166 +
  167 + /**
  168 + * 注册账号
  169 + *
  170 + * @return
  171 + */
  172 + @ApiOperation("注册账号")
  173 + @RequestMapping(value = "registerAccount", method = RequestMethod.POST)
  174 + @ResponseBody()
  175 + public BaseResponse<RegisterInfoResVO> registerAccount(@RequestBody RegisterInfoReqVO registerInfoReqVO) throws Exception {
  176 + BaseResponse<RegisterInfoResVO> res = new BaseResponse();
  177 +
  178 + long userId = System.currentTimeMillis();
  179 + RegisterInfoResVO info = new RegisterInfoResVO(userId, registerInfoReqVO.getUserName());
  180 + info = accountService.register(info);
  181 +
  182 + res.setDataBody(info);
  183 + res.setCode(StatusEnum.SUCCESS.getCode());
  184 + res.setMessage(StatusEnum.SUCCESS.getMessage());
  185 + return res;
  186 + }
  187 +
  188 + /**
  189 + * 注册账号
  190 + *
  191 + * @return
  192 + */
  193 + @ApiOperation("获取所有在线用户")
  194 + @RequestMapping(value = "onlineUser", method = RequestMethod.POST)
  195 + @ResponseBody()
  196 + public BaseResponse<Set<CIMUserInfo>> onlineUser() throws Exception {
  197 + BaseResponse<Set<CIMUserInfo>> res = new BaseResponse();
  198 +
  199 + Set<CIMUserInfo> cimUserInfos = userInfoCacheService.onlineUser();
  200 + res.setDataBody(cimUserInfos) ;
  201 + res.setCode(StatusEnum.SUCCESS.getCode());
  202 + res.setMessage(StatusEnum.SUCCESS.getMessage());
  203 + return res;
  204 + }
  205 +
  206 +
  207 +
  208 +
  209 +
  210 +}
  1 +package com.crossoverjie.cim.route.kit;
  2 +
  3 +import com.crossoverjie.cim.route.config.AppConfiguration;
  4 +import com.crossoverjie.cim.route.util.SpringBeanFactory;
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
  7 +
  8 +/**
  9 + * Function:
  10 + *
  11 + * @author crossoverJie
  12 + * Date: 2018/12/23 00:35
  13 + * @since JDK 1.8
  14 + */
  15 +public class ServerListListener implements Runnable{
  16 +
  17 + private static Logger logger = LoggerFactory.getLogger(ServerListListener.class);
  18 +
  19 + private ZKit zkUtil;
  20 +
  21 + private AppConfiguration appConfiguration ;
  22 +
  23 +
  24 + public ServerListListener() {
  25 + zkUtil = SpringBeanFactory.getBean(ZKit.class) ;
  26 + appConfiguration = SpringBeanFactory.getBean(AppConfiguration.class) ;
  27 + }
  28 +
  29 + @Override
  30 + public void run() {
  31 + //注册监听服务
  32 + zkUtil.subscribeEvent(appConfiguration.getZkRoot());
  33 +
  34 + }
  35 +}
  1 +package com.crossoverjie.cim.route.kit;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.crossoverjie.cim.route.cache.ServerCache;
  5 +import org.I0Itec.zkclient.IZkChildListener;
  6 +import org.I0Itec.zkclient.ZkClient;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +import java.util.List;
  13 +
  14 +/**
  15 + * Function: Zookeeper 工具
  16 + *
  17 + * @author crossoverJie
  18 + * Date: 2018/8/19 00:33
  19 + * @since JDK 1.8
  20 + */
  21 +@Component
  22 +public class ZKit {
  23 +
  24 + private static Logger logger = LoggerFactory.getLogger(ZKit.class);
  25 +
  26 +
  27 + @Autowired
  28 + private ZkClient zkClient;
  29 +
  30 + @Autowired
  31 + private ServerCache serverCache ;
  32 +
  33 +
  34 + /**
  35 + * 监听事件
  36 + *
  37 + * @param path
  38 + */
  39 + public void subscribeEvent(String path) {
  40 + zkClient.subscribeChildChanges(path, new IZkChildListener() {
  41 + @Override
  42 + public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
  43 + logger.info("清除/更新本地缓存 parentPath=【{}】,currentChilds=【{}】", parentPath,currentChilds.toString());
  44 +
  45 + //更新所有缓存/先删除 再新增
  46 + serverCache.updateCache(currentChilds) ;
  47 + }
  48 + });
  49 +
  50 +
  51 + }
  52 +
  53 +
  54 + /**
  55 + * 获取所有注册节点
  56 + * @return
  57 + */
  58 + public List<String> getAllNode(){
  59 + List<String> children = zkClient.getChildren("/route");
  60 + logger.info("查询所有节点成功=【{}】", JSON.toJSONString(children));
  61 + return children;
  62 + }
  63 +
  64 +
  65 +}
  1 +package com.crossoverjie.cim.route.service;
  2 +
  3 +import com.crossoverjie.cim.route.vo.req.ChatReqVO;
  4 +import com.crossoverjie.cim.route.vo.req.LoginReqVO;
  5 +import com.crossoverjie.cim.route.vo.res.CIMServerResVO;
  6 +import com.crossoverjie.cim.route.vo.res.RegisterInfoResVO;
  7 +
  8 +import java.util.Map;
  9 +
  10 +/**
  11 + * Function: 账户服务
  12 + *
  13 + * @author crossoverJie
  14 + * Date: 2018/12/23 21:57
  15 + * @since JDK 1.8
  16 + */
  17 +public interface AccountService {
  18 +
  19 + /**
  20 + * 注册用户
  21 + * @param info 用户信息
  22 + * @return
  23 + * @throws Exception
  24 + */
  25 + RegisterInfoResVO register(RegisterInfoResVO info) throws Exception;
  26 +
  27 + /**
  28 + * 登录服务
  29 + * @param loginReqVO 登录信息
  30 + * @return true 成功 false 失败
  31 + * @throws Exception
  32 + */
  33 + boolean login(LoginReqVO loginReqVO) throws Exception ;
  34 +
  35 + /**
  36 + * 保存路由信息
  37 + * @param msg 服务器信息
  38 + * @param loginReqVO 用户信息
  39 + * @throws Exception
  40 + */
  41 + void saveRouteInfo(LoginReqVO loginReqVO ,String msg) throws Exception ;
  42 +
  43 + /**
  44 + * 加载所有用户的路有关系
  45 + * @return 所有的路由关系
  46 + */
  47 + Map<Long,CIMServerResVO> loadRouteRelated() ;
  48 +
  49 + /**
  50 + * 获取某个用户的路有关系
  51 + * @param userId
  52 + * @return 获取某个用户的路有关系
  53 + */
  54 + CIMServerResVO loadRouteRelatedByUserId(Long userId) ;
  55 +
  56 +
  57 + /**
  58 + * 推送消息
  59 + * @param url url
  60 + * @param groupReqVO 消息
  61 + * @param sendUserId 发送者的ID
  62 + * @throws Exception
  63 + */
  64 + void pushMsg(String url,long sendUserId ,ChatReqVO groupReqVO) throws Exception;
  65 +
  66 + /**
  67 + * 用户下线
  68 + * @param userId 下线用户ID
  69 + * @throws Exception
  70 + */
  71 + void offLine(Long userId) throws Exception;
  72 +}
  1 +package com.crossoverjie.cim.route.service;
  2 +
  3 +import com.crossoverjie.cim.common.pojo.CIMUserInfo;
  4 +
  5 +import java.util.Set;
  6 +
  7 +/**
  8 + * Function:
  9 + *
  10 + * @author crossoverJie
  11 + * Date: 2018/12/24 11:06
  12 + * @since JDK 1.8
  13 + */
  14 +public interface UserInfoCacheService {
  15 +
  16 + /**
  17 + * 通过 userID 获取用户信息
  18 + * @param userId 用户唯一 ID
  19 + * @return
  20 + * @throws Exception
  21 + */
  22 + CIMUserInfo loadUserInfoByUserId(Long userId) ;
  23 +
  24 + /**
  25 + * 保存和检查用户登录情况
  26 + * @param userId userId 用户唯一 ID
  27 + * @return true 为可以登录 false 为已经登录
  28 + * @throws Exception
  29 + */
  30 + boolean saveAndCheckUserLoginStatus(Long userId) throws Exception ;
  31 +
  32 + /**
  33 + * 清除用户的登录状态
  34 + * @param userId
  35 + * @throws Exception
  36 + */
  37 + void removeLoginStatus(Long userId) throws Exception ;
  38 +
  39 +
  40 + /**
  41 + *
  42 + * @return 获取所有在线用户
  43 + */
  44 + Set<CIMUserInfo> onlineUser() ;
  45 +}
  1 +package com.crossoverjie.cim.route.service.impl;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.crossoverjie.cim.common.exception.CIMException;
  5 +import com.crossoverjie.cim.common.pojo.CIMUserInfo;
  6 +import com.crossoverjie.cim.route.service.AccountService;
  7 +import com.crossoverjie.cim.route.service.UserInfoCacheService;
  8 +import com.crossoverjie.cim.route.vo.req.ChatReqVO;
  9 +import com.crossoverjie.cim.route.vo.req.LoginReqVO;
  10 +import com.crossoverjie.cim.route.vo.res.CIMServerResVO;
  11 +import com.crossoverjie.cim.route.vo.res.RegisterInfoResVO;
  12 +import okhttp3.*;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.data.redis.connection.RedisConnection;
  17 +import org.springframework.data.redis.core.Cursor;
  18 +import org.springframework.data.redis.core.RedisTemplate;
  19 +import org.springframework.data.redis.core.ScanOptions;
  20 +import org.springframework.stereotype.Service;
  21 +
  22 +import java.io.IOException;
  23 +import java.nio.charset.StandardCharsets;
  24 +import java.util.HashMap;
  25 +import java.util.Map;
  26 +
  27 +import static com.crossoverjie.cim.common.enums.StatusEnum.OFF_LINE;
  28 +import static com.crossoverjie.cim.route.constant.Constant.ACCOUNT_PREFIX;
  29 +import static com.crossoverjie.cim.route.constant.Constant.ROUTE_PREFIX;
  30 +
  31 +/**
  32 + * Function:
  33 + *
  34 + * @author crossoverJie
  35 + * Date: 2018/12/23 21:58
  36 + * @since JDK 1.8
  37 + */
  38 +@Service
  39 +public class AccountServiceRedisImpl implements AccountService {
  40 + private final static Logger LOGGER = LoggerFactory.getLogger(AccountServiceRedisImpl.class);
  41 +
  42 + @Autowired
  43 + private RedisTemplate<String, String> redisTemplate;
  44 +
  45 + @Autowired
  46 + private UserInfoCacheService userInfoCacheService ;
  47 +
  48 + @Autowired
  49 + private OkHttpClient okHttpClient;
  50 +
  51 + private MediaType mediaType = MediaType.parse("application/json");
  52 +
  53 + @Override
  54 + public RegisterInfoResVO register(RegisterInfoResVO info) {
  55 + String key = ACCOUNT_PREFIX + info.getUserId();
  56 +
  57 + String name = redisTemplate.opsForValue().get(info.getUserName());
  58 + if (null == name) {
  59 + //为了方便查询,冗余一份
  60 + redisTemplate.opsForValue().set(key, info.getUserName());
  61 + redisTemplate.opsForValue().set(info.getUserName(), key);
  62 + } else {
  63 + long userId = Long.parseLong(name.split(":")[1]);
  64 + info.setUserId(userId);
  65 + info.setUserName(info.getUserName());
  66 + }
  67 +
  68 + return info;
  69 + }
  70 +
  71 + @Override
  72 + public boolean login(LoginReqVO loginReqVO) throws Exception {
  73 + //再去Redis里查询
  74 + String key = ACCOUNT_PREFIX + loginReqVO.getUserId();
  75 + String userName = redisTemplate.opsForValue().get(key);
  76 + if (null == userName) {
  77 + return false;
  78 + }
  79 +
  80 + if (!userName.equals(loginReqVO.getUserName())) {
  81 + return false;
  82 + }
  83 +
  84 + //登录成功,保存登录状态
  85 + boolean status = userInfoCacheService.saveAndCheckUserLoginStatus(loginReqVO.getUserId());
  86 + if (status == false){
  87 + //重复登录
  88 + return false;
  89 + }
  90 +
  91 + return true;
  92 + }
  93 +
  94 + @Override
  95 + public void saveRouteInfo(LoginReqVO loginReqVO, String msg) throws Exception {
  96 + String key = ROUTE_PREFIX + loginReqVO.getUserId();
  97 + redisTemplate.opsForValue().set(key, msg);
  98 + }
  99 +
  100 + @Override
  101 + public Map<Long, CIMServerResVO> loadRouteRelated() {
  102 +
  103 + Map<Long, CIMServerResVO> routes = new HashMap<>(64);
  104 +
  105 + RedisConnection connection = redisTemplate.getConnectionFactory().getConnection();
  106 + ScanOptions options = ScanOptions.scanOptions()
  107 + .match(ROUTE_PREFIX + "*")
  108 + .build();
  109 + Cursor<byte[]> scan = connection.scan(options);
  110 +
  111 + while (scan.hasNext()) {
  112 + byte[] next = scan.next();
  113 + String key = new String(next, StandardCharsets.UTF_8);
  114 + LOGGER.info("key={}", key);
  115 + parseServerInfo(routes, key);
  116 +
  117 + }
  118 +
  119 + return routes;
  120 + }
  121 +
  122 + @Override
  123 + public CIMServerResVO loadRouteRelatedByUserId(Long userId) {
  124 + String value = redisTemplate.opsForValue().get(ROUTE_PREFIX + userId);
  125 +
  126 + if (value == null){
  127 + throw new CIMException(OFF_LINE) ;
  128 + }
  129 +
  130 + String[] server = value.split(":");
  131 + CIMServerResVO cimServerResVO = new CIMServerResVO(server[0], Integer.parseInt(server[1]), Integer.parseInt(server[2]));
  132 + return cimServerResVO;
  133 + }
  134 +
  135 + private void parseServerInfo(Map<Long, CIMServerResVO> routes, String key) {
  136 + long userId = Long.valueOf(key.split(":")[1]);
  137 + String value = redisTemplate.opsForValue().get(key);
  138 + String[] server = value.split(":");
  139 + CIMServerResVO cimServerResVO = new CIMServerResVO(server[0], Integer.parseInt(server[1]), Integer.parseInt(server[2]));
  140 + routes.put(userId, cimServerResVO);
  141 + }
  142 +
  143 +
  144 + @Override
  145 + public void pushMsg(String url, long sendUserId, ChatReqVO groupReqVO) throws Exception {
  146 + CIMUserInfo cimUserInfo = userInfoCacheService.loadUserInfoByUserId(sendUserId);
  147 +
  148 + JSONObject jsonObject = new JSONObject();
  149 + jsonObject.put("msg", cimUserInfo.getUserName() + ":【" + groupReqVO.getMsg() + "】");
  150 + jsonObject.put("userId", groupReqVO.getUserId());
  151 + RequestBody requestBody = RequestBody.create(mediaType, jsonObject.toString());
  152 +
  153 + Request request = new Request.Builder()
  154 + .url(url)
  155 + .post(requestBody)
  156 + .build();
  157 +
  158 + Response response = okHttpClient.newCall(request).execute();
  159 + if (!response.isSuccessful()) {
  160 + throw new IOException("Unexpected code " + response);
  161 + }
  162 + }
  163 +
  164 + @Override
  165 + public void offLine(Long userId) throws Exception {
  166 + //删除路由
  167 + redisTemplate.delete(ROUTE_PREFIX + userId) ;
  168 +
  169 + //删除登录状态
  170 + userInfoCacheService.removeLoginStatus(userId);
  171 + }
  172 +}
  1 +package com.crossoverjie.cim.route.service.impl;
  2 +
  3 +import com.crossoverjie.cim.common.pojo.CIMUserInfo;
  4 +import com.crossoverjie.cim.route.service.UserInfoCacheService;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.data.redis.core.RedisTemplate;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +import java.util.HashSet;
  10 +import java.util.Map;
  11 +import java.util.Set;
  12 +import java.util.concurrent.ConcurrentHashMap;
  13 +
  14 +import static com.crossoverjie.cim.route.constant.Constant.ACCOUNT_PREFIX;
  15 +import static com.crossoverjie.cim.route.constant.Constant.LOGIN_STATUS_PREFIX;
  16 +
  17 +/**
  18 + * Function:
  19 + *
  20 + * @author crossoverJie
  21 + * Date: 2018/12/24 11:06
  22 + * @since JDK 1.8
  23 + */
  24 +@Service
  25 +public class UserInfoCacheServiceImpl implements UserInfoCacheService {
  26 +
  27 + /**
  28 + * 本地缓存,为了防止内存撑爆,后期可换为 LRU。
  29 + */
  30 + private final static Map<Long,CIMUserInfo> USER_INFO_MAP = new ConcurrentHashMap<>(64) ;
  31 +
  32 + @Autowired
  33 + private RedisTemplate<String,String> redisTemplate ;
  34 +
  35 + @Override
  36 + public CIMUserInfo loadUserInfoByUserId(Long userId) {
  37 +
  38 + //优先从本地缓存获取
  39 + CIMUserInfo cimUserInfo = USER_INFO_MAP.get(userId);
  40 + if (cimUserInfo != null){
  41 + return cimUserInfo ;
  42 + }
  43 +
  44 + //load redis
  45 + String sendUserName = redisTemplate.opsForValue().get(ACCOUNT_PREFIX + userId);
  46 + if (sendUserName != null){
  47 + cimUserInfo = new CIMUserInfo(userId,sendUserName) ;
  48 + USER_INFO_MAP.put(userId,cimUserInfo) ;
  49 + }
  50 +
  51 + return cimUserInfo;
  52 + }
  53 +
  54 + @Override
  55 + public boolean saveAndCheckUserLoginStatus(Long userId) throws Exception {
  56 +
  57 + Long add = redisTemplate.opsForSet().add(LOGIN_STATUS_PREFIX, userId.toString());
  58 + if (add == 0){
  59 + return false ;
  60 + }else {
  61 + return true ;
  62 + }
  63 + }
  64 +
  65 + @Override
  66 + public void removeLoginStatus(Long userId) throws Exception {
  67 + redisTemplate.opsForSet().remove(LOGIN_STATUS_PREFIX,userId.toString()) ;
  68 + }
  69 +
  70 + @Override
  71 + public Set<CIMUserInfo> onlineUser() {
  72 + Set<CIMUserInfo> set = null ;
  73 + Set<String> members = redisTemplate.opsForSet().members(LOGIN_STATUS_PREFIX);
  74 + for (String member : members) {
  75 + if (set == null){
  76 + set = new HashSet<>(64) ;
  77 + }
  78 + CIMUserInfo cimUserInfo = loadUserInfoByUserId(Long.valueOf(member)) ;
  79 + set.add(cimUserInfo) ;
  80 + }
  81 +
  82 + return set;
  83 + }
  84 +
  85 +}
1 -package com.crossoverjie.netty.action.util; 1 +package com.crossoverjie.cim.route.util;
2 2
3 import org.springframework.beans.BeansException; 3 import org.springframework.beans.BeansException;
4 import org.springframework.context.ApplicationContext; 4 import org.springframework.context.ApplicationContext;
  1 +package com.crossoverjie.cim.route.vo.req;
  2 +
  3 +import com.crossoverjie.cim.common.req.BaseRequest;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +
  6 +import javax.validation.constraints.NotNull;
  7 +
  8 +/**
  9 + * Function: Google Protocol 编解码发送
  10 + *
  11 + * @author crossoverJie
  12 + * Date: 2018/05/21 15:56
  13 + * @since JDK 1.8
  14 + */
  15 +public class ChatReqVO extends BaseRequest {
  16 +
  17 + @NotNull(message = "userId 不能为空")
  18 + @ApiModelProperty(required = true, value = "userId", example = "1545574049323")
  19 + private Long userId ;
  20 +
  21 +
  22 + @NotNull(message = "msg 不能为空")
  23 + @ApiModelProperty(required = true, value = "msg", example = "hello")
  24 + private String msg ;
  25 +
  26 + public ChatReqVO() {
  27 + }
  28 +
  29 + public ChatReqVO(Long userId, String msg) {
  30 + this.userId = userId;
  31 + this.msg = msg;
  32 + }
  33 +
  34 + public String getMsg() {
  35 + return msg;
  36 + }
  37 +
  38 + public void setMsg(String msg) {
  39 + this.msg = msg;
  40 + }
  41 +
  42 + public Long getUserId() {
  43 + return userId;
  44 + }
  45 +
  46 + public void setUserId(Long userId) {
  47 + this.userId = userId;
  48 + }
  49 +
  50 + @Override
  51 + public String toString() {
  52 + return "GroupReqVO{" +
  53 + "userId=" + userId +
  54 + ", msg='" + msg + '\'' +
  55 + "} " + super.toString();
  56 + }
  57 +}
  1 +package com.crossoverjie.cim.route.vo.req;
  2 +
  3 +import com.crossoverjie.cim.common.req.BaseRequest;
  4 +
  5 +/**
  6 + * Function:
  7 + *
  8 + * @author crossoverJie
  9 + * Date: 2018/12/23 22:30
  10 + * @since JDK 1.8
  11 + */
  12 +public class LoginReqVO extends BaseRequest{
  13 + private Long userId ;
  14 + private String userName ;
  15 +
  16 + public Long getUserId() {
  17 + return userId;
  18 + }
  19 +
  20 + public void setUserId(Long userId) {
  21 + this.userId = userId;
  22 + }
  23 +
  24 + public String getUserName() {
  25 + return userName;
  26 + }
  27 +
  28 + public void setUserName(String userName) {
  29 + this.userName = userName;
  30 + }
  31 +
  32 + @Override
  33 + public String toString() {
  34 + return "LoginReqVO{" +
  35 + "userId=" + userId +
  36 + ", userName='" + userName + '\'' +
  37 + "} " + super.toString();
  38 + }
  39 +}
  1 +package com.crossoverjie.cim.route.vo.req;
  2 +
  3 +import com.crossoverjie.cim.common.req.BaseRequest;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +
  6 +import javax.validation.constraints.NotNull;
  7 +
  8 +/**
  9 + * Function: 单聊请求
  10 + *
  11 + * @author crossoverJie
  12 + * Date: 2018/05/21 15:56
  13 + * @since JDK 1.8
  14 + */
  15 +public class P2PReqVO extends BaseRequest {
  16 +
  17 + @NotNull(message = "userId 不能为空")
  18 + @ApiModelProperty(required = true, value = "消息发送者的 userId", example = "1545574049323")
  19 + private Long userId ;
  20 +
  21 +
  22 + @NotNull(message = "userId 不能为空")
  23 + @ApiModelProperty(required = true, value = "消息接收者的 userId", example = "1545574049323")
  24 + private Long receiveUserId ;
  25 +
  26 +
  27 +
  28 +
  29 + @NotNull(message = "msg 不能为空")
  30 + @ApiModelProperty(required = true, value = "msg", example = "hello")
  31 + private String msg ;
  32 +
  33 + public P2PReqVO() {
  34 + }
  35 +
  36 + public P2PReqVO(Long userId, Long receiveUserId, String msg) {
  37 + this.userId = userId;
  38 + this.receiveUserId = receiveUserId;
  39 + this.msg = msg;
  40 + }
  41 +
  42 + public Long getReceiveUserId() {
  43 + return receiveUserId;
  44 + }
  45 +
  46 + public void setReceiveUserId(Long receiveUserId) {
  47 + this.receiveUserId = receiveUserId;
  48 + }
  49 +
  50 + public String getMsg() {
  51 + return msg;
  52 + }
  53 +
  54 + public void setMsg(String msg) {
  55 + this.msg = msg;
  56 + }
  57 +
  58 + public Long getUserId() {
  59 + return userId;
  60 + }
  61 +
  62 + public void setUserId(Long userId) {
  63 + this.userId = userId;
  64 + }
  65 +
  66 + @Override
  67 + public String toString() {
  68 + return "GroupReqVO{" +
  69 + "userId=" + userId +
  70 + ", msg='" + msg + '\'' +
  71 + "} " + super.toString();
  72 + }
  73 +}
  1 +package com.crossoverjie.cim.route.vo.req;
  2 +
  3 +import com.crossoverjie.cim.common.req.BaseRequest;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +
  6 +import javax.validation.constraints.NotNull;
  7 +
  8 +/**
  9 + * Function:
  10 + *
  11 + * @author crossoverJie
  12 + * Date: 2018/12/23 22:04
  13 + * @since JDK 1.8
  14 + */
  15 +public class RegisterInfoReqVO extends BaseRequest {
  16 +
  17 + @NotNull(message = "用户名不能为空")
  18 + @ApiModelProperty(required = true, value = "userName", example = "zhangsan")
  19 + private String userName ;
  20 +
  21 + public String getUserName() {
  22 + return userName;
  23 + }
  24 +
  25 + public void setUserName(String userName) {
  26 + this.userName = userName;
  27 + }
  28 +
  29 + @Override
  30 + public String toString() {
  31 + return "RegisterInfoReqVO{" +
  32 + "userName='" + userName + '\'' +
  33 + "} " + super.toString();
  34 + }
  35 +}
1 -package com.crossoverjie.netty.action.client.vo.req; 1 +package com.crossoverjie.cim.route.vo.req;
2 2
3 -import com.crossoverjie.netty.action.common.req.BaseRequest; 3 +import com.crossoverjie.cim.common.req.BaseRequest;
4 import io.swagger.annotations.ApiModelProperty; 4 import io.swagger.annotations.ApiModelProperty;
5 5
6 import javax.validation.constraints.NotNull; 6 import javax.validation.constraints.NotNull;
  1 +package com.crossoverjie.cim.route.vo.res;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +/**
  6 + * Function:
  7 + *
  8 + * @author crossoverJie
  9 + * Date: 2018/12/23 00:43
  10 + * @since JDK 1.8
  11 + */
  12 +public class CIMServerResVO implements Serializable {
  13 +
  14 + private String ip ;
  15 + private Integer cimServerPort;
  16 + private Integer httpPort;
  17 +
  18 + public CIMServerResVO(String ip, Integer cimServerPort, Integer httpPort) {
  19 + this.ip = ip;
  20 + this.cimServerPort = cimServerPort;
  21 + this.httpPort = httpPort;
  22 + }
  23 +
  24 + public String getIp() {
  25 + return ip;
  26 + }
  27 +
  28 + public void setIp(String ip) {
  29 + this.ip = ip;
  30 + }
  31 +
  32 + public Integer getCimServerPort() {
  33 + return cimServerPort;
  34 + }
  35 +
  36 + public void setCimServerPort(Integer cimServerPort) {
  37 + this.cimServerPort = cimServerPort;
  38 + }
  39 +
  40 + public Integer getHttpPort() {
  41 + return httpPort;
  42 + }
  43 +
  44 + public void setHttpPort(Integer httpPort) {
  45 + this.httpPort = httpPort;
  46 + }
  47 +}
  1 +package com.crossoverjie.cim.route.vo.res;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +/**
  6 + * Function:
  7 + *
  8 + * @author crossoverJie
  9 + * Date: 2018/12/23 21:54
  10 + * @since JDK 1.8
  11 + */
  12 +public class RegisterInfoResVO implements Serializable{
  13 + private Long userId ;
  14 + private String userName ;
  15 +
  16 + public RegisterInfoResVO(Long userId, String userName) {
  17 + this.userId = userId;
  18 + this.userName = userName;
  19 + }
  20 +
  21 + public Long getUserId() {
  22 + return userId;
  23 + }
  24 +
  25 + public void setUserId(Long userId) {
  26 + this.userId = userId;
  27 + }
  28 +
  29 + public String getUserName() {
  30 + return userName;
  31 + }
  32 +
  33 + public void setUserName(String userName) {
  34 + this.userName = userName;
  35 + }
  36 +
  37 + @Override
  38 + public String toString() {
  39 + return "RegisterInfo{" +
  40 + "userId=" + userId +
  41 + ", userName='" + userName + '\'' +
  42 + '}';
  43 + }
  44 +}
  1 +spring.application.name=cim-forward-route
  2 +
  3 +# web port
  4 +server.port=8083
  5 +
  6 +# 是否打开swagger
  7 +swagger.enable = true
  8 +
  9 +logging.level.root=info
  10 +
  11 +
  12 +# 关闭健康检查权限
  13 +management.security.enabled=false
  14 +
  15 +# zk 地址
  16 +app.zk.addr=47.98.194.60:2182
  17 +
  18 +# zk 注册根节点
  19 +app.zk.root=/route
  20 +
  21 +
  22 +
  23 +# Redis 配置
  24 +spring.redis.host=47.98.194.60
  25 +spring.redis.port=6379
  26 +spring.redis.pool.max-active=100
  27 +spring.redis.pool.max-idle=100
  28 +spring.redis.pool.max-wait=1000
  29 +spring.redis.pool.min-idle=10
  30 +