feat(grpc): 实现 gRPC 服务并添加设备在线状态管理

- 新增 gRPC 服务配置和实现类
- 添加设备在线状态字段和相关接口
- 实现客户端连接管理和消息推送功能
- 新增终端开机和关机接口
master
chenhao 2025-08-21 17:36:40 +08:00
parent 6a9538e377
commit 57444011dc
20 changed files with 3333 additions and 0 deletions

View File

@ -22,6 +22,7 @@
<properties>
<java.version>1.8</java.version>
<protobuf.version>3.23.4</protobuf.version>
</properties>
<dependencies>
@ -101,10 +102,64 @@
<version>1.5</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>${protobuf.version}</version>
</dependency>
<!-- grpc server和spring-boot集成框架 -->
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-server-spring-boot-starter</artifactId>
<version>2.14.0.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.2</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.19.2:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.50.0:exe:${os.detected.classifier}</pluginArtifact>
<!-- proto文件目录 -->
<protoSourceRoot>${project.basedir}/src/main/java/com/unisinsight/project/grpc/proto</protoSourceRoot>
<!-- 生成的Java文件目录,这里指定到这一级就可以咯proto文件有基于package指定 -->
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
<clearOutputDirectory>false</clearOutputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>

View File

@ -0,0 +1,67 @@
package com.unisinsight.project.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author : ch
* @version : 1.0
* @ClassName : ThreadConfig
* @Description :
* @DATE : Created in 16:22 2025/8/21
* <pre> Copyright: Copyright(c) 2025 </pre>
* <pre> Company : </pre>
* Modification History:
* Date Author Version Discription
* --------------------------------------------------------------------------
* 2025/08/21 ch 1.0 Why & What is modified: <> *
*/
@Configuration
public class ThreadConfig {
/**
* gRPC线
* /
*/
@Bean("grpcConnectionListenerExecutor")
public ExecutorService grpcConnectionListenerExecutor() {
// 获取系统可用处理器核心数
int corePoolSize =1;
int maximumPoolSize = corePoolSize * 2;
// 设置线程空闲时间
long keepAliveTime = 60L;
// 设置队列大小
int queueCapacity = 1000;
// 创建线程池
return new ThreadPoolExecutor(
// 核心线程数
corePoolSize,
// 最大线程数
maximumPoolSize,
// 空闲线程存活时间
keepAliveTime,
// 时间单位
TimeUnit.SECONDS,
// 任务队列
new LinkedBlockingQueue<>(queueCapacity),
new ThreadFactory() {
private final AtomicInteger threadNumber = new AtomicInteger(1);
@Override
public Thread newThread(Runnable runable) {
Thread thread = new Thread(runable, "grpc-connection-listener-" + threadNumber.getAndIncrement());
thread.setDaemon(false); // 设置为非守护线程
return thread;
}
},
// 拒绝策略:由调用线程执行任务
new ThreadPoolExecutor.CallerRunsPolicy()
);
}
}

View File

