作者 crossoverJie

:recycle: Refactoring code.联调成功

正在显示 21 个修改的文件 包含 392 行增加917 行删除
package com.crossoverjie.cim.client.client;
import com.alibaba.fastjson.JSON;
import com.crossoverjie.cim.client.init.CustomerHandleInitializer;
import com.crossoverjie.cim.client.init.CIMClientHandleInitializer;
import com.crossoverjie.cim.client.service.RouteRequest;
import com.crossoverjie.cim.client.vo.req.GoogleProtocolVO;
import com.crossoverjie.cim.common.protocol.BaseRequestProto;
import com.crossoverjie.cim.client.vo.res.CIMServerResVO;
import com.crossoverjie.cim.common.pojo.CustomProtocol;
import com.crossoverjie.cim.common.protocol.CIMRequestProto;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
... ... @@ -16,6 +18,7 @@ import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
... ... @@ -44,17 +47,24 @@ public class CIMClient {
private SocketChannel channel;
@Autowired
private RouteRequest routeRequest ;
@PostConstruct
public void start() throws InterruptedException {
public void start() throws Exception {
//获取可以使用的服务器 ip+port
CIMServerResVO.ServerInfo cimServer = routeRequest.getCIMServer();
LOGGER.info("cimServer=[{}]",cimServer.toString());
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group)
.channel(NioSocketChannel.class)
.handler(new CustomerHandleInitializer())
.handler(new CIMClientHandleInitializer())
;
ChannelFuture future = bootstrap.connect(host, nettyPort).sync();
ChannelFuture future = bootstrap.connect(cimServer.getIp(), cimServer.getPort()).sync();
if (future.isSuccess()) {
LOGGER.info("启动 Netty 成功");
LOGGER.info("启动 cim client 成功");
}
channel = (SocketChannel) future.channel();
}
... ... @@ -91,7 +101,7 @@ public class CIMClient {
*/
public void sendGoogleProtocolMsg(GoogleProtocolVO googleProtocolVO) {
BaseRequestProto.RequestProtocol protocol = BaseRequestProto.RequestProtocol.newBuilder()
CIMRequestProto.CIMReqProtocol protocol = CIMRequestProto.CIMReqProtocol.newBuilder()
.setRequestId(googleProtocolVO.getRequestId())
.setReqMsg(googleProtocolVO.getMsg())
.build();
... ...
package com.crossoverjie.cim.client.config;
import com.crossoverjie.cim.common.protocol.BaseRequestProto;
import com.crossoverjie.cim.common.protocol.CIMRequestProto;
import okhttp3.OkHttpClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
... ... @@ -27,8 +27,8 @@ public class BeanConfig {
* @return
*/
@Bean(value = "heartBeat")
public BaseRequestProto.RequestProtocol heartBeat() {
BaseRequestProto.RequestProtocol heart = BaseRequestProto.RequestProtocol.newBuilder()
public CIMRequestProto.CIMReqProtocol heartBeat() {
CIMRequestProto.CIMReqProtocol heart = CIMRequestProto.CIMReqProtocol.newBuilder()
.setRequestId(requestId)
.setReqMsg("ping")
.build();
... ...
package com.crossoverjie.cim.client.handle;
import com.crossoverjie.cim.client.util.SpringBeanFactory;
import com.crossoverjie.cim.common.protocol.BaseRequestProto;
import com.crossoverjie.cim.common.protocol.BaseResponseProto;
import io.netty.channel.ChannelFutureListener;
import com.crossoverjie.cim.common.protocol.CIMRequestProto;
import com.crossoverjie.cim.common.protocol.CIMResponseProto;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.timeout.IdleState;
... ... @@ -18,9 +18,10 @@ import org.slf4j.LoggerFactory;
* Date: 16/02/2018 18:09
* @since JDK 1.8
*/
public class EchoClientHandle extends SimpleChannelInboundHandler<BaseResponseProto.ResponseProtocol> {
@ChannelHandler.Sharable
public class CIMClientHandle extends SimpleChannelInboundHandler<CIMResponseProto.CIMResProtocol> {
private final static Logger LOGGER = LoggerFactory.getLogger(EchoClientHandle.class);
private final static Logger LOGGER = LoggerFactory.getLogger(CIMClientHandle.class);
... ... @@ -34,8 +35,8 @@ public class EchoClientHandle extends SimpleChannelInboundHandler<BaseResponsePr
if (idleStateEvent.state() == IdleState.WRITER_IDLE){
LOGGER.info("已经 10 秒没有发送信息!");
//向服务端发送消息
BaseRequestProto.RequestProtocol heartBeat = SpringBeanFactory.getBean("heartBeat", BaseRequestProto.RequestProtocol.class);
ctx.writeAndFlush(heartBeat).addListener(ChannelFutureListener.CLOSE_ON_FAILURE) ;
CIMRequestProto.CIMReqProtocol heartBeat = SpringBeanFactory.getBean("heartBeat", CIMRequestProto.CIMReqProtocol.class);
ctx.writeAndFlush(heartBeat) ;
}
... ... @@ -48,11 +49,11 @@ public class EchoClientHandle extends SimpleChannelInboundHandler<BaseResponsePr
public void channelActive(ChannelHandlerContext ctx) throws Exception {
//客户端和服务端建立连接时调用
LOGGER.info("已经建立了联系。。");
LOGGER.info("cim server connect success");
}
@Override
protected void channelRead0(ChannelHandlerContext channelHandlerContext, BaseResponseProto.ResponseProtocol responseProtocol) throws Exception {
protected void channelRead0(ChannelHandlerContext channelHandlerContext, CIMResponseProto.CIMResProtocol responseProtocol) throws Exception {
//从服务端收到消息时被调用
//LOGGER.info("客户端收到消息={}",in.toString(CharsetUtil.UTF_8)) ;
... ...
package com.crossoverjie.cim.client.init;
import com.crossoverjie.cim.client.handle.EchoClientHandle;
import com.crossoverjie.cim.common.protocol.BaseResponseProto;
import com.crossoverjie.cim.client.handle.CIMClientHandle;
import com.crossoverjie.cim.common.protocol.CIMResponseProto;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.protobuf.ProtobufDecoder;
... ... @@ -17,7 +17,10 @@ import io.netty.handler.timeout.IdleStateHandler;
* Date: 23/02/2018 22:47
* @since JDK 1.8
*/
public class CustomerHandleInitializer extends ChannelInitializer<Channel> {
public class CIMClientHandleInitializer extends ChannelInitializer<Channel> {
private final CIMClientHandle cimClientHandle = new CIMClientHandle();
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline()
... ... @@ -30,14 +33,12 @@ public class CustomerHandleInitializer extends ChannelInitializer<Channel> {
// google Protobuf 编解码
//拆包解码
.addLast(new ProtobufVarint32FrameDecoder())
.addLast(new ProtobufDecoder(BaseResponseProto.ResponseProtocol.getDefaultInstance()))
.addLast(new ProtobufDecoder(CIMResponseProto.CIMResProtocol.getDefaultInstance()))
//
//拆包编码
.addLast(new ProtobufVarint32LengthFieldPrepender())
.addLast(new ProtobufEncoder())
.addLast(new EchoClientHandle())
.addLast(cimClientHandle)
;
}
}
... ...
package com.crossoverjie.cim.client.service;
import com.crossoverjie.cim.client.vo.res.CIMServerResVO;
/**
* Function:
*
... ... @@ -15,4 +17,11 @@ public interface RouteRequest {
* @throws Exception
*/
void sendGroupMsg(String msg) throws Exception;
/**
* 获取服务器
* @return 服务ip+port
* @throws Exception
*/
CIMServerResVO.ServerInfo getCIMServer() throws Exception;
}
... ...
package com.crossoverjie.cim.client.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.crossoverjie.cim.client.service.RouteRequest;
import com.crossoverjie.cim.client.vo.res.CIMServerResVO;
import com.crossoverjie.cim.common.enums.StatusEnum;
import okhttp3.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
... ... @@ -19,14 +24,18 @@ import java.io.IOException;
@Service
public class RouteRequestImpl implements RouteRequest {
private final static Logger LOGGER = LoggerFactory.getLogger(RouteRequestImpl.class);
@Autowired
private OkHttpClient okHttpClient ;
private MediaType mediaType = MediaType.parse("application/json");
@Value("${cim.route.request.url}")
private String routeRequestUrl ;
@Value("${cim.group.route.request.url}")
private String groupRouteRequestUrl;
@Value("${cim.server.route.request.url}")
private String serverRouteRequestUrl;
@Override
public void sendGroupMsg(String msg) throws Exception {
... ... @@ -36,7 +45,7 @@ public class RouteRequestImpl implements RouteRequest {
RequestBody requestBody = RequestBody.create(mediaType,jsonObject.toString());
Request request = new Request.Builder()
.url(routeRequestUrl)
.url(groupRouteRequestUrl)
.post(requestBody)
.build();
... ... @@ -45,4 +54,29 @@ public class RouteRequestImpl implements RouteRequest {
throw new IOException("Unexpected code " + response);
}
}
@Override
public CIMServerResVO.ServerInfo getCIMServer() throws Exception {
JSONObject jsonObject = new JSONObject();
RequestBody requestBody = RequestBody.create(mediaType,jsonObject.toString());
Request request = new Request.Builder()
.url(serverRouteRequestUrl)
.post(requestBody)
.build();
Response response = okHttpClient.newCall(request).execute() ;
if (!response.isSuccessful()){
throw new IOException("Unexpected code " + response);
}
String json = response.body().string();
CIMServerResVO cimServerResVO = JSON.parseObject(json, CIMServerResVO.class);
if (!cimServerResVO.getCode().equals(StatusEnum.SUCCESS.getCode())){
throw new RuntimeException("route server exception code=" + cimServerResVO.getCode()) ;
}
return cimServerResVO.getDataBody();
}
}
... ...
package com.crossoverjie.cim.client.vo.res;
import java.io.Serializable;
/**
* Function:
*
* @author crossoverJie
* Date: 2018/12/23 00:43
* @since JDK 1.8
*/
public class CIMServerResVO implements Serializable {
/**
* code : 9000
* message : 成功
* reqNo : null
* dataBody : {"ip":"127.0.0.1","port":8081}
*/
private String code;
private String message;
private Object reqNo;
private ServerInfo dataBody;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Object getReqNo() {
return reqNo;
}
public void setReqNo(Object reqNo) {
this.reqNo = reqNo;
}
public ServerInfo getDataBody() {
return dataBody;
}
public void setDataBody(ServerInfo dataBody) {
this.dataBody = dataBody;
}
public static class ServerInfo {
/**
* ip : 127.0.0.1
* port : 8081
*/
private String ip;
private int port;
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
@Override
public String toString() {
return "DataBodyBean{" +
"ip='" + ip + '\'' +
", port=" + port +
'}';
}
}
@Override
public String toString() {
return "CIMServerResVO{" +
"code='" + code + '\'' +
", message='" + message + '\'' +
", reqNo=" + reqNo +
", dataBody=" + dataBody +
'}';
}
}
... ...
... ... @@ -11,8 +11,11 @@ netty.server.port=11211
logging.level.root=info
# 路由地址
cim.route.request.url=http://localhost:8083/groupRoute
# 群发消息
cim.group.route.request.url=http://localhost:8083/groupRoute
# 获取服务器ip+port
cim.server.route.request.url=http://localhost:8083/getCIMServer
# 客户端唯一ID
client.request.id=100
... ...
package com.crossoverjie.cim.server.test;
import com.alibaba.fastjson.JSON;
import com.crossoverjie.cim.client.vo.res.CIMServerResVO;
import org.junit.Test;
/**
* Function:
*
* @author crossoverJie
* Date: 22/05/2018 18:44
* @since JDK 1.8
*/
public class CommonTest {
@Test
public void test() {
String json = "{\"code\":\"9000\",\"message\":\"成功\",\"reqNo\":null,\"dataBody\":{\"ip\":\"127.0.0.1\",\"port\":8081}}" ;
CIMServerResVO cimServerResVO = JSON.parseObject(json, CIMServerResVO.class);
System.out.println(cimServerResVO.toString());
}
}
... ...
... ... @@ -8,6 +8,7 @@
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<version>1.0.1-SNAPSHOT</version>
<artifactId>cim-common</artifactId>
... ...
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: BaseProtoc.proto
package com.crossoverjie.cim.common.protocol;
public final class BaseProto {
private BaseProto() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface ProtocolOrBuilder extends
// @@protoc_insertion_point(interface_extends:protocol.Protocol)
com.google.protobuf.MessageOrBuilder {
/**
* <code>required int32 header = 2;</code>
*/
boolean hasHeader();
/**
* <code>required int32 header = 2;</code>
*/
int getHeader();
/**
* <code>required string msg = 1;</code>
*/
boolean hasMsg();
/**
* <code>required string msg = 1;</code>
*/
String getMsg();
/**
* <code>required string msg = 1;</code>
*/
com.google.protobuf.ByteString
getMsgBytes();
}
/**
* Protobuf type {@code protocol.Protocol}
*/
public static final class Protocol extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:protocol.Protocol)
ProtocolOrBuilder {
private static final long serialVersionUID = 0L;
// Use Protocol.newBuilder() to construct.
private Protocol(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private Protocol() {
header_ = 0;
msg_ = "";
}
@Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private Protocol(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new NullPointerException();
}
int mutable_bitField0_ = 0;
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
case 10: {
com.google.protobuf.ByteString bs = input.readBytes();
bitField0_ |= 0x00000002;
msg_ = bs;
break;
}
case 16: {
bitField0_ |= 0x00000001;
header_ = input.readInt32();
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return BaseProto.internal_static_protocol_Protocol_descriptor;
}
protected FieldAccessorTable
internalGetFieldAccessorTable() {
return BaseProto.internal_static_protocol_Protocol_fieldAccessorTable
.ensureFieldAccessorsInitialized(
Protocol.class, Builder.class);
}
private int bitField0_;
public static final int HEADER_FIELD_NUMBER = 2;
private int header_;
/**
* <code>required int32 header = 2;</code>
*/
public boolean hasHeader() {
return ((bitField0_ & 0x00000001) == 0x00000001);
}
/**
* <code>required int32 header = 2;</code>
*/
public int getHeader() {
return header_;
}
public static final int MSG_FIELD_NUMBER = 1;
private volatile Object msg_;
/**
* <code>required string msg = 1;</code>
*/
public boolean hasMsg() {
return ((bitField0_ & 0x00000002) == 0x00000002);
}
/**
* <code>required string msg = 1;</code>
*/
public String getMsg() {
Object ref = msg_;
if (ref instanceof String) {
return (String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
msg_ = s;
}
return s;
}
}
/**
* <code>required string msg = 1;</code>
*/
public com.google.protobuf.ByteString
getMsgBytes() {
Object ref = msg_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(String) ref);
msg_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
if (!hasHeader()) {
memoizedIsInitialized = 0;
return false;
}
if (!hasMsg()) {
memoizedIsInitialized = 0;
return false;
}
memoizedIsInitialized = 1;
return true;
}
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (((bitField0_ & 0x00000002) == 0x00000002)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, msg_);
}
if (((bitField0_ & 0x00000001) == 0x00000001)) {
output.writeInt32(2, header_);
}
unknownFields.writeTo(output);
}
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (((bitField0_ & 0x00000002) == 0x00000002)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, msg_);
}
if (((bitField0_ & 0x00000001) == 0x00000001)) {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(2, header_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof Protocol)) {
return super.equals(obj);
}
Protocol other = (Protocol) obj;
boolean result = true;
result = result && (hasHeader() == other.hasHeader());
if (hasHeader()) {
result = result && (getHeader()
== other.getHeader());
}
result = result && (hasMsg() == other.hasMsg());
if (hasMsg()) {
result = result && getMsg()
.equals(other.getMsg());
}
result = result && unknownFields.equals(other.unknownFields);
return result;
}
@Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
if (hasHeader()) {
hash = (37 * hash) + HEADER_FIELD_NUMBER;
hash = (53 * hash) + getHeader();
}
if (hasMsg()) {
hash = (37 * hash) + MSG_FIELD_NUMBER;
hash = (53 * hash) + getMsg().hashCode();
}
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static Protocol parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static Protocol parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static Protocol parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static Protocol parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static Protocol parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static Protocol parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static Protocol parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static Protocol parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static Protocol parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static Protocol parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static Protocol parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static Protocol parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(Protocol prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@Override
protected Builder newBuilderForType(
BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* Protobuf type {@code protocol.Protocol}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:protocol.Protocol)
ProtocolOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return BaseProto.internal_static_protocol_Protocol_descriptor;
}
protected FieldAccessorTable
internalGetFieldAccessorTable() {
return BaseProto.internal_static_protocol_Protocol_fieldAccessorTable
.ensureFieldAccessorsInitialized(
Protocol.class, Builder.class);
}
// Construct using com.crossoverjie.netty.action.protocol.BaseProto.Protocol.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
public Builder clear() {
super.clear();
header_ = 0;
bitField0_ = (bitField0_ & ~0x00000001);
msg_ = "";
bitField0_ = (bitField0_ & ~0x00000002);
return this;
}
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return BaseProto.internal_static_protocol_Protocol_descriptor;
}
public Protocol getDefaultInstanceForType() {
return Protocol.getDefaultInstance();
}
public Protocol build() {
Protocol result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
public Protocol buildPartial() {
Protocol result = new Protocol(this);
int from_bitField0_ = bitField0_;
int to_bitField0_ = 0;
if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
to_bitField0_ |= 0x00000001;
}
result.header_ = header_;
if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
to_bitField0_ |= 0x00000002;
}
result.msg_ = msg_;
result.bitField0_ = to_bitField0_;
onBuilt();
return result;
}
public Builder clone() {
return (Builder) super.clone();
}
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
Object value) {
return (Builder) super.setField(field, value);
}
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return (Builder) super.clearField(field);
}
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return (Builder) super.clearOneof(oneof);
}
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, Object value) {
return (Builder) super.setRepeatedField(field, index, value);
}
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
Object value) {
return (Builder) super.addRepeatedField(field, value);
}
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof Protocol) {
return mergeFrom((Protocol)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(Protocol other) {
if (other == Protocol.getDefaultInstance()) return this;
if (other.hasHeader()) {
setHeader(other.getHeader());
}
if (other.hasMsg()) {
bitField0_ |= 0x00000002;
msg_ = other.msg_;
onChanged();
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
public final boolean isInitialized() {
if (!hasHeader()) {
return false;
}
if (!hasMsg()) {
return false;
}
return true;
}
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
Protocol parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (Protocol) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int bitField0_;
private int header_ ;
/**
* <code>required int32 header = 2;</code>
*/
public boolean hasHeader() {
return ((bitField0_ & 0x00000001) == 0x00000001);
}
/**
* <code>required int32 header = 2;</code>
*/
public int getHeader() {
return header_;
}
/**
* <code>required int32 header = 2;</code>
*/
public Builder setHeader(int value) {
bitField0_ |= 0x00000001;
header_ = value;
onChanged();
return this;
}
/**
* <code>required int32 header = 2;</code>
*/
public Builder clearHeader() {
bitField0_ = (bitField0_ & ~0x00000001);
header_ = 0;
onChanged();
return this;
}
private Object msg_ = "";
/**
* <code>required string msg = 1;</code>
*/
public boolean hasMsg() {
return ((bitField0_ & 0x00000002) == 0x00000002);
}
/**
* <code>required string msg = 1;</code>
*/
public String getMsg() {
Object ref = msg_;
if (!(ref instanceof String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
msg_ = s;
}
return s;
} else {
return (String) ref;
}
}
/**
* <code>required string msg = 1;</code>
*/
public com.google.protobuf.ByteString
getMsgBytes() {
Object ref = msg_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(String) ref);
msg_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>required string msg = 1;</code>
*/
public Builder setMsg(
String value) {
if (value == null) {
throw new NullPointerException();
}
bitField0_ |= 0x00000002;
msg_ = value;
onChanged();
return this;
}
/**
* <code>required string msg = 1;</code>
*/
public Builder clearMsg() {
bitField0_ = (bitField0_ & ~0x00000002);
msg_ = getDefaultInstance().getMsg();
onChanged();
return this;
}
/**
* <code>required string msg = 1;</code>
*/
public Builder setMsgBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
bitField0_ |= 0x00000002;
msg_ = value;
onChanged();
return this;
}
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:protocol.Protocol)
}
// @@protoc_insertion_point(class_scope:protocol.Protocol)
private static final Protocol DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new Protocol();
}
public static Protocol getDefaultInstance() {
return DEFAULT_INSTANCE;
}
@Deprecated public static final com.google.protobuf.Parser<Protocol>
PARSER = new com.google.protobuf.AbstractParser<Protocol>() {
public Protocol parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new Protocol(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<Protocol> parser() {
return PARSER;
}
@Override
public com.google.protobuf.Parser<Protocol> getParserForType() {
return PARSER;
}
public Protocol getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_protocol_Protocol_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_protocol_Protocol_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
String[] descriptorData = {
"\n\020BaseProtoc.proto\022\010protocol\"\'\n\010Protocol" +
"\022\016\n\006header\030\002 \002(\005\022\013\n\003msg\030\001 \002(\tB3\n&com.cro" +
"ssoverjie.netty.action.protocolB\tBasePro" +
"to"
};
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
public com.google.protobuf.ExtensionRegistry assignDescriptors(
com.google.protobuf.Descriptors.FileDescriptor root) {
descriptor = root;
return null;
}
};
com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
}, assigner);
internal_static_protocol_Protocol_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_protocol_Protocol_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_protocol_Protocol_descriptor,
new String[] { "Header", "Msg", });
}
// @@protoc_insertion_point(outer_class_scope)
}
... ... @@ -3,8 +3,8 @@
package com.crossoverjie.cim.common.protocol;
public final class BaseRequestProto {
private BaseRequestProto() {}
public final class CIMRequestProto {
private CIMRequestProto() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
... ... @@ -14,8 +14,8 @@ public final class BaseRequestProto {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface RequestProtocolOrBuilder extends
// @@protoc_insertion_point(interface_extends:protocol.RequestProtocol)
public interface CIMReqProtocolOrBuilder extends
// @@protoc_insertion_point(interface_extends:protocol.CIMReqProtocol)
com.google.protobuf.MessageOrBuilder {
/**
... ... @@ -42,18 +42,18 @@ public final class BaseRequestProto {
getReqMsgBytes();
}
/**
* Protobuf type {@code protocol.RequestProtocol}
* Protobuf type {@code protocol.CIMReqProtocol}
*/
public static final class RequestProtocol extends
public static final class CIMReqProtocol extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:protocol.RequestProtocol)
RequestProtocolOrBuilder {
// @@protoc_insertion_point(message_implements:protocol.CIMReqProtocol)
CIMReqProtocolOrBuilder {
private static final long serialVersionUID = 0L;
// Use RequestProtocol.newBuilder() to construct.
private RequestProtocol(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
// Use CIMReqProtocol.newBuilder() to construct.
private CIMReqProtocol(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private RequestProtocol() {
private CIMReqProtocol() {
requestId_ = 0;
reqMsg_ = "";
}
... ... @@ -63,7 +63,7 @@ public final class BaseRequestProto {
getUnknownFields() {
return this.unknownFields;
}
private RequestProtocol(
private CIMReqProtocol(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
... ... @@ -114,14 +114,14 @@ public final class BaseRequestProto {
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return BaseRequestProto.internal_static_protocol_RequestProtocol_descriptor;
return CIMRequestProto.internal_static_protocol_CIMReqProtocol_descriptor;
}
protected FieldAccessorTable
internalGetFieldAccessorTable() {
return BaseRequestProto.internal_static_protocol_RequestProtocol_fieldAccessorTable
return CIMRequestProto.internal_static_protocol_CIMReqProtocol_fieldAccessorTable
.ensureFieldAccessorsInitialized(
RequestProtocol.class, Builder.class);
CIMReqProtocol.class, Builder.class);
}
private int bitField0_;
... ... @@ -233,10 +233,10 @@ public final class BaseRequestProto {
if (obj == this) {
return true;
}
if (!(obj instanceof RequestProtocol)) {
if (!(obj instanceof CIMReqProtocol)) {
return super.equals(obj);
}
RequestProtocol other = (RequestProtocol) obj;
CIMReqProtocol other = (CIMReqProtocol) obj;
boolean result = true;
result = result && (hasRequestId() == other.hasRequestId());
... ... @@ -273,69 +273,69 @@ public final class BaseRequestProto {
return hash;
}
public static RequestProtocol parseFrom(
public static CIMReqProtocol parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static RequestProtocol parseFrom(
public static CIMReqProtocol parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static RequestProtocol parseFrom(
public static CIMReqProtocol parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static RequestProtocol parseFrom(
public static CIMReqProtocol parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static RequestProtocol parseFrom(byte[] data)
public static CIMReqProtocol parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static RequestProtocol parseFrom(
public static CIMReqProtocol parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static RequestProtocol parseFrom(java.io.InputStream input)
public static CIMReqProtocol parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static RequestProtocol parseFrom(
public static CIMReqProtocol parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static RequestProtocol parseDelimitedFrom(java.io.InputStream input)
public static CIMReqProtocol parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static RequestProtocol parseDelimitedFrom(
public static CIMReqProtocol parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static RequestProtocol parseFrom(
public static CIMReqProtocol parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static RequestProtocol parseFrom(
public static CIMReqProtocol parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
... ... @@ -347,7 +347,7 @@ public final class BaseRequestProto {
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(RequestProtocol prototype) {
public static Builder newBuilder(CIMReqProtocol prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
public Builder toBuilder() {
... ... @@ -362,25 +362,25 @@ public final class BaseRequestProto {
return builder;
}
/**
* Protobuf type {@code protocol.RequestProtocol}
* Protobuf type {@code protocol.CIMReqProtocol}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:protocol.RequestProtocol)
RequestProtocolOrBuilder {
// @@protoc_insertion_point(builder_implements:protocol.CIMReqProtocol)
CIMReqProtocolOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return BaseRequestProto.internal_static_protocol_RequestProtocol_descriptor;
return CIMRequestProto.internal_static_protocol_CIMReqProtocol_descriptor;
}
protected FieldAccessorTable
internalGetFieldAccessorTable() {
return BaseRequestProto.internal_static_protocol_RequestProtocol_fieldAccessorTable
return CIMRequestProto.internal_static_protocol_CIMReqProtocol_fieldAccessorTable
.ensureFieldAccessorsInitialized(
RequestProtocol.class, Builder.class);
CIMReqProtocol.class, Builder.class);
}
// Construct using com.crossoverjie.netty.action.protocol.BaseRequestProto.RequestProtocol.newBuilder()
// Construct using com.crossoverjie.cim.common.protocol.CIMRequestProto.CIMReqProtocol.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
... ... @@ -406,23 +406,23 @@ public final class BaseRequestProto {
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return BaseRequestProto.internal_static_protocol_RequestProtocol_descriptor;
return CIMRequestProto.internal_static_protocol_CIMReqProtocol_descriptor;
}
public RequestProtocol getDefaultInstanceForType() {
return RequestProtocol.getDefaultInstance();
public CIMReqProtocol getDefaultInstanceForType() {
return CIMReqProtocol.getDefaultInstance();
}
public RequestProtocol build() {
RequestProtocol result = buildPartial();
public CIMReqProtocol build() {
CIMReqProtocol result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
public RequestProtocol buildPartial() {
RequestProtocol result = new RequestProtocol(this);
public CIMReqProtocol buildPartial() {
CIMReqProtocol result = new CIMReqProtocol(this);
int from_bitField0_ = bitField0_;
int to_bitField0_ = 0;
if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
... ... @@ -465,16 +465,16 @@ public final class BaseRequestProto {
return (Builder) super.addRepeatedField(field, value);
}
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof RequestProtocol) {
return mergeFrom((RequestProtocol)other);
if (other instanceof CIMReqProtocol) {
return mergeFrom((CIMReqProtocol)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(RequestProtocol other) {
if (other == RequestProtocol.getDefaultInstance()) return this;
public Builder mergeFrom(CIMReqProtocol other) {
if (other == CIMReqProtocol.getDefaultInstance()) return this;
if (other.hasRequestId()) {
setRequestId(other.getRequestId());
}
... ... @@ -502,11 +502,11 @@ public final class BaseRequestProto {
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
RequestProtocol parsedMessage = null;
CIMReqProtocol parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (RequestProtocol) e.getUnfinishedMessage();
parsedMessage = (CIMReqProtocol) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
... ... @@ -635,49 +635,49 @@ public final class BaseRequestProto {
}
// @@protoc_insertion_point(builder_scope:protocol.RequestProtocol)
// @@protoc_insertion_point(builder_scope:protocol.CIMReqProtocol)
}
// @@protoc_insertion_point(class_scope:protocol.RequestProtocol)
private static final RequestProtocol DEFAULT_INSTANCE;
// @@protoc_insertion_point(class_scope:protocol.CIMReqProtocol)
private static final CIMReqProtocol DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new RequestProtocol();
DEFAULT_INSTANCE = new CIMReqProtocol();
}
public static RequestProtocol getDefaultInstance() {
public static CIMReqProtocol getDefaultInstance() {
return DEFAULT_INSTANCE;
}
@Deprecated public static final com.google.protobuf.Parser<RequestProtocol>
PARSER = new com.google.protobuf.AbstractParser<RequestProtocol>() {
public RequestProtocol parsePartialFrom(
@Deprecated public static final com.google.protobuf.Parser<CIMReqProtocol>
PARSER = new com.google.protobuf.AbstractParser<CIMReqProtocol>() {
public CIMReqProtocol parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new RequestProtocol(input, extensionRegistry);
return new CIMReqProtocol(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<RequestProtocol> parser() {
public static com.google.protobuf.Parser<CIMReqProtocol> parser() {
return PARSER;
}
@Override
public com.google.protobuf.Parser<RequestProtocol> getParserForType() {
public com.google.protobuf.Parser<CIMReqProtocol> getParserForType() {
return PARSER;
}
public RequestProtocol getDefaultInstanceForType() {
public CIMReqProtocol getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_protocol_RequestProtocol_descriptor;
internal_static_protocol_CIMReqProtocol_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_protocol_RequestProtocol_fieldAccessorTable;
internal_static_protocol_CIMReqProtocol_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
... ... @@ -687,10 +687,10 @@ public final class BaseRequestProto {
descriptor;
static {
String[] descriptorData = {
"\n\026BaseRequestProto.proto\022\010protocol\"4\n\017Re" +
"questProtocol\022\021\n\trequestId\030\002 \002(\005\022\016\n\006reqM" +
"sg\030\001 \002(\tB:\n&com.crossoverjie.netty.actio" +
"n.protocolB\020BaseRequestProto"
"\n\026BaseRequestProto.proto\022\010protocol\"3\n\016CI" +
"MReqProtocol\022\021\n\trequestId\030\002 \002(\005\022\016\n\006reqMs" +
"g\030\001 \002(\tB7\n$com.crossoverjie.cim.common.p" +
"rotocolB\017CIMRequestProto"
};
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
... ... @@ -704,11 +704,11 @@ public final class BaseRequestProto {
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
}, assigner);
internal_static_protocol_RequestProtocol_descriptor =
internal_static_protocol_CIMReqProtocol_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_protocol_RequestProtocol_fieldAccessorTable = new
internal_static_protocol_CIMReqProtocol_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_protocol_RequestProtocol_descriptor,
internal_static_protocol_CIMReqProtocol_descriptor,
new String[] { "RequestId", "ReqMsg", });
}
... ...
... ... @@ -3,8 +3,8 @@
package com.crossoverjie.cim.common.protocol;
public final class BaseResponseProto {
private BaseResponseProto() {}
public final class CIMResponseProto {
private CIMResponseProto() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
... ... @@ -14,8 +14,8 @@ public final class BaseResponseProto {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface ResponseProtocolOrBuilder extends
// @@protoc_insertion_point(interface_extends:protocol.ResponseProtocol)
public interface CIMResProtocolOrBuilder extends
// @@protoc_insertion_point(interface_extends:protocol.CIMResProtocol)
com.google.protobuf.MessageOrBuilder {
/**
... ... @@ -42,18 +42,18 @@ public final class BaseResponseProto {
getResMsgBytes();
}
/**
* Protobuf type {@code protocol.ResponseProtocol}
* Protobuf type {@code protocol.CIMResProtocol}
*/
public static final class ResponseProtocol extends
public static final class CIMResProtocol extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:protocol.ResponseProtocol)
ResponseProtocolOrBuilder {
// @@protoc_insertion_point(message_implements:protocol.CIMResProtocol)
CIMResProtocolOrBuilder {
private static final long serialVersionUID = 0L;
// Use ResponseProtocol.newBuilder() to construct.
private ResponseProtocol(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
// Use CIMResProtocol.newBuilder() to construct.
private CIMResProtocol(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private ResponseProtocol() {
private CIMResProtocol() {
responseId_ = 0;
resMsg_ = "";
}
... ... @@ -63,7 +63,7 @@ public final class BaseResponseProto {
getUnknownFields() {
return this.unknownFields;
}
private ResponseProtocol(
private CIMResProtocol(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
... ... @@ -114,14 +114,14 @@ public final class BaseResponseProto {
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return BaseResponseProto.internal_static_protocol_ResponseProtocol_descriptor;
return CIMResponseProto.internal_static_protocol_CIMResProtocol_descriptor;
}
protected FieldAccessorTable
internalGetFieldAccessorTable() {
return BaseResponseProto.internal_static_protocol_ResponseProtocol_fieldAccessorTable
return CIMResponseProto.internal_static_protocol_CIMResProtocol_fieldAccessorTable
.ensureFieldAccessorsInitialized(
ResponseProtocol.class, Builder.class);
CIMResProtocol.class, Builder.class);
}
private int bitField0_;
... ... @@ -233,10 +233,10 @@ public final class BaseResponseProto {
if (obj == this) {
return true;
}
if (!(obj instanceof ResponseProtocol)) {
if (!(obj instanceof CIMResProtocol)) {
return super.equals(obj);
}
ResponseProtocol other = (ResponseProtocol) obj;
CIMResProtocol other = (CIMResProtocol) obj;
boolean result = true;
result = result && (hasResponseId() == other.hasResponseId());
... ... @@ -273,69 +273,69 @@ public final class BaseResponseProto {
return hash;
}
public static ResponseProtocol parseFrom(
public static CIMResProtocol parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static ResponseProtocol parseFrom(
public static CIMResProtocol parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static ResponseProtocol parseFrom(
public static CIMResProtocol parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static ResponseProtocol parseFrom(
public static CIMResProtocol parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static ResponseProtocol parseFrom(byte[] data)
public static CIMResProtocol parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static ResponseProtocol parseFrom(
public static CIMResProtocol parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static ResponseProtocol parseFrom(java.io.InputStream input)
public static CIMResProtocol parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static ResponseProtocol parseFrom(
public static CIMResProtocol parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static ResponseProtocol parseDelimitedFrom(java.io.InputStream input)
public static CIMResProtocol parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static ResponseProtocol parseDelimitedFrom(
public static CIMResProtocol parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static ResponseProtocol parseFrom(
public static CIMResProtocol parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static ResponseProtocol parseFrom(
public static CIMResProtocol parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
... ... @@ -347,7 +347,7 @@ public final class BaseResponseProto {
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(ResponseProtocol prototype) {
public static Builder newBuilder(CIMResProtocol prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
public Builder toBuilder() {
... ... @@ -362,25 +362,25 @@ public final class BaseResponseProto {
return builder;
}
/**
* Protobuf type {@code protocol.ResponseProtocol}
* Protobuf type {@code protocol.CIMResProtocol}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:protocol.ResponseProtocol)
ResponseProtocolOrBuilder {
// @@protoc_insertion_point(builder_implements:protocol.CIMResProtocol)
CIMResProtocolOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return BaseResponseProto.internal_static_protocol_ResponseProtocol_descriptor;
return CIMResponseProto.internal_static_protocol_CIMResProtocol_descriptor;
}
protected FieldAccessorTable
internalGetFieldAccessorTable() {
return BaseResponseProto.internal_static_protocol_ResponseProtocol_fieldAccessorTable
return CIMResponseProto.internal_static_protocol_CIMResProtocol_fieldAccessorTable
.ensureFieldAccessorsInitialized(
ResponseProtocol.class, Builder.class);
CIMResProtocol.class, Builder.class);
}
// Construct using com.crossoverjie.netty.action.protocol.BaseResponseProto.ResponseProtocol.newBuilder()
// Construct using com.crossoverjie.cim.common.protocol.CIMResponseProto.CIMResProtocol.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
... ... @@ -406,23 +406,23 @@ public final class BaseResponseProto {
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return BaseResponseProto.internal_static_protocol_ResponseProtocol_descriptor;
return CIMResponseProto.internal_static_protocol_CIMResProtocol_descriptor;
}
public ResponseProtocol getDefaultInstanceForType() {
return ResponseProtocol.getDefaultInstance();
public CIMResProtocol getDefaultInstanceForType() {
return CIMResProtocol.getDefaultInstance();
}
public ResponseProtocol build() {
ResponseProtocol result = buildPartial();
public CIMResProtocol build() {
CIMResProtocol result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
public ResponseProtocol buildPartial() {
ResponseProtocol result = new ResponseProtocol(this);
public CIMResProtocol buildPartial() {
CIMResProtocol result = new CIMResProtocol(this);
int from_bitField0_ = bitField0_;
int to_bitField0_ = 0;
if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
... ... @@ -465,16 +465,16 @@ public final class BaseResponseProto {
return (Builder) super.addRepeatedField(field, value);
}
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof ResponseProtocol) {
return mergeFrom((ResponseProtocol)other);
if (other instanceof CIMResProtocol) {
return mergeFrom((CIMResProtocol)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(ResponseProtocol other) {
if (other == ResponseProtocol.getDefaultInstance()) return this;
public Builder mergeFrom(CIMResProtocol other) {
if (other == CIMResProtocol.getDefaultInstance()) return this;
if (other.hasResponseId()) {
setResponseId(other.getResponseId());
}
... ... @@ -502,11 +502,11 @@ public final class BaseResponseProto {
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
ResponseProtocol parsedMessage = null;
CIMResProtocol parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (ResponseProtocol) e.getUnfinishedMessage();
parsedMessage = (CIMResProtocol) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
... ... @@ -635,49 +635,49 @@ public final class BaseResponseProto {
}
// @@protoc_insertion_point(builder_scope:protocol.ResponseProtocol)
// @@protoc_insertion_point(builder_scope:protocol.CIMResProtocol)
}
// @@protoc_insertion_point(class_scope:protocol.ResponseProtocol)
private static final ResponseProtocol DEFAULT_INSTANCE;
// @@protoc_insertion_point(class_scope:protocol.CIMResProtocol)
private static final CIMResProtocol DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new ResponseProtocol();
DEFAULT_INSTANCE = new CIMResProtocol();
}
public static ResponseProtocol getDefaultInstance() {
public static CIMResProtocol getDefaultInstance() {
return DEFAULT_INSTANCE;
}
@Deprecated public static final com.google.protobuf.Parser<ResponseProtocol>
PARSER = new com.google.protobuf.AbstractParser<ResponseProtocol>() {
public ResponseProtocol parsePartialFrom(
@Deprecated public static final com.google.protobuf.Parser<CIMResProtocol>
PARSER = new com.google.protobuf.AbstractParser<CIMResProtocol>() {
public CIMResProtocol parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new ResponseProtocol(input, extensionRegistry);
return new CIMResProtocol(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<ResponseProtocol> parser() {
public static com.google.protobuf.Parser<CIMResProtocol> parser() {
return PARSER;
}
@Override
public com.google.protobuf.Parser<ResponseProtocol> getParserForType() {
public com.google.protobuf.Parser<CIMResProtocol> getParserForType() {
return PARSER;
}
public ResponseProtocol getDefaultInstanceForType() {
public CIMResProtocol getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_protocol_ResponseProtocol_descriptor;
internal_static_protocol_CIMResProtocol_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_protocol_ResponseProtocol_fieldAccessorTable;
internal_static_protocol_CIMResProtocol_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
... ... @@ -687,10 +687,10 @@ public final class BaseResponseProto {
descriptor;
static {
String[] descriptorData = {
"\n\027BaseResponseProto.proto\022\010protocol\"6\n\020R" +
"esponseProtocol\022\022\n\nresponseId\030\002 \002(\005\022\016\n\006r" +
"esMsg\030\001 \002(\tB;\n&com.crossoverjie.netty.ac" +
"tion.protocolB\021BaseResponseProto"
"\n\027BaseResponseProto.proto\022\010protocol\"4\n\016C" +
"IMResProtocol\022\022\n\nresponseId\030\002 \002(\005\022\016\n\006res" +
"Msg\030\001 \002(\tB8\n$com.crossoverjie.cim.common" +
".protocolB\020CIMResponseProto"
};
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
... ... @@ -704,11 +704,11 @@ public final class BaseResponseProto {
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
}, assigner);
internal_static_protocol_ResponseProtocol_descriptor =
internal_static_protocol_CIMResProtocol_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_protocol_ResponseProtocol_fieldAccessorTable = new
internal_static_protocol_CIMResProtocol_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_protocol_ResponseProtocol_descriptor,
internal_static_protocol_CIMResProtocol_descriptor,
new String[] { "ResponseId", "ResMsg", });
}
... ...
... ... @@ -12,14 +12,14 @@ import com.google.protobuf.InvalidProtocolBufferException;
public class ProtocolUtil {
public static void main(String[] args) throws InvalidProtocolBufferException {
BaseRequestProto.RequestProtocol protocol = BaseRequestProto.RequestProtocol.newBuilder()
CIMRequestProto.CIMReqProtocol protocol = CIMRequestProto.CIMReqProtocol.newBuilder()
.setRequestId(123)
.setReqMsg("你好啊")
.build();
byte[] encode = encode(protocol);
BaseRequestProto.RequestProtocol parseFrom = decode(encode);
CIMRequestProto.CIMReqProtocol parseFrom = decode(encode);
System.out.println(protocol.toString());
System.out.println(protocol.toString().equals(parseFrom.toString()));
... ... @@ -30,7 +30,7 @@ public class ProtocolUtil {
* @param protocol
* @return
*/
public static byte[] encode(BaseRequestProto.RequestProtocol protocol){
public static byte[] encode(CIMRequestProto.CIMReqProtocol protocol){
return protocol.toByteArray() ;
}
... ... @@ -40,7 +40,7 @@ public class ProtocolUtil {
* @return
* @throws InvalidProtocolBufferException
*/
public static BaseRequestProto.RequestProtocol decode(byte[] bytes) throws InvalidProtocolBufferException {
return BaseRequestProto.RequestProtocol.parseFrom(bytes);
public static CIMRequestProto.CIMReqProtocol decode(byte[] bytes) throws InvalidProtocolBufferException {
return CIMRequestProto.CIMReqProtocol.parseFrom(bytes);
}
}
... ...
... ... @@ -80,7 +80,7 @@ public class ServerCache {
public String selectServer() {
List<String> all = getAll();
if (all.size() == 0) {
throw new RuntimeException("路由列表为空");
throw new RuntimeException("CIM 服务器可用服务列表为空");
}
Long position = index.incrementAndGet() % all.size();
if (position < 0) {
... ...
... ... @@ -22,7 +22,7 @@ public class AppConfiguration {
@Value("${app.zk.switch}")
private boolean zkSwitch;
@Value("${server.port}")
@Value("${netty.server.port}")
private int port;
public int getPort() {
... ...
... ... @@ -24,7 +24,7 @@ public class SwaggerConfig {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.crossoverjie.netty.action.controller"))
.apis(RequestHandlerSelectors.basePackage("com.crossoverjie.cim.server.controller"))
.paths(PathSelectors.any())
.build();
}
... ...
package com.crossoverjie.cim.server.handle;
import com.crossoverjie.cim.common.protocol.BaseRequestProto;
import com.crossoverjie.cim.common.protocol.BaseResponseProto;
import com.crossoverjie.cim.common.protocol.CIMRequestProto;
import com.crossoverjie.cim.common.protocol.CIMResponseProto;
import com.crossoverjie.cim.server.util.NettySocketHolder;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.nio.NioSocketChannel;
... ... @@ -16,9 +17,10 @@ import org.slf4j.LoggerFactory;
* Date: 17/05/2018 18:52
* @since JDK 1.8
*/
public class ServerHandle extends SimpleChannelInboundHandler<BaseRequestProto.RequestProtocol> {
@ChannelHandler.Sharable
public class CIMServerHandle extends SimpleChannelInboundHandler<CIMRequestProto.CIMReqProtocol> {
private final static Logger LOGGER = LoggerFactory.getLogger(ServerHandle.class);
private final static Logger LOGGER = LoggerFactory.getLogger(CIMServerHandle.class);
/**
... ... @@ -28,6 +30,7 @@ public class ServerHandle extends SimpleChannelInboundHandler<BaseRequestProto.R
*/
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
LOGGER.info("客户端断开");
NettySocketHolder.remove((NioSocketChannel) ctx.channel());
}
... ... @@ -37,11 +40,11 @@ public class ServerHandle extends SimpleChannelInboundHandler<BaseRequestProto.R
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, BaseRequestProto.RequestProtocol msg) throws Exception {
protected void channelRead0(ChannelHandlerContext ctx, CIMRequestProto.CIMReqProtocol msg) throws Exception {
LOGGER.info("收到msg={}", msg.getReqMsg());
if (999 == msg.getRequestId()){
BaseResponseProto.ResponseProtocol responseProtocol = BaseResponseProto.ResponseProtocol.newBuilder()
CIMResponseProto.CIMResProtocol responseProtocol = CIMResponseProto.CIMResProtocol.newBuilder()
.setResponseId(1000)
.setResMsg("服务端响应")
.build();
... ...
package com.crossoverjie.cim.server.init;
import com.crossoverjie.cim.common.protocol.BaseRequestProto;
import com.crossoverjie.cim.server.handle.ServerHandle;
import com.crossoverjie.cim.common.protocol.CIMRequestProto;
import com.crossoverjie.cim.server.handle.CIMServerHandle;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.protobuf.ProtobufDecoder;
... ... @@ -16,9 +16,9 @@ import io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;
* Date: 17/05/2018 18:51
* @since JDK 1.8
*/
public class HeartbeatInitializer extends ChannelInitializer<Channel> {
public class CIMServerInitializer extends ChannelInitializer<Channel> {
private final ServerHandle serverHandle = new ServerHandle();
private final CIMServerHandle cimServerHandle = new CIMServerHandle() ;
@Override
protected void initChannel(Channel ch) throws Exception {
... ... @@ -26,9 +26,9 @@ public class HeartbeatInitializer extends ChannelInitializer<Channel> {
ch.pipeline()
// google Protobuf 编解码
.addLast(new ProtobufVarint32FrameDecoder())
.addLast(new ProtobufDecoder(BaseRequestProto.RequestProtocol.getDefaultInstance()))
.addLast(new ProtobufDecoder(CIMRequestProto.CIMReqProtocol.getDefaultInstance()))
.addLast(new ProtobufVarint32LengthFieldPrepender())
.addLast(new ProtobufEncoder())
.addLast(serverHandle);
.addLast(cimServerHandle);
}
}
... ...
package com.crossoverjie.cim.server.server;
import com.alibaba.fastjson.JSON;
import com.crossoverjie.cim.common.protocol.BaseRequestProto;
import com.crossoverjie.cim.common.pojo.CustomProtocol;
import com.crossoverjie.cim.common.protocol.CIMRequestProto;
import com.crossoverjie.cim.server.init.CIMServerInitializer;
import com.crossoverjie.cim.server.util.NettySocketHolder;
import com.crossoverjie.cim.server.vo.req.SendMsgReqVO;
import com.crossoverjie.cim.common.pojo.CustomProtocol;
import com.crossoverjie.cim.server.init.HeartbeatInitializer;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
... ... @@ -60,7 +60,7 @@ public class CIMServer {
.localAddress(new InetSocketAddress(nettyPort))
//保持长连接
.childOption(ChannelOption.SO_KEEPALIVE, true)
.childHandler(new HeartbeatInitializer());
.childHandler(new CIMServerInitializer());
ChannelFuture future = bootstrap.bind().sync();
if (future.isSuccess()) {
... ... @@ -107,7 +107,7 @@ public class CIMServer {
if (null == socketChannel) {
throw new NullPointerException("没有[" + sendMsgReqVO.getId() + "]的socketChannel");
}
BaseRequestProto.RequestProtocol protocol = BaseRequestProto.RequestProtocol.newBuilder()
CIMRequestProto.CIMReqProtocol protocol = CIMRequestProto.CIMReqProtocol.newBuilder()
.setRequestId((int) sendMsgReqVO.getId())
.setReqMsg(sendMsgReqVO.getMsg())
.build();
... ...
... ... @@ -6,7 +6,7 @@
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>netty-action</name>
<name>cim</name>
<description>Spring Boot</description>
... ... @@ -53,7 +53,7 @@
<dependency>
<groupId>com.crossoverjie.netty</groupId>
<artifactId>cim-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>
</dependency>
<dependency>
... ...