@ -7,10 +7,12 @@ import com.unisinsight.project.entity.res.DeviceRes;
import com.unisinsight.project.entity.res.PageResult;
import com.unisinsight.project.exception.BaseErrorCode;
import com.unisinsight.project.exception.Result;
import com.unisinsight.project.service.ClientOperateService;
import com.unisinsight.project.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -33,6 +35,8 @@ public class DeviceController {
@Resource
private DeviceService deviceService;
@Autowired
private ClientOperateService clientOperateService;
@ApiOperation(value = "终端新增")
@PostMapping("/add")
public Result<?> insertUser(@RequestBody DeviceReq deviceReq) {
@ -82,4 +86,25 @@ public class DeviceController {
return deviceService.selectPageUser(deviceReq);
}
@ApiOperation(value = "开机")
@PostMapping("/terminal/start")
public Result<?> terminalStart(@RequestBody DeviceReq deviceReq) {
if (Objects.isNull(deviceReq)) {
return Result.errorResult(BaseErrorCode.PARAMS_CHK_ERROR);
}
log.info("终端开机请求参数为:{}", JSONUtil.toJsonStr(deviceReq));
return clientOperateService.terminalStart(deviceReq);
}
@ApiOperation(value = "关机")
@PostMapping("/terminal/end")
public Result<?> terminalEnd(@RequestBody DeviceReq deviceReq) {
if (Objects.isNull(deviceReq)) {
return Result.errorResult(BaseErrorCode.PARAMS_CHK_ERROR);
}
log.info("终端关机请求参数为:{}", JSONUtil.toJsonStr(deviceReq));
return clientOperateService.terminalEnd(deviceReq);
}
}

View File

@ -102,6 +102,11 @@ public class Device implements Serializable {
*/
@TableField(value = "description")
private String description;
/**
* 0:线 1:线
*/
@TableField(value = "device_status")
private Integer deviceStatus;
@TableField(exist = false)
private static final long serialVersionUID = 1L;

View File

@ -84,6 +84,12 @@ public class DeviceReq implements Serializable {
@ApiModelProperty("描述")
@JsonProperty("description")
private String description;
/**
* 0:线 1:线
*/
@ApiModelProperty("设备状态")
@JsonProperty("device_status")
private String deviceStatus;
/**
*

View File

@ -0,0 +1,622 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: message.proto
package com.unisinsight.project.grpc.generate;
/**
* Protobuf type {@code MsgResponse}
*/
public final class MsgResponse extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:MsgResponse)
MsgResponseOrBuilder {
private static final long serialVersionUID = 0L;
// Use MsgResponse.newBuilder() to construct.
private MsgResponse(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private MsgResponse() {
message_ = "";
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new MsgResponse();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private MsgResponse(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
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;
case 8: {
success_ = input.readBool();
break;
}
case 18: {
java.lang.String s = input.readStringRequireUtf8();
message_ = s;
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
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 com.unisinsight.project.grpc.generate.NotificationProto.internal_static_MsgResponse_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_MsgResponse_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.unisinsight.project.grpc.generate.MsgResponse.class, com.unisinsight.project.grpc.generate.MsgResponse.Builder.class);
}
public static final int SUCCESS_FIELD_NUMBER = 1;
private boolean success_;
/**
* <code>bool success = 1;</code>
* @return The success.
*/
@java.lang.Override
public boolean getSuccess() {
return success_;
}
public static final int MESSAGE_FIELD_NUMBER = 2;
private volatile java.lang.Object message_;
/**
* <code>string message = 2;</code>
* @return The message.
*/
@java.lang.Override
public java.lang.String getMessage() {
java.lang.Object ref = message_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
message_ = s;
return s;
}
}
/**
* <code>string message = 2;</code>
* @return The bytes for message.
*/
@java.lang.Override
public com.google.protobuf.ByteString
getMessageBytes() {
java.lang.Object ref = message_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
message_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (success_ != false) {
output.writeBool(1, success_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(message_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 2, message_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (success_ != false) {
size += com.google.protobuf.CodedOutputStream
.computeBoolSize(1, success_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(message_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, message_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof com.unisinsight.project.grpc.generate.MsgResponse)) {
return super.equals(obj);
}
com.unisinsight.project.grpc.generate.MsgResponse other = (com.unisinsight.project.grpc.generate.MsgResponse) obj;
if (getSuccess()
!= other.getSuccess()) return false;
if (!getMessage()
.equals(other.getMessage())) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + SUCCESS_FIELD_NUMBER;
hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean(
getSuccess());
hash = (37 * hash) + MESSAGE_FIELD_NUMBER;
hash = (53 * hash) + getMessage().hashCode();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.unisinsight.project.grpc.generate.MsgResponse 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 com.unisinsight.project.grpc.generate.MsgResponse parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static com.unisinsight.project.grpc.generate.MsgResponse 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 com.unisinsight.project.grpc.generate.MsgResponse parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(com.unisinsight.project.grpc.generate.MsgResponse prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* Protobuf type {@code MsgResponse}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:MsgResponse)
com.unisinsight.project.grpc.generate.MsgResponseOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_MsgResponse_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_MsgResponse_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.unisinsight.project.grpc.generate.MsgResponse.class, com.unisinsight.project.grpc.generate.MsgResponse.Builder.class);
}
// Construct using com.unisinsight.project.grpc.generate.MsgResponse.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
success_ = false;
message_ = "";
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_MsgResponse_descriptor;
}
@java.lang.Override
public com.unisinsight.project.grpc.generate.MsgResponse getDefaultInstanceForType() {
return com.unisinsight.project.grpc.generate.MsgResponse.getDefaultInstance();
}
@java.lang.Override
public com.unisinsight.project.grpc.generate.MsgResponse build() {
com.unisinsight.project.grpc.generate.MsgResponse result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public com.unisinsight.project.grpc.generate.MsgResponse buildPartial() {
com.unisinsight.project.grpc.generate.MsgResponse result = new com.unisinsight.project.grpc.generate.MsgResponse(this);
result.success_ = success_;
result.message_ = message_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof com.unisinsight.project.grpc.generate.MsgResponse) {
return mergeFrom((com.unisinsight.project.grpc.generate.MsgResponse)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(com.unisinsight.project.grpc.generate.MsgResponse other) {
if (other == com.unisinsight.project.grpc.generate.MsgResponse.getDefaultInstance()) return this;
if (other.getSuccess() != false) {
setSuccess(other.getSuccess());
}
if (!other.getMessage().isEmpty()) {
message_ = other.message_;
onChanged();
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
com.unisinsight.project.grpc.generate.MsgResponse parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (com.unisinsight.project.grpc.generate.MsgResponse) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private boolean success_ ;
/**
* <code>bool success = 1;</code>
* @return The success.
*/
@java.lang.Override
public boolean getSuccess() {
return success_;
}
/**
* <code>bool success = 1;</code>
* @param value The success to set.
* @return This builder for chaining.
*/
public Builder setSuccess(boolean value) {
success_ = value;
onChanged();
return this;
}
/**
* <code>bool success = 1;</code>
* @return This builder for chaining.
*/
public Builder clearSuccess() {
success_ = false;
onChanged();
return this;
}
private java.lang.Object message_ = "";
/**
* <code>string message = 2;</code>
* @return The message.
*/
public java.lang.String getMessage() {
java.lang.Object ref = message_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
message_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>string message = 2;</code>
* @return The bytes for message.
*/
public com.google.protobuf.ByteString
getMessageBytes() {
java.lang.Object ref = message_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
message_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string message = 2;</code>
* @param value The message to set.
* @return This builder for chaining.
*/
public Builder setMessage(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
message_ = value;
onChanged();
return this;
}
/**
* <code>string message = 2;</code>
* @return This builder for chaining.
*/
public Builder clearMessage() {
message_ = getDefaultInstance().getMessage();
onChanged();
return this;
}
/**
* <code>string message = 2;</code>
* @param value The bytes for message to set.
* @return This builder for chaining.
*/
public Builder setMessageBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
message_ = value;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:MsgResponse)
}
// @@protoc_insertion_point(class_scope:MsgResponse)
private static final com.unisinsight.project.grpc.generate.MsgResponse DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new com.unisinsight.project.grpc.generate.MsgResponse();
}
public static com.unisinsight.project.grpc.generate.MsgResponse getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<MsgResponse>
PARSER = new com.google.protobuf.AbstractParser<MsgResponse>() {
@java.lang.Override
public MsgResponse parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new MsgResponse(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<MsgResponse> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<MsgResponse> getParserForType() {
return PARSER;
}
@java.lang.Override
public com.unisinsight.project.grpc.generate.MsgResponse getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}

View File

@ -0,0 +1,27 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: message.proto
package com.unisinsight.project.grpc.generate;
public interface MsgResponseOrBuilder extends
// @@protoc_insertion_point(interface_extends:MsgResponse)
com.google.protobuf.MessageOrBuilder {
/**
* <code>bool success = 1;</code>
* @return The success.
*/
boolean getSuccess();
/**
* <code>string message = 2;</code>
* @return The message.
*/
java.lang.String getMessage();
/**
* <code>string message = 2;</code>
* @return The bytes for message.
*/
com.google.protobuf.ByteString
getMessageBytes();
}

View File

@ -0,0 +1,962 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: message.proto
package com.unisinsight.project.grpc.generate;
/**
* Protobuf type {@code NotificationMessage}
*/
public final class NotificationMessage extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:NotificationMessage)
NotificationMessageOrBuilder {
private static final long serialVersionUID = 0L;
// Use NotificationMessage.newBuilder() to construct.
private NotificationMessage(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private NotificationMessage() {
type_ = "";
content_ = "";
msg_ = "";
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new NotificationMessage();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private NotificationMessage(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
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;
case 10: {
java.lang.String s = input.readStringRequireUtf8();
type_ = s;
break;
}
case 18: {
java.lang.String s = input.readStringRequireUtf8();
content_ = s;
break;
}
case 24: {
timestamp_ = input.readInt64();
break;
}
case 32: {
code_ = input.readInt32();
break;
}
case 42: {
java.lang.String s = input.readStringRequireUtf8();
msg_ = s;
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
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 com.unisinsight.project.grpc.generate.NotificationProto.internal_static_NotificationMessage_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_NotificationMessage_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.unisinsight.project.grpc.generate.NotificationMessage.class, com.unisinsight.project.grpc.generate.NotificationMessage.Builder.class);
}
public static final int TYPE_FIELD_NUMBER = 1;
private volatile java.lang.Object type_;
/**
* <code>string type = 1;</code>
* @return The type.
*/
@java.lang.Override
public java.lang.String getType() {
java.lang.Object ref = type_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
type_ = s;
return s;
}
}
/**
* <code>string type = 1;</code>
* @return The bytes for type.
*/
@java.lang.Override
public com.google.protobuf.ByteString
getTypeBytes() {
java.lang.Object ref = type_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
type_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
public static final int CONTENT_FIELD_NUMBER = 2;
private volatile java.lang.Object content_;
/**
* <code>string content = 2;</code>
* @return The content.
*/
@java.lang.Override
public java.lang.String getContent() {
java.lang.Object ref = content_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
content_ = s;
return s;
}
}
/**
* <code>string content = 2;</code>
* @return The bytes for content.
*/
@java.lang.Override
public com.google.protobuf.ByteString
getContentBytes() {
java.lang.Object ref = content_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
content_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
public static final int TIMESTAMP_FIELD_NUMBER = 3;
private long timestamp_;
/**
* <code>int64 timestamp = 3;</code>
* @return The timestamp.
*/
@java.lang.Override
public long getTimestamp() {
return timestamp_;
}
public static final int CODE_FIELD_NUMBER = 4;
private int code_;
/**
* <code>int32 code = 4;</code>
* @return The code.
*/
@java.lang.Override
public int getCode() {
return code_;
}
public static final int MSG_FIELD_NUMBER = 5;
private volatile java.lang.Object msg_;
/**
* <code>string msg = 5;</code>
* @return The msg.
*/
@java.lang.Override
public java.lang.String getMsg() {
java.lang.Object ref = msg_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
msg_ = s;
return s;
}
}
/**
* <code>string msg = 5;</code>
* @return The bytes for msg.
*/
@java.lang.Override
public com.google.protobuf.ByteString
getMsgBytes() {
java.lang.Object ref = msg_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
msg_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(type_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, type_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(content_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 2, content_);
}
if (timestamp_ != 0L) {
output.writeInt64(3, timestamp_);
}
if (code_ != 0) {
output.writeInt32(4, code_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(msg_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 5, msg_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(type_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, type_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(content_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, content_);
}
if (timestamp_ != 0L) {
size += com.google.protobuf.CodedOutputStream
.computeInt64Size(3, timestamp_);
}
if (code_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(4, code_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(msg_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(5, msg_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof com.unisinsight.project.grpc.generate.NotificationMessage)) {
return super.equals(obj);
}
com.unisinsight.project.grpc.generate.NotificationMessage other = (com.unisinsight.project.grpc.generate.NotificationMessage) obj;
if (!getType()
.equals(other.getType())) return false;
if (!getContent()
.equals(other.getContent())) return false;
if (getTimestamp()
!= other.getTimestamp()) return false;
if (getCode()
!= other.getCode()) return false;
if (!getMsg()
.equals(other.getMsg())) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + TYPE_FIELD_NUMBER;
hash = (53 * hash) + getType().hashCode();
hash = (37 * hash) + CONTENT_FIELD_NUMBER;
hash = (53 * hash) + getContent().hashCode();
hash = (37 * hash) + TIMESTAMP_FIELD_NUMBER;
hash = (53 * hash) + com.google.protobuf.Internal.hashLong(
getTimestamp());
hash = (37 * hash) + CODE_FIELD_NUMBER;
hash = (53 * hash) + getCode();
hash = (37 * hash) + MSG_FIELD_NUMBER;
hash = (53 * hash) + getMsg().hashCode();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.unisinsight.project.grpc.generate.NotificationMessage 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 com.unisinsight.project.grpc.generate.NotificationMessage parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static com.unisinsight.project.grpc.generate.NotificationMessage 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 com.unisinsight.project.grpc.generate.NotificationMessage parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(com.unisinsight.project.grpc.generate.NotificationMessage prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* Protobuf type {@code NotificationMessage}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:NotificationMessage)
com.unisinsight.project.grpc.generate.NotificationMessageOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_NotificationMessage_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_NotificationMessage_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.unisinsight.project.grpc.generate.NotificationMessage.class, com.unisinsight.project.grpc.generate.NotificationMessage.Builder.class);
}
// Construct using com.unisinsight.project.grpc.generate.NotificationMessage.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
type_ = "";
content_ = "";
timestamp_ = 0L;
code_ = 0;
msg_ = "";
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_NotificationMessage_descriptor;
}
@java.lang.Override
public com.unisinsight.project.grpc.generate.NotificationMessage getDefaultInstanceForType() {
return com.unisinsight.project.grpc.generate.NotificationMessage.getDefaultInstance();
}
@java.lang.Override
public com.unisinsight.project.grpc.generate.NotificationMessage build() {
com.unisinsight.project.grpc.generate.NotificationMessage result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public com.unisinsight.project.grpc.generate.NotificationMessage buildPartial() {
com.unisinsight.project.grpc.generate.NotificationMessage result = new com.unisinsight.project.grpc.generate.NotificationMessage(this);
result.type_ = type_;
result.content_ = content_;
result.timestamp_ = timestamp_;
result.code_ = code_;
result.msg_ = msg_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof com.unisinsight.project.grpc.generate.NotificationMessage) {
return mergeFrom((com.unisinsight.project.grpc.generate.NotificationMessage)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(com.unisinsight.project.grpc.generate.NotificationMessage other) {
if (other == com.unisinsight.project.grpc.generate.NotificationMessage.getDefaultInstance()) return this;
if (!other.getType().isEmpty()) {
type_ = other.type_;
onChanged();
}
if (!other.getContent().isEmpty()) {
content_ = other.content_;
onChanged();
}
if (other.getTimestamp() != 0L) {
setTimestamp(other.getTimestamp());
}
if (other.getCode() != 0) {
setCode(other.getCode());
}
if (!other.getMsg().isEmpty()) {
msg_ = other.msg_;
onChanged();
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
com.unisinsight.project.grpc.generate.NotificationMessage parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (com.unisinsight.project.grpc.generate.NotificationMessage) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private java.lang.Object type_ = "";
/**
* <code>string type = 1;</code>
* @return The type.
*/
public java.lang.String getType() {
java.lang.Object ref = type_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
type_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>string type = 1;</code>
* @return The bytes for type.
*/
public com.google.protobuf.ByteString
getTypeBytes() {
java.lang.Object ref = type_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
type_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string type = 1;</code>
* @param value The type to set.
* @return This builder for chaining.
*/
public Builder setType(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
type_ = value;
onChanged();
return this;
}
/**
* <code>string type = 1;</code>
* @return This builder for chaining.
*/
public Builder clearType() {
type_ = getDefaultInstance().getType();
onChanged();
return this;
}
/**
* <code>string type = 1;</code>
* @param value The bytes for type to set.
* @return This builder for chaining.
*/
public Builder setTypeBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
type_ = value;
onChanged();
return this;
}
private java.lang.Object content_ = "";
/**
* <code>string content = 2;</code>
* @return The content.
*/
public java.lang.String getContent() {
java.lang.Object ref = content_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
content_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>string content = 2;</code>
* @return The bytes for content.
*/
public com.google.protobuf.ByteString
getContentBytes() {
java.lang.Object ref = content_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
content_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string content = 2;</code>
* @param value The content to set.
* @return This builder for chaining.
*/
public Builder setContent(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
content_ = value;
onChanged();
return this;
}
/**
* <code>string content = 2;</code>
* @return This builder for chaining.
*/
public Builder clearContent() {
content_ = getDefaultInstance().getContent();
onChanged();
return this;
}
/**
* <code>string content = 2;</code>
* @param value The bytes for content to set.
* @return This builder for chaining.
*/
public Builder setContentBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
content_ = value;
onChanged();
return this;
}
private long timestamp_ ;
/**
* <code>int64 timestamp = 3;</code>
* @return The timestamp.
*/
@java.lang.Override
public long getTimestamp() {
return timestamp_;
}
/**
* <code>int64 timestamp = 3;</code>
* @param value The timestamp to set.
* @return This builder for chaining.
*/
public Builder setTimestamp(long value) {
timestamp_ = value;
onChanged();
return this;
}
/**
* <code>int64 timestamp = 3;</code>
* @return This builder for chaining.
*/
public Builder clearTimestamp() {
timestamp_ = 0L;
onChanged();
return this;
}
private int code_ ;
/**
* <code>int32 code = 4;</code>
* @return The code.
*/
@java.lang.Override
public int getCode() {
return code_;
}
/**
* <code>int32 code = 4;</code>
* @param value The code to set.
* @return This builder for chaining.
*/
public Builder setCode(int value) {
code_ = value;
onChanged();
return this;
}
/**
* <code>int32 code = 4;</code>
* @return This builder for chaining.
*/
public Builder clearCode() {
code_ = 0;
onChanged();
return this;
}
private java.lang.Object msg_ = "";
/**
* <code>string msg = 5;</code>
* @return The msg.
*/
public java.lang.String getMsg() {
java.lang.Object ref = msg_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
msg_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>string msg = 5;</code>
* @return The bytes for msg.
*/
public com.google.protobuf.ByteString
getMsgBytes() {
java.lang.Object ref = msg_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
msg_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string msg = 5;</code>
* @param value The msg to set.
* @return This builder for chaining.
*/
public Builder setMsg(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
msg_ = value;
onChanged();
return this;
}
/**
* <code>string msg = 5;</code>
* @return This builder for chaining.
*/
public Builder clearMsg() {
msg_ = getDefaultInstance().getMsg();
onChanged();
return this;
}
/**
* <code>string msg = 5;</code>
* @param value The bytes for msg to set.
* @return This builder for chaining.
*/
public Builder setMsgBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
msg_ = value;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:NotificationMessage)
}
// @@protoc_insertion_point(class_scope:NotificationMessage)
private static final com.unisinsight.project.grpc.generate.NotificationMessage DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new com.unisinsight.project.grpc.generate.NotificationMessage();
}
public static com.unisinsight.project.grpc.generate.NotificationMessage getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<NotificationMessage>
PARSER = new com.google.protobuf.AbstractParser<NotificationMessage>() {
@java.lang.Override
public NotificationMessage parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new NotificationMessage(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<NotificationMessage> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<NotificationMessage> getParserForType() {
return PARSER;
}
@java.lang.Override
public com.unisinsight.project.grpc.generate.NotificationMessage getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}

View File

@ -0,0 +1,57 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: message.proto
package com.unisinsight.project.grpc.generate;
public interface NotificationMessageOrBuilder extends
// @@protoc_insertion_point(interface_extends:NotificationMessage)
com.google.protobuf.MessageOrBuilder {
/**
* <code>string type = 1;</code>
* @return The type.
*/
java.lang.String getType();
/**
* <code>string type = 1;</code>
* @return The bytes for type.
*/
com.google.protobuf.ByteString
getTypeBytes();
/**
* <code>string content = 2;</code>
* @return The content.
*/
java.lang.String getContent();
/**
* <code>string content = 2;</code>
* @return The bytes for content.
*/
com.google.protobuf.ByteString
getContentBytes();
/**
* <code>int64 timestamp = 3;</code>
* @return The timestamp.
*/
long getTimestamp();
/**
* <code>int32 code = 4;</code>
* @return The code.
*/
int getCode();
/**
* <code>string msg = 5;</code>
* @return The msg.
*/
java.lang.String getMsg();
/**
* <code>string msg = 5;</code>
* @return The bytes for msg.
*/
com.google.protobuf.ByteString
getMsgBytes();
}

View File

@ -0,0 +1,78 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: message.proto
package com.unisinsight.project.grpc.generate;
public final class NotificationProto {
private NotificationProto() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
static final com.google.protobuf.Descriptors.Descriptor
internal_static_RegisterRequest_descriptor;
static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_RegisterRequest_fieldAccessorTable;
static final com.google.protobuf.Descriptors.Descriptor
internal_static_NotificationMessage_descriptor;
static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_NotificationMessage_fieldAccessorTable;
static final com.google.protobuf.Descriptors.Descriptor
internal_static_MsgResponse_descriptor;
static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_MsgResponse_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n\rmessage.proto\"8\n\017RegisterRequest\022\021\n\tcl" +
"ient_sn\030\001 \001(\t\022\022\n\nclient_mac\030\002 \001(\t\"b\n\023Not" +
"ificationMessage\022\014\n\004type\030\001 \001(\t\022\017\n\007conten" +
"t\030\002 \001(\t\022\021\n\ttimestamp\030\003 \001(\003\022\014\n\004code\030\004 \001(\005" +
"\022\013\n\003msg\030\005 \001(\t\"/\n\013MsgResponse\022\017\n\007success\030" +
"\001 \001(\010\022\017\n\007message\030\002 \001(\t2\213\001\n\023NotificationS" +
"ervice\022:\n\016RegisterStream\022\020.RegisterReque" +
"st\032\024.NotificationMessage0\001\0228\n\016shutdownCl" +
"ient\022\020.RegisterRequest\032\024.NotificationMes" +
"sageB<\n%com.unisinsight.project.grpc.gen" +
"erateB\021NotificationProtoP\001b\006proto3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_RegisterRequest_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_RegisterRequest_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_RegisterRequest_descriptor,
new java.lang.String[] { "ClientSn", "ClientMac", });
internal_static_NotificationMessage_descriptor =
getDescriptor().getMessageTypes().get(1);
internal_static_NotificationMessage_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_NotificationMessage_descriptor,
new java.lang.String[] { "Type", "Content", "Timestamp", "Code", "Msg", });
internal_static_MsgResponse_descriptor =
getDescriptor().getMessageTypes().get(2);
internal_static_MsgResponse_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_MsgResponse_descriptor,
new java.lang.String[] { "Success", "Message", });
}
// @@protoc_insertion_point(outer_class_scope)
}

View File

@ -0,0 +1,364 @@
package com.unisinsight.project.grpc.generate;
import static io.grpc.MethodDescriptor.generateFullMethodName;
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.50.0)",
comments = "Source: message.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class NotificationServiceGrpc {
private NotificationServiceGrpc() {}
public static final String SERVICE_NAME = "NotificationService";
// Static method descriptors that strictly reflect the proto.
private static volatile io.grpc.MethodDescriptor<com.unisinsight.project.grpc.generate.RegisterRequest,
com.unisinsight.project.grpc.generate.NotificationMessage> getRegisterStreamMethod;
@io.grpc.stub.annotations.RpcMethod(
fullMethodName = SERVICE_NAME + '/' + "RegisterStream",
requestType = com.unisinsight.project.grpc.generate.RegisterRequest.class,
responseType = com.unisinsight.project.grpc.generate.NotificationMessage.class,
methodType = io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING)
public static io.grpc.MethodDescriptor<com.unisinsight.project.grpc.generate.RegisterRequest,
com.unisinsight.project.grpc.generate.NotificationMessage> getRegisterStreamMethod() {
io.grpc.MethodDescriptor<com.unisinsight.project.grpc.generate.RegisterRequest, com.unisinsight.project.grpc.generate.NotificationMessage> getRegisterStreamMethod;
if ((getRegisterStreamMethod = NotificationServiceGrpc.getRegisterStreamMethod) == null) {
synchronized (NotificationServiceGrpc.class) {
if ((getRegisterStreamMethod = NotificationServiceGrpc.getRegisterStreamMethod) == null) {
NotificationServiceGrpc.getRegisterStreamMethod = getRegisterStreamMethod =
io.grpc.MethodDescriptor.<com.unisinsight.project.grpc.generate.RegisterRequest, com.unisinsight.project.grpc.generate.NotificationMessage>newBuilder()
.setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING)
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "RegisterStream"))
.setSampledToLocalTracing(true)
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
com.unisinsight.project.grpc.generate.RegisterRequest.getDefaultInstance()))
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
com.unisinsight.project.grpc.generate.NotificationMessage.getDefaultInstance()))
.setSchemaDescriptor(new NotificationServiceMethodDescriptorSupplier("RegisterStream"))
.build();
}
}
}
return getRegisterStreamMethod;
}
private static volatile io.grpc.MethodDescriptor<com.unisinsight.project.grpc.generate.RegisterRequest,
com.unisinsight.project.grpc.generate.NotificationMessage> getShutdownClientMethod;
@io.grpc.stub.annotations.RpcMethod(
fullMethodName = SERVICE_NAME + '/' + "shutdownClient",
requestType = com.unisinsight.project.grpc.generate.RegisterRequest.class,
responseType = com.unisinsight.project.grpc.generate.NotificationMessage.class,
methodType = io.grpc.MethodDescriptor.MethodType.UNARY)
public static io.grpc.MethodDescriptor<com.unisinsight.project.grpc.generate.RegisterRequest,
com.unisinsight.project.grpc.generate.NotificationMessage> getShutdownClientMethod() {
io.grpc.MethodDescriptor<com.unisinsight.project.grpc.generate.RegisterRequest, com.unisinsight.project.grpc.generate.NotificationMessage> getShutdownClientMethod;
if ((getShutdownClientMethod = NotificationServiceGrpc.getShutdownClientMethod) == null) {
synchronized (NotificationServiceGrpc.class) {
if ((getShutdownClientMethod = NotificationServiceGrpc.getShutdownClientMethod) == null) {
NotificationServiceGrpc.getShutdownClientMethod = getShutdownClientMethod =
io.grpc.MethodDescriptor.<com.unisinsight.project.grpc.generate.RegisterRequest, com.unisinsight.project.grpc.generate.NotificationMessage>newBuilder()
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "shutdownClient"))
.setSampledToLocalTracing(true)
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
com.unisinsight.project.grpc.generate.RegisterRequest.getDefaultInstance()))
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
com.unisinsight.project.grpc.generate.NotificationMessage.getDefaultInstance()))
.setSchemaDescriptor(new NotificationServiceMethodDescriptorSupplier("shutdownClient"))
.build();
}
}
}
return getShutdownClientMethod;
}
/**
* Creates a new async stub that supports all call types for the service
*/
public static NotificationServiceStub newStub(io.grpc.Channel channel) {
io.grpc.stub.AbstractStub.StubFactory<NotificationServiceStub> factory =
new io.grpc.stub.AbstractStub.StubFactory<NotificationServiceStub>() {
@java.lang.Override
public NotificationServiceStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
return new NotificationServiceStub(channel, callOptions);
}
};
return NotificationServiceStub.newStub(factory, channel);
}
/**
* Creates a new blocking-style stub that supports unary and streaming output calls on the service
*/
public static NotificationServiceBlockingStub newBlockingStub(
io.grpc.Channel channel) {
io.grpc.stub.AbstractStub.StubFactory<NotificationServiceBlockingStub> factory =
new io.grpc.stub.AbstractStub.StubFactory<NotificationServiceBlockingStub>() {
@java.lang.Override
public NotificationServiceBlockingStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
return new NotificationServiceBlockingStub(channel, callOptions);
}
};
return NotificationServiceBlockingStub.newStub(factory, channel);
}
/**
* Creates a new ListenableFuture-style stub that supports unary calls on the service
*/
public static NotificationServiceFutureStub newFutureStub(
io.grpc.Channel channel) {
io.grpc.stub.AbstractStub.StubFactory<NotificationServiceFutureStub> factory =
new io.grpc.stub.AbstractStub.StubFactory<NotificationServiceFutureStub>() {
@java.lang.Override
public NotificationServiceFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
return new NotificationServiceFutureStub(channel, callOptions);
}
};
return NotificationServiceFutureStub.newStub(factory, channel);
}
/**
*/
public static abstract class NotificationServiceImplBase implements io.grpc.BindableService {
/**
* <pre>
*
* </pre>
*/
public void registerStream(com.unisinsight.project.grpc.generate.RegisterRequest request,
io.grpc.stub.StreamObserver<com.unisinsight.project.grpc.generate.NotificationMessage> responseObserver) {
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getRegisterStreamMethod(), responseObserver);
}
/**
* <pre>
*
* </pre>
*/
public void shutdownClient(com.unisinsight.project.grpc.generate.RegisterRequest request,
io.grpc.stub.StreamObserver<com.unisinsight.project.grpc.generate.NotificationMessage> responseObserver) {
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getShutdownClientMethod(), responseObserver);
}
@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
.addMethod(
getRegisterStreamMethod(),
io.grpc.stub.ServerCalls.asyncServerStreamingCall(
new MethodHandlers<
com.unisinsight.project.grpc.generate.RegisterRequest,
com.unisinsight.project.grpc.generate.NotificationMessage>(
this, METHODID_REGISTER_STREAM)))
.addMethod(
getShutdownClientMethod(),
io.grpc.stub.ServerCalls.asyncUnaryCall(
new MethodHandlers<
com.unisinsight.project.grpc.generate.RegisterRequest,
com.unisinsight.project.grpc.generate.NotificationMessage>(
this, METHODID_SHUTDOWN_CLIENT)))
.build();
}
}
/**
*/
public static final class NotificationServiceStub extends io.grpc.stub.AbstractAsyncStub<NotificationServiceStub> {
private NotificationServiceStub(
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
super(channel, callOptions);
}
@java.lang.Override
protected NotificationServiceStub build(
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
return new NotificationServiceStub(channel, callOptions);
}
/**
* <pre>
*
* </pre>
*/
public void registerStream(com.unisinsight.project.grpc.generate.RegisterRequest request,
io.grpc.stub.StreamObserver<com.unisinsight.project.grpc.generate.NotificationMessage> responseObserver) {
io.grpc.stub.ClientCalls.asyncServerStreamingCall(
getChannel().newCall(getRegisterStreamMethod(), getCallOptions()), request, responseObserver);
}
/**
* <pre>
*
* </pre>
*/
public void shutdownClient(com.unisinsight.project.grpc.generate.RegisterRequest request,
io.grpc.stub.StreamObserver<com.unisinsight.project.grpc.generate.NotificationMessage> responseObserver) {
io.grpc.stub.ClientCalls.asyncUnaryCall(
getChannel().newCall(getShutdownClientMethod(), getCallOptions()), request, responseObserver);
}
}
/**
*/
public static final class NotificationServiceBlockingStub extends io.grpc.stub.AbstractBlockingStub<NotificationServiceBlockingStub> {
private NotificationServiceBlockingStub(
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
super(channel, callOptions);
}
@java.lang.Override
protected NotificationServiceBlockingStub build(
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
return new NotificationServiceBlockingStub(channel, callOptions);
}
/**
* <pre>
*
* </pre>
*/
public java.util.Iterator<com.unisinsight.project.grpc.generate.NotificationMessage> registerStream(
com.unisinsight.project.grpc.generate.RegisterRequest request) {
return io.grpc.stub.ClientCalls.blockingServerStreamingCall(
getChannel(), getRegisterStreamMethod(), getCallOptions(), request);
}
/**
* <pre>
*
* </pre>
*/
public com.unisinsight.project.grpc.generate.NotificationMessage shutdownClient(com.unisinsight.project.grpc.generate.RegisterRequest request) {
return io.grpc.stub.ClientCalls.blockingUnaryCall(
getChannel(), getShutdownClientMethod(), getCallOptions(), request);
}
}
/**
*/
public static final class NotificationServiceFutureStub extends io.grpc.stub.AbstractFutureStub<NotificationServiceFutureStub> {
private NotificationServiceFutureStub(
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
super(channel, callOptions);
}
@java.lang.Override
protected NotificationServiceFutureStub build(
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
return new NotificationServiceFutureStub(channel, callOptions);
}
/**
* <pre>
*
* </pre>
*/
public com.google.common.util.concurrent.ListenableFuture<com.unisinsight.project.grpc.generate.NotificationMessage> shutdownClient(
com.unisinsight.project.grpc.generate.RegisterRequest request) {
return io.grpc.stub.ClientCalls.futureUnaryCall(
getChannel().newCall(getShutdownClientMethod(), getCallOptions()), request);
}
}
private static final int METHODID_REGISTER_STREAM = 0;
private static final int METHODID_SHUTDOWN_CLIENT = 1;
private static final class MethodHandlers<Req, Resp> implements
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
private final NotificationServiceImplBase serviceImpl;
private final int methodId;
MethodHandlers(NotificationServiceImplBase serviceImpl, int methodId) {
this.serviceImpl = serviceImpl;
this.methodId = methodId;
}
@java.lang.Override
@java.lang.SuppressWarnings("unchecked")
public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
switch (methodId) {
case METHODID_REGISTER_STREAM:
serviceImpl.registerStream((com.unisinsight.project.grpc.generate.RegisterRequest) request,
(io.grpc.stub.StreamObserver<com.unisinsight.project.grpc.generate.NotificationMessage>) responseObserver);
break;
case METHODID_SHUTDOWN_CLIENT:
serviceImpl.shutdownClient((com.unisinsight.project.grpc.generate.RegisterRequest) request,
(io.grpc.stub.StreamObserver<com.unisinsight.project.grpc.generate.NotificationMessage>) responseObserver);
break;
default:
throw new AssertionError();
}
}
@java.lang.Override
@java.lang.SuppressWarnings("unchecked")
public io.grpc.stub.StreamObserver<Req> invoke(
io.grpc.stub.StreamObserver<Resp> responseObserver) {
switch (methodId) {
default:
throw new AssertionError();
}
}
}
private static abstract class NotificationServiceBaseDescriptorSupplier
implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier {
NotificationServiceBaseDescriptorSupplier() {}
@java.lang.Override
public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
return com.unisinsight.project.grpc.generate.NotificationProto.getDescriptor();
}
@java.lang.Override
public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() {
return getFileDescriptor().findServiceByName("NotificationService");
}
}
private static final class NotificationServiceFileDescriptorSupplier
extends NotificationServiceBaseDescriptorSupplier {
NotificationServiceFileDescriptorSupplier() {}
}
private static final class NotificationServiceMethodDescriptorSupplier
extends NotificationServiceBaseDescriptorSupplier
implements io.grpc.protobuf.ProtoMethodDescriptorSupplier {
private final String methodName;
NotificationServiceMethodDescriptorSupplier(String methodName) {
this.methodName = methodName;
}
@java.lang.Override
public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() {
return getServiceDescriptor().findMethodByName(methodName);
}
}
private static volatile io.grpc.ServiceDescriptor serviceDescriptor;
public static io.grpc.ServiceDescriptor getServiceDescriptor() {
io.grpc.ServiceDescriptor result = serviceDescriptor;
if (result == null) {
synchronized (NotificationServiceGrpc.class) {
result = serviceDescriptor;
if (result == null) {
serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME)
.setSchemaDescriptor(new NotificationServiceFileDescriptorSupplier())
.addMethod(getRegisterStreamMethod())
.addMethod(getShutdownClientMethod())
.build();
}
}
}
return result;
}
}

View File

@ -0,0 +1,695 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: message.proto
package com.unisinsight.project.grpc.generate;
/**
* Protobuf type {@code RegisterRequest}
*/
public final class RegisterRequest extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:RegisterRequest)
RegisterRequestOrBuilder {
private static final long serialVersionUID = 0L;
// Use RegisterRequest.newBuilder() to construct.
private RegisterRequest(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private RegisterRequest() {
clientSn_ = "";
clientMac_ = "";
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new RegisterRequest();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private RegisterRequest(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
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;
case 10: {
java.lang.String s = input.readStringRequireUtf8();
clientSn_ = s;
break;
}
case 18: {
java.lang.String s = input.readStringRequireUtf8();
clientMac_ = s;
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
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 com.unisinsight.project.grpc.generate.NotificationProto.internal_static_RegisterRequest_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_RegisterRequest_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.unisinsight.project.grpc.generate.RegisterRequest.class, com.unisinsight.project.grpc.generate.RegisterRequest.Builder.class);
}
public static final int CLIENT_SN_FIELD_NUMBER = 1;
private volatile java.lang.Object clientSn_;
/**
* <code>string client_sn = 1;</code>
* @return The clientSn.
*/
@java.lang.Override
public java.lang.String getClientSn() {
java.lang.Object ref = clientSn_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
clientSn_ = s;
return s;
}
}
/**
* <code>string client_sn = 1;</code>
* @return The bytes for clientSn.
*/
@java.lang.Override
public com.google.protobuf.ByteString
getClientSnBytes() {
java.lang.Object ref = clientSn_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
clientSn_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
public static final int CLIENT_MAC_FIELD_NUMBER = 2;
private volatile java.lang.Object clientMac_;
/**
* <code>string client_mac = 2;</code>
* @return The clientMac.
*/
@java.lang.Override
public java.lang.String getClientMac() {
java.lang.Object ref = clientMac_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
clientMac_ = s;
return s;
}
}
/**
* <code>string client_mac = 2;</code>
* @return The bytes for clientMac.
*/
@java.lang.Override
public com.google.protobuf.ByteString
getClientMacBytes() {
java.lang.Object ref = clientMac_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
clientMac_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(clientSn_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 1, clientSn_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(clientMac_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 2, clientMac_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(clientSn_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, clientSn_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(clientMac_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, clientMac_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof com.unisinsight.project.grpc.generate.RegisterRequest)) {
return super.equals(obj);
}
com.unisinsight.project.grpc.generate.RegisterRequest other = (com.unisinsight.project.grpc.generate.RegisterRequest) obj;
if (!getClientSn()
.equals(other.getClientSn())) return false;
if (!getClientMac()
.equals(other.getClientMac())) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + CLIENT_SN_FIELD_NUMBER;
hash = (53 * hash) + getClientSn().hashCode();
hash = (37 * hash) + CLIENT_MAC_FIELD_NUMBER;
hash = (53 * hash) + getClientMac().hashCode();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.unisinsight.project.grpc.generate.RegisterRequest 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 com.unisinsight.project.grpc.generate.RegisterRequest parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static com.unisinsight.project.grpc.generate.RegisterRequest 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 com.unisinsight.project.grpc.generate.RegisterRequest parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(com.unisinsight.project.grpc.generate.RegisterRequest prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* Protobuf type {@code RegisterRequest}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:RegisterRequest)
com.unisinsight.project.grpc.generate.RegisterRequestOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_RegisterRequest_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_RegisterRequest_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.unisinsight.project.grpc.generate.RegisterRequest.class, com.unisinsight.project.grpc.generate.RegisterRequest.Builder.class);
}
// Construct using com.unisinsight.project.grpc.generate.RegisterRequest.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
clientSn_ = "";
clientMac_ = "";
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_RegisterRequest_descriptor;
}
@java.lang.Override
public com.unisinsight.project.grpc.generate.RegisterRequest getDefaultInstanceForType() {
return com.unisinsight.project.grpc.generate.RegisterRequest.getDefaultInstance();
}
@java.lang.Override
public com.unisinsight.project.grpc.generate.RegisterRequest build() {
com.unisinsight.project.grpc.generate.RegisterRequest result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public com.unisinsight.project.grpc.generate.RegisterRequest buildPartial() {
com.unisinsight.project.grpc.generate.RegisterRequest result = new com.unisinsight.project.grpc.generate.RegisterRequest(this);
result.clientSn_ = clientSn_;
result.clientMac_ = clientMac_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof com.unisinsight.project.grpc.generate.RegisterRequest) {
return mergeFrom((com.unisinsight.project.grpc.generate.RegisterRequest)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(com.unisinsight.project.grpc.generate.RegisterRequest other) {
if (other == com.unisinsight.project.grpc.generate.RegisterRequest.getDefaultInstance()) return this;
if (!other.getClientSn().isEmpty()) {
clientSn_ = other.clientSn_;
onChanged();
}
if (!other.getClientMac().isEmpty()) {
clientMac_ = other.clientMac_;
onChanged();
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
com.unisinsight.project.grpc.generate.RegisterRequest parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (com.unisinsight.project.grpc.generate.RegisterRequest) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private java.lang.Object clientSn_ = "";
/**
* <code>string client_sn = 1;</code>
* @return The clientSn.
*/
public java.lang.String getClientSn() {
java.lang.Object ref = clientSn_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
clientSn_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>string client_sn = 1;</code>
* @return The bytes for clientSn.
*/
public com.google.protobuf.ByteString
getClientSnBytes() {
java.lang.Object ref = clientSn_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
clientSn_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string client_sn = 1;</code>
* @param value The clientSn to set.
* @return This builder for chaining.
*/
public Builder setClientSn(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
clientSn_ = value;
onChanged();
return this;
}
/**
* <code>string client_sn = 1;</code>
* @return This builder for chaining.
*/
public Builder clearClientSn() {
clientSn_ = getDefaultInstance().getClientSn();
onChanged();
return this;
}
/**
* <code>string client_sn = 1;</code>
* @param value The bytes for clientSn to set.
* @return This builder for chaining.
*/
public Builder setClientSnBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
clientSn_ = value;
onChanged();
return this;
}
private java.lang.Object clientMac_ = "";
/**
* <code>string client_mac = 2;</code>
* @return The clientMac.
*/
public java.lang.String getClientMac() {
java.lang.Object ref = clientMac_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
clientMac_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>string client_mac = 2;</code>
* @return The bytes for clientMac.
*/
public com.google.protobuf.ByteString
getClientMacBytes() {
java.lang.Object ref = clientMac_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
clientMac_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string client_mac = 2;</code>
* @param value The clientMac to set.
* @return This builder for chaining.
*/
public Builder setClientMac(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
clientMac_ = value;
onChanged();
return this;
}
/**
* <code>string client_mac = 2;</code>
* @return This builder for chaining.
*/
public Builder clearClientMac() {
clientMac_ = getDefaultInstance().getClientMac();
onChanged();
return this;
}
/**
* <code>string client_mac = 2;</code>
* @param value The bytes for clientMac to set.
* @return This builder for chaining.
*/
public Builder setClientMacBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
clientMac_ = value;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:RegisterRequest)
}
// @@protoc_insertion_point(class_scope:RegisterRequest)
private static final com.unisinsight.project.grpc.generate.RegisterRequest DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new com.unisinsight.project.grpc.generate.RegisterRequest();
}
public static com.unisinsight.project.grpc.generate.RegisterRequest getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<RegisterRequest>
PARSER = new com.google.protobuf.AbstractParser<RegisterRequest>() {
@java.lang.Override
public RegisterRequest parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new RegisterRequest(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<RegisterRequest> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<RegisterRequest> getParserForType() {
return PARSER;
}
@java.lang.Override
public com.unisinsight.project.grpc.generate.RegisterRequest getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}

View File

@ -0,0 +1,33 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: message.proto
package com.unisinsight.project.grpc.generate;
public interface RegisterRequestOrBuilder extends
// @@protoc_insertion_point(interface_extends:RegisterRequest)
com.google.protobuf.MessageOrBuilder {
/**
* <code>string client_sn = 1;</code>
* @return The clientSn.
*/
java.lang.String getClientSn();
/**
* <code>string client_sn = 1;</code>
* @return The bytes for clientSn.
*/
com.google.protobuf.ByteString
getClientSnBytes();
/**
* <code>string client_mac = 2;</code>
* @return The clientMac.
*/
java.lang.String getClientMac();
/**
* <code>string client_mac = 2;</code>
* @return The bytes for clientMac.
*/
com.google.protobuf.ByteString
getClientMacBytes();
}

View File

@ -0,0 +1,31 @@
syntax = "proto3";
option java_multiple_files = true;
option java_package = "com.unisinsight.project.grpc.generate";
option java_outer_classname = "NotificationProto";
service NotificationService {
//
rpc RegisterStream (RegisterRequest) returns (stream NotificationMessage);
//
rpc shutdownClient (RegisterRequest) returns (NotificationMessage);
}
message RegisterRequest {
string client_sn = 1;
string client_mac = 2;
}
message NotificationMessage {
string type = 1;
string content = 2;
int64 timestamp = 3;
int32 code=4;
string msg=5;
}
message MsgResponse {
bool success = 1;
string message = 2;
}

View File

@ -0,0 +1,213 @@
package com.unisinsight.project.grpc.service;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.unisinsight.project.entity.dao.Device;
import com.unisinsight.project.exception.BaseErrorCode;
import com.unisinsight.project.exception.Result;
import com.unisinsight.project.grpc.generate.NotificationMessage;
import com.unisinsight.project.grpc.generate.NotificationServiceGrpc;
import com.unisinsight.project.grpc.generate.RegisterRequest;
import com.unisinsight.project.service.DeviceService;
import com.unisinsight.project.util.StringUtil;
import io.grpc.stub.StreamObserver;
import lombok.extern.slf4j.Slf4j;
import net.devh.boot.grpc.server.service.GrpcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
/**
* @author : ch
* @version : 1.0
* @ClassName : ClientNotificationServiceImpl
* @Description :
* @DATE : Created in 9:17 2025/8/21
* <pre> Copyright: Copyright(c) 2025 </pre>
* <pre> Company : </pre>
* Modification History:
* Date Author Version Discription
* --------------------------------------------------------------------------
* 2025/08/21 ch 1.0 Why & What is modified: <> *
*/
@GrpcService
@Slf4j
public class ClientNotificationServiceImpl extends NotificationServiceGrpc.NotificationServiceImplBase implements SendNotificationService {
// 保存客户端连接的映射表
private final ConcurrentHashMap<String, StreamObserver<NotificationMessage>> clientStreamMap =
new ConcurrentHashMap<>();
private final static int MAX_CLIENT_COUNT = 1000;
@Autowired
@Qualifier("grpcConnectionListenerExecutor")
private ExecutorService executorService;
@Autowired
private DeviceService deviceService;
@Override
public void registerStream(RegisterRequest request, StreamObserver<NotificationMessage> responseObserver) {
String clientSn = request.getClientSn();
String clientMac = request.getClientMac();
if (StringUtil.isEmpty(clientSn)) {
NotificationMessage errMsg = NotificationMessage.newBuilder()
.setCode(HttpStatus.BAD_REQUEST.value())
.setMsg("client_id不能为空")
.build();
responseObserver.onNext(errMsg);
responseObserver.onCompleted();
return; // 避免继续执行后续逻辑
}
if (StringUtil.isEmpty(clientMac)) {
NotificationMessage errMsg = NotificationMessage.newBuilder()
.setCode(HttpStatus.BAD_REQUEST.value())
.setMsg("client_mac不能为空")
.build();
responseObserver.onNext(errMsg);
responseObserver.onCompleted();
return; // 避免继续执行后续逻辑
}
log.info("客户端连接client_sn:[{}],client_mac: [{}]", clientSn, clientMac);
addClientConnection(responseObserver, clientSn, clientMac);
responseObserver.onNext(NotificationMessage.newBuilder()
.setCode(HttpStatus.OK.value())
.setMsg("连接成功")
.build());
// 获取当前的 ServerCall
final io.grpc.Context context = io.grpc.Context.current();
// 注册一个取消监听器来监听客户端断开连接
context.addListener(context1 -> {
// 客户端断开连接时的处理逻辑
log.info("通过Context监听到客户端断开连接: {}", clientSn);
removeClientConnection(clientSn);
log.info("清理客户端连接: {}, 剩余客户端数: {}", clientSn, clientStreamMap.size());
}, executorService);
}
private StreamObserver<NotificationMessage> removeClientConnection(String clientId) {
StreamObserver<NotificationMessage> remove = clientStreamMap.remove(clientId);
//更新设备状态
LambdaUpdateWrapper<Device> updateWrapper = new LambdaUpdateWrapper<>();
//离线
updateWrapper.set(Device::getDeviceStatus, 0);
updateWrapper.eq(Device::getDeviceId, clientId);
deviceService.update(updateWrapper);
return remove;
}
private void addClientConnection(StreamObserver<NotificationMessage> responseObserver, String clientId, String clientMac) {
if (clientStreamMap.size() >= MAX_CLIENT_COUNT) {
NotificationMessage errMsg = NotificationMessage.newBuilder()
.setCode(HttpStatus.TOO_MANY_REQUESTS.value())
.setMsg("服务器连接数已达上限")
.build();
responseObserver.onNext(errMsg);
responseObserver.onCompleted();
return;
}
// 使用 putIfAbsent 确保线程安全的注册
StreamObserver<NotificationMessage> previousObserver = clientStreamMap.putIfAbsent(clientId, responseObserver);
if (previousObserver != null) {
// 如果已经存在连接,关闭旧连接
try {
previousObserver.onNext(NotificationMessage.newBuilder()
.setCode(HttpStatus.CONFLICT.value())
.setMsg("重复连接,已断开旧连接")
.build());
previousObserver.onCompleted();
} catch (Exception e) {
log.warn("关闭旧连接时出错: {}", e.getMessage());
}
// 更新为新的连接
clientStreamMap.put(clientId, responseObserver);
}
log.info("客户端注册: {}, 总客户端: {}", clientId, clientStreamMap.size());
// 连接成功后更新设备状态
LambdaUpdateWrapper<Device> updateWrapper = new LambdaUpdateWrapper<>();
//在线
updateWrapper.set(Device::getDeviceStatus, 1);
updateWrapper.set(Device::getMacAddr, clientMac);
updateWrapper.eq(Device::getDeviceId, clientId);
deviceService.update(updateWrapper);
}
@Override
public void shutdownClient(RegisterRequest request, StreamObserver<NotificationMessage> responseObserver) {
String clientSn = request.getClientSn();
String clientMac = request.getClientMac();
if (StringUtil.isEmpty(clientSn)) {
NotificationMessage errMsg = NotificationMessage.newBuilder()
.setCode(HttpStatus.BAD_REQUEST.value())
.setMsg("client_id不能为空")
.build();
responseObserver.onNext(errMsg);
responseObserver.onCompleted();
return; // 避免继续执行后续逻辑
}
if (StringUtil.isEmpty(clientMac)) {
NotificationMessage errMsg = NotificationMessage.newBuilder()
.setCode(HttpStatus.BAD_REQUEST.value())
.setMsg("client_mac不能为空")
.build();
responseObserver.onNext(errMsg);
responseObserver.onCompleted();
return; // 避免继续执行后续逻辑
}
log.info("客户端注销client_sn:[{}],client_mac: [{}]", clientSn, clientMac);
// 安全地移除并关闭连接
StreamObserver<NotificationMessage> notificationStream = removeClientConnection(clientSn);
if (notificationStream != null) {
try {
notificationStream.onNext(NotificationMessage.newBuilder()
.setCode(HttpStatus.OK.value())
.setMsg("注销成功")
.build());
notificationStream.onCompleted();
} catch (Exception e) {
log.warn("关闭连接时出错: {}", e.getMessage());
}
} else {
// 客户端不存在时也返回成功,避免信息泄露
responseObserver.onNext(NotificationMessage.newBuilder()
.setCode(HttpStatus.OK.value())
.setMsg("注销成功")
.build());
}
responseObserver.onCompleted();
}
@Override
public Result<?> sendNotification(String clientId, NotificationMessage notification) {
StreamObserver<NotificationMessage> notificationStream = clientStreamMap.get(clientId);
if (notificationStream == null) {
return Result.errorResult(BaseErrorCode.CONNECTION_FAILURE, "未找到对应的客户端连接");
}
try {
notificationStream.onNext(notification);
} catch (Exception e) {
log.error("发送消息失败,错误信息:{},错误详情:{}", e.getMessage(), e.getStackTrace());
removeClientConnection(clientId);
return Result.errorResult(BaseErrorCode.CONNECTION_FAILURE, "对应的客户端连接失效");
}
return Result.successResult();
}
}

View File

@ -0,0 +1,22 @@
package com.unisinsight.project.grpc.service;
import com.unisinsight.project.exception.Result;
import com.unisinsight.project.grpc.generate.NotificationMessage;
/**
* @author : ch
* @version : 1.0
* @ClassName : SendNotificationService
* @Description :
* @DATE : Created in 11:45 2025/8/21
* <pre> Copyright: Copyright(c) 2025 </pre>
* <pre> Company : </pre>
* Modification History:
* Date Author Version Discription
* --------------------------------------------------------------------------
* 2025/08/21 ch 1.0 Why & What is modified: <> *
*/
public interface SendNotificationService {
Result<?> sendNotification(String clientId, NotificationMessage notification);
}

View File

@ -0,0 +1,25 @@
package com.unisinsight.project.service;
import com.unisinsight.project.entity.req.DeviceReq;
import com.unisinsight.project.exception.Result;
/**
* @author : ch
* @version : 1.0
* @ClassName : ClientOperateService
* @Description :
* @DATE : Created in 17:06 2025/8/21
* <pre> Copyright: Copyright(c) 2025 </pre>
* <pre> Company : </pre>
* Modification History:
* Date Author Version Discription
* --------------------------------------------------------------------------
* 2025/08/21 ch 1.0 Why & What is modified: <> *
*/
public interface ClientOperateService {
Result<?> terminalStart(DeviceReq deviceReq);
Result<?> terminalEnd(DeviceReq deviceReq);
}

View File

@ -0,0 +1,41 @@
package com.unisinsight.project.service.impl;
import com.unisinsight.project.entity.req.DeviceReq;
import com.unisinsight.project.exception.Result;
import com.unisinsight.project.grpc.generate.NotificationMessage;
import com.unisinsight.project.grpc.service.SendNotificationService;
import com.unisinsight.project.service.ClientOperateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author : ch
* @version : 1.0
* @ClassName : ClientOperateServiceImpl
* @Description :
* @DATE : Created in 17:07 2025/8/21
* <pre> Copyright: Copyright(c) 2025 </pre>
* <pre> Company : </pre>
* Modification History:
* Date Author Version Discription
* --------------------------------------------------------------------------
* 2025/08/21 ch 1.0 Why & What is modified: <> *
*/
@Service
public class ClientOperateServiceImpl implements ClientOperateService {
@Autowired
private SendNotificationService notificationService;
@Override
public Result<?> terminalStart(DeviceReq deviceReq) {
//todo 待客户端确认消息内容后完善
return notificationService.sendNotification(deviceReq.getDeviceId(), NotificationMessage.newBuilder().setContent("终端开机").build());
}
@Override
public Result<?> terminalEnd(DeviceReq deviceReq) {
//todo 待客户端确认消息内容后完善
return notificationService.sendNotification(deviceReq.getDeviceId(), NotificationMessage.newBuilder().setContent("终端关机").build());
}
}

View File

@ -99,6 +99,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device>
queryWrapper.eq(ObjectUtils.isNotEmpty(deviceReq.getDeviceGroupId()), Device::getDeviceGroupId, deviceReq.getDeviceGroupId());
queryWrapper.eq(StringUtils.isNotBlank(deviceReq.getIpAddr()), Device::getIpAddr, deviceReq.getIpAddr());
queryWrapper.eq(ObjectUtils.isNotEmpty(deviceReq.getDeviceType()), Device::getDeviceType, deviceReq.getDeviceType());
queryWrapper.eq(ObjectUtils.isNotEmpty(deviceReq.getDeviceStatus()), Device::getDeviceStatus, deviceReq.getDeviceStatus());
queryWrapper.orderByAsc(Device::getId);
IPage<Device> userPage = deviceMapper.selectPage(page, queryWrapper);

View File

@ -44,3 +44,7 @@ mybatis-plus:
map-underscore-to-camel-case: true
cache-enabled: false
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
grpc:
server:
# 指定Grpc暴露的端口后续客户端通过这个端口访问
port: 50051