feat:(grpc):
初步完成grpc 完成 服务端 -> 客户端 客户端-> 服务端的调用
This commit is contained in:
parent
bec03831a9
commit
6d326c3b24
19
pom.xml
19
pom.xml
@ -174,6 +174,11 @@
|
||||
<version>${commons-logging.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.devh</groupId>
|
||||
<artifactId>grpc-client-spring-boot-starter</artifactId>
|
||||
<version>3.1.0.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
@ -258,13 +263,13 @@
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<!-- Prevent `gpg` from using pinentry programs -->
|
||||
<gpgArguments>
|
||||
<arg>--pinentry-mode</arg>
|
||||
<arg>loopback</arg>
|
||||
</gpgArguments>
|
||||
</configuration>
|
||||
<!-- <configuration>-->
|
||||
<!-- <!– Prevent `gpg` from using pinentry programs –>-->
|
||||
<!-- <gpgArguments>-->
|
||||
<!-- <arg>--pinentry-mode</arg>-->
|
||||
<!-- <arg>loopback</arg>-->
|
||||
<!-- </gpgArguments>-->
|
||||
<!-- </configuration>-->
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
@ -86,6 +86,20 @@
|
||||
<artifactId>log4j</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.devh</groupId>
|
||||
<artifactId>grpc-client-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-netty-shaded</artifactId>
|
||||
<version>1.63.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.devh</groupId>
|
||||
<artifactId>grpc-server-spring-boot-starter</artifactId>
|
||||
<version>3.1.0.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@ -0,0 +1,196 @@
|
||||
package com.aizuda.snailjob.client.common.rpc.client;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aizuda.snailjob.client.common.cache.GroupVersionCache;
|
||||
import com.aizuda.snailjob.client.common.config.SnailJobProperties;
|
||||
import com.aizuda.snailjob.client.common.exception.SnailJobRemoteException;
|
||||
import com.aizuda.snailjob.common.core.constant.SystemConstants;
|
||||
import com.aizuda.snailjob.common.core.context.SnailSpringContext;
|
||||
import com.aizuda.snailjob.common.core.enums.HeadersEnum;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcResult;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.Metadata;
|
||||
import com.aizuda.snailjob.common.core.util.NetUtil;
|
||||
import com.aizuda.snailjob.common.log.SnailJobLog;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.protobuf.Any;
|
||||
import com.google.protobuf.UnsafeByteOperations;
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.MethodDescriptor;
|
||||
import io.grpc.protobuf.ProtoUtils;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author: opensnail
|
||||
* @date : 2024-08-22
|
||||
*/
|
||||
public final class GrpcChannel {
|
||||
|
||||
private static ManagedChannel channel;
|
||||
|
||||
public static void setChannel(ManagedChannel channel) {
|
||||
GrpcChannel.channel = channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务端端口
|
||||
*/
|
||||
private static final String SNAIL_JOB_SERVER_PORT = "snail-job.server.port";
|
||||
/**
|
||||
* 服务端host
|
||||
*/
|
||||
private static final String SNAIL_JOB_SERVER_HOST = "snail-job.server.host";
|
||||
|
||||
/**
|
||||
* 客户端端口
|
||||
*/
|
||||
private static final String SNAIL_JOB_CLIENT_PORT = "snail-job.port";
|
||||
/**
|
||||
* 客户端host
|
||||
*/
|
||||
private static final String SNAIL_JOB_CLIENT_HOST = "snail-job.host";
|
||||
|
||||
private static final String HOST_ID = IdUtil.getSnowflake().nextIdStr();
|
||||
private static final int PORT;
|
||||
private static final String HOST;
|
||||
|
||||
static {
|
||||
PORT = Integer.parseInt(System.getProperty(SNAIL_JOB_CLIENT_PORT, String.valueOf(1789)));
|
||||
HOST = System.getProperty(SNAIL_JOB_CLIENT_HOST, NetUtil.getLocalIpStr());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务端端口
|
||||
*
|
||||
* @return port
|
||||
*/
|
||||
public static int getServerPort() {
|
||||
SnailJobProperties snailJobProperties = SnailSpringContext.getContext().getBean(SnailJobProperties.class);
|
||||
SnailJobProperties.ServerConfig serverConfig = snailJobProperties.getServer();
|
||||
|
||||
String port = System.getProperty(SNAIL_JOB_SERVER_PORT);
|
||||
if (StrUtil.isBlank(port)) {
|
||||
System.setProperty(SNAIL_JOB_SERVER_PORT, String.valueOf(serverConfig.getPort()));
|
||||
}
|
||||
|
||||
return Integer.parseInt(System.getProperty(SNAIL_JOB_SERVER_PORT));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务端host
|
||||
*
|
||||
* @return host
|
||||
*/
|
||||
public static String getServerHost() {
|
||||
SnailJobProperties snailJobProperties = SnailSpringContext.getBean(SnailJobProperties.class);
|
||||
SnailJobProperties.ServerConfig serverConfig = snailJobProperties.getServer();
|
||||
|
||||
String host = System.getProperty(SNAIL_JOB_SERVER_HOST);
|
||||
if (StrUtil.isBlank(host)) {
|
||||
System.setProperty(SNAIL_JOB_SERVER_HOST, serverConfig.getHost());
|
||||
}
|
||||
|
||||
return System.getProperty(SNAIL_JOB_SERVER_HOST);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定的客户IP
|
||||
*
|
||||
* @return 客户端IP
|
||||
*/
|
||||
public static String getClientHost() {
|
||||
SnailJobProperties snailJobProperties = SnailSpringContext.getBean(SnailJobProperties.class);
|
||||
|
||||
String host = snailJobProperties.getHost();
|
||||
// 获取客户端指定的IP地址
|
||||
if (StrUtil.isBlank(host)) {
|
||||
host = HOST;
|
||||
}
|
||||
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客户端端口
|
||||
*
|
||||
* @return port 端口
|
||||
*/
|
||||
public static Integer getClientPort() {
|
||||
SnailJobProperties snailJobProperties = SnailSpringContext.getBean(SnailJobProperties.class);
|
||||
ServerProperties serverProperties = SnailSpringContext.getBean(ServerProperties.class);
|
||||
|
||||
Integer port = snailJobProperties.getPort();
|
||||
// 获取客户端指定的端口
|
||||
if (Objects.isNull(port)) {
|
||||
port = Optional.ofNullable(serverProperties.getPort()).orElse(PORT);
|
||||
}
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
|
||||
public static ListenableFuture<GrpcResult> sendOfUnary(String path, String body) {
|
||||
if (channel == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SnailJobProperties snailJobProperties = SnailSpringContext.getBean(SnailJobProperties.class);
|
||||
|
||||
// server配置不能为空
|
||||
SnailJobProperties.ServerConfig serverConfig = snailJobProperties.getServer();
|
||||
if (Objects.isNull(serverConfig)) {
|
||||
SnailJobLog.LOCAL.error("snail job server config is null");
|
||||
return null;
|
||||
}
|
||||
|
||||
Assert.notBlank(snailJobProperties.getGroup(),
|
||||
() -> new SnailJobRemoteException("The group is null, please check if your configuration is correct."));
|
||||
|
||||
Map<String, String> headersMap = new HashMap<>();
|
||||
|
||||
headersMap.put(HeadersEnum.HOST_ID.getKey(), HOST_ID);
|
||||
headersMap.put(HeadersEnum.HOST_IP.getKey(), getClientHost());
|
||||
headersMap.put(HeadersEnum.GROUP_NAME.getKey(), snailJobProperties.getGroup());
|
||||
headersMap.put(HeadersEnum.HOST_PORT.getKey(), String.valueOf(getClientPort()));
|
||||
headersMap.put(HeadersEnum.VERSION.getKey(), String.valueOf(GroupVersionCache.getVersion()));
|
||||
headersMap.put(HeadersEnum.HOST.getKey(), serverConfig.getHost());
|
||||
headersMap.put(HeadersEnum.NAMESPACE.getKey(), Optional.ofNullable(snailJobProperties.getNamespace()).orElse(
|
||||
SystemConstants.DEFAULT_NAMESPACE));
|
||||
headersMap.put(HeadersEnum.TOKEN.getKey(), Optional.ofNullable(snailJobProperties.getToken()).orElse(
|
||||
SystemConstants.DEFAULT_TOKEN));
|
||||
|
||||
Metadata metadata = Metadata
|
||||
.newBuilder()
|
||||
.setUri(path)
|
||||
.putAllHeaders(headersMap)
|
||||
.build();
|
||||
Any build = Any.newBuilder().setValue(UnsafeByteOperations.unsafeWrap(body.getBytes()))
|
||||
.build();
|
||||
GrpcSnailJobRequest snailJobRequest = GrpcSnailJobRequest
|
||||
.newBuilder()
|
||||
.setMetadata(metadata)
|
||||
.setBody(build)
|
||||
.build();
|
||||
|
||||
MethodDescriptor<GrpcSnailJobRequest, GrpcResult> methodDescriptor =
|
||||
MethodDescriptor.<GrpcSnailJobRequest, GrpcResult>newBuilder()
|
||||
.setType(MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(MethodDescriptor.generateFullMethodName("UnaryRequest", "unaryRequest"))
|
||||
.setRequestMarshaller(ProtoUtils.marshaller(GrpcSnailJobRequest.getDefaultInstance()))
|
||||
.setResponseMarshaller(ProtoUtils.marshaller(GrpcResult.getDefaultInstance()))
|
||||
.build();
|
||||
|
||||
// 创建动态代理调用方法
|
||||
return io.grpc.stub.ClientCalls.futureUnaryCall(
|
||||
channel.newCall(methodDescriptor, io.grpc.CallOptions.DEFAULT),
|
||||
snailJobRequest);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package com.aizuda.snailjob.client.common.rpc.client;
|
||||
|
||||
import com.aizuda.snailjob.client.common.Lifecycle;
|
||||
import com.aizuda.snailjob.client.common.config.SnailJobProperties;
|
||||
import com.aizuda.snailjob.client.common.config.SnailJobProperties.ServerConfig;
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author: opensnail
|
||||
* @date : 2024-08-22
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public class GrpcClient implements Lifecycle {
|
||||
private final SnailJobProperties snailJobProperties;
|
||||
@Override
|
||||
public void start() {
|
||||
// 创建 gRPC 频道
|
||||
ServerConfig server = snailJobProperties.getServer();
|
||||
ManagedChannel channel = ManagedChannelBuilder.forAddress(server.getHost(), server.getPort())
|
||||
.usePlaintext()
|
||||
.build();
|
||||
GrpcChannel.setChannel(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
//package com.aizuda.snailjob.client.common.rpc.client;
|
||||
//
|
||||
//import com.aizuda.snailjob.common.core.grpc.auto.GrpcResult;
|
||||
//import com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest;
|
||||
//import com.aizuda.snailjob.common.core.grpc.auto.Metadata;
|
||||
//import com.google.common.util.concurrent.FutureCallback;
|
||||
//import com.google.common.util.concurrent.Futures;
|
||||
//import com.google.common.util.concurrent.ListenableFuture;
|
||||
//import com.google.protobuf.Any;
|
||||
//import com.google.protobuf.UnsafeByteOperations;
|
||||
//import io.grpc.Channel;
|
||||
//import io.grpc.ManagedChannel;
|
||||
//import io.grpc.ManagedChannelBuilder;
|
||||
//import io.grpc.MethodDescriptor;
|
||||
//import io.grpc.protobuf.ProtoUtils;
|
||||
//
|
||||
//import java.util.concurrent.LinkedBlockingDeque;
|
||||
//import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
//import java.util.concurrent.ThreadPoolExecutor;
|
||||
//import java.util.concurrent.TimeUnit;
|
||||
//
|
||||
///**
|
||||
// * @author: shuguang.zhang
|
||||
// * @date : 2024-08-21
|
||||
// */
|
||||
//public class GrpcClient2 {
|
||||
// private final Channel channel;
|
||||
//
|
||||
// public GrpcClient2(Channel channel) {
|
||||
// this.channel = channel;
|
||||
// }
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
// // 创建 gRPC 频道
|
||||
// ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 1788)
|
||||
// .usePlaintext()
|
||||
// .build();
|
||||
//
|
||||
// // 实例化客户端
|
||||
// GrpcClient2 grpcClient = new GrpcClient2(channel);
|
||||
//
|
||||
// String s = "zsg";
|
||||
// Any build = Any.newBuilder().setValue(UnsafeByteOperations.unsafeWrap(s.getBytes())).build();
|
||||
// // 构造请求对象
|
||||
// Metadata metadata = Metadata
|
||||
// .newBuilder()
|
||||
// .setClientIp("11")
|
||||
// .setType("1")
|
||||
// .putHeaders("aa", "bb")
|
||||
// .build();
|
||||
// GrpcSnailJobRequest request = GrpcSnailJobRequest.newBuilder().setMetadata(metadata).setBody(build).build();
|
||||
//
|
||||
// // 动态调用方法并获取响应 "UnaryRequest", "unaryRequest",
|
||||
// ListenableFuture<GrpcResult> future = grpcClient.invokeMethod("unaryRequest", request);
|
||||
// ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
|
||||
// ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2,2,1,TimeUnit.SECONDS, new LinkedBlockingDeque<>());
|
||||
//// System.out.println("Response: " + response.getMessage());
|
||||
// Futures.addCallback(future, new FutureCallback<GrpcResult>() {
|
||||
// @Override
|
||||
// public void onSuccess(final GrpcResult result) {
|
||||
// System.out.println(result);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onFailure(final Throwable t) {
|
||||
// System.out.println(t);
|
||||
// }
|
||||
// }, threadPoolExecutor);
|
||||
//
|
||||
// Futures.withTimeout(future, 5, TimeUnit.SECONDS, scheduledThreadPoolExecutor);
|
||||
// // 关闭频道
|
||||
// channel.shutdown();
|
||||
// }
|
||||
//
|
||||
// public ListenableFuture<GrpcResult> invokeMethod(String methodName, GrpcSnailJobRequest request) {
|
||||
// MethodDescriptor<GrpcSnailJobRequest, GrpcResult> methodDescriptor =
|
||||
// MethodDescriptor.<GrpcSnailJobRequest, GrpcResult>newBuilder()
|
||||
// .setType(MethodDescriptor.MethodType.UNARY)
|
||||
// .setFullMethodName(MethodDescriptor.generateFullMethodName("UnaryRequest", methodName))
|
||||
// .setRequestMarshaller(ProtoUtils.marshaller(GrpcSnailJobRequest.getDefaultInstance()))
|
||||
// .setResponseMarshaller(ProtoUtils.marshaller(GrpcResult.getDefaultInstance()))
|
||||
// .build();
|
||||
//
|
||||
// // 创建动态代理调用方法
|
||||
// return io.grpc.stub.ClientCalls.futureUnaryCall(
|
||||
// channel.newCall(methodDescriptor, io.grpc.CallOptions.DEFAULT),
|
||||
// request);
|
||||
// }
|
||||
//}
|
||||
@ -0,0 +1,104 @@
|
||||
package com.aizuda.snailjob.client.common.rpc.client;
|
||||
|
||||
import cn.hutool.core.date.StopWatch;
|
||||
import com.aizuda.snailjob.client.common.annotation.Mapping;
|
||||
import com.aizuda.snailjob.client.common.exception.SnailJobClientTimeOutException;
|
||||
import com.aizuda.snailjob.common.core.enums.HeadersEnum;
|
||||
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcResult;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.Metadata;
|
||||
import com.aizuda.snailjob.common.core.model.NettyResult;
|
||||
import com.aizuda.snailjob.common.core.model.Result;
|
||||
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
||||
import com.aizuda.snailjob.common.log.SnailJobLog;
|
||||
import com.fasterxml.jackson.databind.util.ByteBufferBackedInputStream;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.protobuf.Any;
|
||||
import com.google.protobuf.UnsafeByteOperations;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* 请求处理器
|
||||
*
|
||||
* @author: opensnail
|
||||
* @date : 2023-05-11 21:45
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public class GrpcClientInvokeHandler<R extends Result<Object>> implements InvocationHandler {
|
||||
private final Consumer<R> consumer;
|
||||
private final boolean async;
|
||||
private final long timeout;
|
||||
private final TimeUnit unit;
|
||||
private static final ExecutorService executorService = Executors.newFixedThreadPool(10);
|
||||
private static final ScheduledThreadPoolExecutor schedule = new ScheduledThreadPoolExecutor(1);
|
||||
public GrpcClientInvokeHandler(boolean async, long timeout, TimeUnit unit, Consumer<R> consumer) {
|
||||
this.consumer = consumer;
|
||||
this.async = async;
|
||||
this.timeout = timeout;
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
|
||||
StopWatch sw = new StopWatch();
|
||||
Mapping annotation = method.getAnnotation(Mapping.class);
|
||||
|
||||
ListenableFuture<GrpcResult> future = GrpcChannel.sendOfUnary(annotation.path(), JsonUtil.toJsonString(args));
|
||||
SnailJobLog.LOCAL.debug("request complete requestId:[{}] 耗时:[{}ms]", sw.getTotalTimeMillis());
|
||||
|
||||
if (async) {
|
||||
if (future == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Futures.addCallback(future, new FutureCallback<>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(final GrpcResult result) {
|
||||
|
||||
ByteBuffer byteBuffer = result.getData().getValue().asReadOnlyByteBuffer();
|
||||
String str = JsonUtil.parseObject(new ByteBufferBackedInputStream(byteBuffer), String.class);
|
||||
consumer.accept((R) new NettyResult(result.getStatus(), result.getMessage(), str, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(final Throwable t) {
|
||||
consumer.accept((R) new NettyResult(StatusEnum.NO.getStatus(), t.getMessage(), null, 1));
|
||||
}
|
||||
}, executorService);
|
||||
|
||||
Futures.withTimeout(future, timeout, unit, schedule);
|
||||
return null;
|
||||
} else {
|
||||
|
||||
try {
|
||||
GrpcResult result = future.get(Integer.MAX_VALUE, TimeUnit.MILLISECONDS);
|
||||
ByteBuffer byteBuffer = result.getData().getValue().asReadOnlyByteBuffer();
|
||||
String str = JsonUtil.parseObject(new ByteBufferBackedInputStream(byteBuffer), String.class);
|
||||
return (R) new Result(result.getStatus(), result.getMessage(), str);
|
||||
} catch (ExecutionException e) {
|
||||
throw e.getCause();
|
||||
} catch (TimeoutException e) {
|
||||
throw new SnailJobClientTimeOutException("Request to remote interface timed out. path:[{}]", annotation.path());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -67,10 +67,10 @@ public class RequestBuilder<T, R extends Result<Object>> {
|
||||
throw new SnailJobClientException("class not found exception to: [{}]", clintInterface.getName());
|
||||
}
|
||||
|
||||
RpcClientInvokeHandler<R> rpcClientInvokeHandler = new RpcClientInvokeHandler<>(async, timeout, unit, callback);
|
||||
|
||||
// RpcClientInvokeHandler<R> rpcClientInvokeHandler = new RpcClientInvokeHandler<>(async, timeout, unit, callback);
|
||||
GrpcClientInvokeHandler invokeHandler = new GrpcClientInvokeHandler(async, timeout, unit, callback);
|
||||
return (T) Proxy.newProxyInstance(clintInterface.getClassLoader(),
|
||||
new Class[]{clintInterface}, rpcClientInvokeHandler);
|
||||
new Class[]{clintInterface}, invokeHandler);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
package com.aizuda.snailjob.client.common.rpc.server;
|
||||
|
||||
import io.grpc.Context;
|
||||
import io.grpc.Contexts;
|
||||
import io.grpc.Metadata;
|
||||
import io.grpc.ServerCall;
|
||||
import io.grpc.ServerCall.Listener;
|
||||
import io.grpc.ServerCallHandler;
|
||||
import io.grpc.ServerInterceptor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author: opensnail
|
||||
* @date : 2024-08-22
|
||||
*/
|
||||
@Slf4j
|
||||
public class GrpcInterceptor implements ServerInterceptor {
|
||||
|
||||
@Override
|
||||
public <ReqT, RespT> Listener<ReqT> interceptCall(final ServerCall<ReqT, RespT> serverCall, final Metadata metadata,
|
||||
final ServerCallHandler<ReqT, RespT> serverCallHandler) {
|
||||
String fullMethodName = serverCall.getMethodDescriptor().getFullMethodName();
|
||||
long start = System.currentTimeMillis();
|
||||
Context context = Context.current();
|
||||
|
||||
try {
|
||||
return Contexts.interceptCall(context, serverCall, metadata, serverCallHandler);
|
||||
} finally {
|
||||
log.info("method invoked: {} cast:{}ms", fullMethodName, System.currentTimeMillis() - start);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
package com.aizuda.snailjob.client.common.rpc.server;
|
||||
|
||||
import com.aizuda.snailjob.client.common.config.SnailJobProperties;
|
||||
import com.aizuda.snailjob.client.common.config.SnailJobProperties.DispatcherThreadPool;
|
||||
import com.aizuda.snailjob.client.common.rpc.supports.handler.SnailDispatcherRequestHandler;
|
||||
import com.aizuda.snailjob.client.common.rpc.supports.handler.UnaryRequestHandler;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcResult;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest;
|
||||
import io.grpc.MethodDescriptor;
|
||||
import io.grpc.ServerBuilder;
|
||||
import io.grpc.ServerCallHandler;
|
||||
import io.grpc.ServerServiceDefinition;
|
||||
import io.grpc.protobuf.ProtoUtils;
|
||||
import io.grpc.stub.ServerCalls;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.devh.boot.grpc.server.serverfactory.GrpcServerConfigurer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
|
||||
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class GrpcServerConsumerConfig implements GrpcServerConfigurer {
|
||||
private final SnailDispatcherRequestHandler handler;
|
||||
private final SnailJobProperties snailJobProperties;
|
||||
|
||||
@Override
|
||||
public void accept(ServerBuilder<?> serverBuilder) {
|
||||
DispatcherThreadPool threadPool = snailJobProperties.getDispatcherThreadPool();
|
||||
ThreadPoolExecutor dispatcherThreadPool = new ThreadPoolExecutor(
|
||||
threadPool.getCorePoolSize(), threadPool.getMaximumPoolSize(), threadPool.getKeepAliveTime(),
|
||||
threadPool.getTimeUnit(), new LinkedBlockingQueue<>(threadPool.getQueueCapacity()),
|
||||
new CustomizableThreadFactory("snail-grpc-server-"));
|
||||
|
||||
// 创建服务定义
|
||||
ServerServiceDefinition serviceDefinition = createServiceDefinition(
|
||||
"UnaryRequest", "unaryRequest",
|
||||
new UnaryRequestHandler(dispatcherThreadPool, handler));
|
||||
serverBuilder.addService(serviceDefinition);
|
||||
serverBuilder.intercept(new GrpcInterceptor());
|
||||
}
|
||||
|
||||
public static ServerServiceDefinition createServiceDefinition(
|
||||
String serviceName,
|
||||
String methodName,
|
||||
ServerCalls.UnaryMethod<GrpcSnailJobRequest, GrpcResult> unaryMethod) {
|
||||
|
||||
MethodDescriptor<GrpcSnailJobRequest, GrpcResult> methodDescriptor =
|
||||
MethodDescriptor.<GrpcSnailJobRequest, GrpcResult>newBuilder()
|
||||
.setType(MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(MethodDescriptor.generateFullMethodName(serviceName, methodName))
|
||||
.setRequestMarshaller(ProtoUtils.marshaller(GrpcSnailJobRequest.getDefaultInstance()))
|
||||
.setResponseMarshaller(ProtoUtils.marshaller(GrpcResult.getDefaultInstance()))
|
||||
.build();
|
||||
|
||||
ServerCallHandler<GrpcSnailJobRequest, GrpcResult> callHandler = ServerCalls.asyncUnaryCall(unaryMethod);
|
||||
|
||||
return ServerServiceDefinition.builder(serviceName)
|
||||
.addMethod(methodDescriptor, callHandler)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@ -31,7 +31,7 @@ import org.springframework.stereotype.Component;
|
||||
* @date : 2024-04-12 23:03
|
||||
* @since 3.3.0
|
||||
*/
|
||||
@Component
|
||||
//@Component
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
package com.aizuda.snailjob.client.common.rpc.supports.handler;
|
||||
|
||||
|
||||
import com.aizuda.snailjob.client.common.rpc.supports.http.HttpRequest;
|
||||
import com.aizuda.snailjob.client.common.rpc.supports.http.HttpResponse;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcResult;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* netty客户端请求模型
|
||||
*
|
||||
* @author: opensnail
|
||||
* @date : 2023-07-24 09:32
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class GrpcRequest {
|
||||
|
||||
private GrpcSnailJobRequest snailJobRequest;
|
||||
private final HttpResponse httpResponse;
|
||||
private final HttpRequest httpRequest;
|
||||
|
||||
}
|
||||
@ -14,7 +14,9 @@ import io.netty.handler.codec.http.*;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
@ -46,6 +48,12 @@ public class NettyHttpServerHandler extends SimpleChannelInboundHandler<FullHttp
|
||||
|
||||
String content = fullHttpRequest.content().toString(CharsetUtil.UTF_8);
|
||||
HttpHeaders headers = fullHttpRequest.headers();
|
||||
Map<String, String> headerMap = new HashMap<>();
|
||||
|
||||
for (final Entry<String, String> header : headers) {
|
||||
headerMap.put(header.getKey(), header.getValue());
|
||||
}
|
||||
|
||||
String uri = fullHttpRequest.uri();
|
||||
NettyHttpRequest nettyHttpRequest = NettyHttpRequest.builder()
|
||||
.keepAlive(HttpUtil.isKeepAlive(fullHttpRequest))
|
||||
@ -55,7 +63,7 @@ public class NettyHttpServerHandler extends SimpleChannelInboundHandler<FullHttp
|
||||
.headers(headers)
|
||||
.content(content)
|
||||
.httpResponse(new com.aizuda.snailjob.client.common.rpc.supports.http.HttpResponse())
|
||||
.httpRequest(new com.aizuda.snailjob.client.common.rpc.supports.http.HttpRequest(headers, uri))
|
||||
.httpRequest(new com.aizuda.snailjob.client.common.rpc.supports.http.HttpRequest(headerMap, uri))
|
||||
.build();
|
||||
|
||||
// 执行任务
|
||||
|
||||
@ -13,6 +13,8 @@ import com.aizuda.snailjob.client.common.rpc.supports.http.HttpResponse;
|
||||
import com.aizuda.snailjob.client.common.rpc.supports.scan.EndPointInfo;
|
||||
import com.aizuda.snailjob.common.core.constant.SystemConstants;
|
||||
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.Metadata;
|
||||
import com.aizuda.snailjob.common.core.model.NettyResult;
|
||||
import com.aizuda.snailjob.common.core.model.Result;
|
||||
import com.aizuda.snailjob.common.core.model.SnailJobRequest;
|
||||
@ -21,6 +23,8 @@ import com.aizuda.snailjob.common.log.SnailJobLog;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.util.ByteBufferBackedInputStream;
|
||||
import com.google.protobuf.Any;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@ -28,6 +32,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -111,6 +116,80 @@ public class SnailDispatcherRequestHandler {
|
||||
return nettyResult;
|
||||
}
|
||||
|
||||
public NettyResult dispatch(GrpcRequest request) {
|
||||
NettyResult nettyResult = new NettyResult();
|
||||
|
||||
HttpRequest httpRequest = request.getHttpRequest();
|
||||
HttpResponse httpResponse = request.getHttpResponse();
|
||||
|
||||
List<HandlerInterceptor> handlerInterceptors = handlerInterceptors();
|
||||
|
||||
GrpcSnailJobRequest snailJobRequest = request.getSnailJobRequest();
|
||||
EndPointInfo endPointInfo = null;
|
||||
Result resultObj = null;
|
||||
Exception e = null;
|
||||
try {
|
||||
Metadata metadata = snailJobRequest.getMetadata();
|
||||
Map<String, String> headersMap = metadata.getHeadersMap();
|
||||
String snailJobAuth = headersMap.get(SystemConstants.SNAIL_JOB_AUTH_TOKEN);
|
||||
String configToken = Optional.ofNullable(snailJobProperties.getToken()).orElse(SystemConstants.DEFAULT_TOKEN);
|
||||
if (!configToken.equals(snailJobAuth)) {
|
||||
throw new SnailJobClientException("认证失败.【请检查配置的Token是否正确】");
|
||||
}
|
||||
|
||||
UrlBuilder builder = UrlBuilder.ofHttp(httpRequest.getUri());
|
||||
endPointInfo = EndPointInfoCache.get(builder.getPathStr(), RequestMethod.POST);
|
||||
if (Objects.isNull(endPointInfo)) {
|
||||
throw new SnailJobClientException("无法找到对应的处理请检查对应的包是否正确引入. " +
|
||||
"path:[{}] requestMethod:[{}]", builder.getPathStr());
|
||||
}
|
||||
|
||||
Class<?>[] paramTypes = endPointInfo.getMethod().getParameterTypes();
|
||||
GrpcSnailJobRequest grpcSnailJobRequest = request.getSnailJobRequest();
|
||||
Any body = grpcSnailJobRequest.getBody();
|
||||
ByteBuffer byteBuffer = body.getValue().asReadOnlyByteBuffer();
|
||||
Object[] args = JsonUtil.parseObject(new ByteBufferBackedInputStream(byteBuffer), Object[].class);
|
||||
|
||||
Object[] deSerialize = (Object[]) deSerialize(JsonUtil.toJsonString(args), endPointInfo.getMethod(),
|
||||
httpRequest, httpResponse);
|
||||
|
||||
for (final HandlerInterceptor handlerInterceptor : handlerInterceptors) {
|
||||
if (!handlerInterceptor.preHandle(httpRequest, httpResponse, endPointInfo)) {
|
||||
return nettyResult;
|
||||
}
|
||||
}
|
||||
|
||||
if (paramTypes.length > 0) {
|
||||
resultObj = (Result) ReflectionUtils.invokeMethod(endPointInfo.getMethod(),
|
||||
endPointInfo.getExecutor(), deSerialize);
|
||||
} else {
|
||||
resultObj = (Result) ReflectionUtils.invokeMethod(endPointInfo.getMethod(),
|
||||
endPointInfo.getExecutor());
|
||||
}
|
||||
|
||||
for (final HandlerInterceptor handlerInterceptor : handlerInterceptors) {
|
||||
handlerInterceptor.postHandle(httpRequest, httpResponse, endPointInfo);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
SnailJobLog.LOCAL.error("http request error. [{}]", snailJobRequest, ex);
|
||||
nettyResult.setMessage(ex.getMessage()).setStatus(StatusEnum.NO.getStatus());
|
||||
e = ex;
|
||||
} finally {
|
||||
nettyResult.setReqId(0);
|
||||
if (Objects.nonNull(resultObj)) {
|
||||
nettyResult.setData(resultObj.getData())
|
||||
.setMessage(resultObj.getMessage())
|
||||
.setStatus(resultObj.getStatus());
|
||||
}
|
||||
|
||||
for (final HandlerInterceptor handlerInterceptor : handlerInterceptors) {
|
||||
handlerInterceptor.afterCompletion(httpRequest, httpResponse, endPointInfo, e);
|
||||
}
|
||||
}
|
||||
|
||||
return nettyResult;
|
||||
}
|
||||
|
||||
private static List<HandlerInterceptor> handlerInterceptors() {
|
||||
List<HandlerInterceptor> handlerInterceptors = ServiceLoaderUtil.loadList(HandlerInterceptor.class);
|
||||
if (CollUtil.isEmpty(handlerInterceptors)) {
|
||||
|
||||
@ -0,0 +1,70 @@
|
||||
package com.aizuda.snailjob.client.common.rpc.supports.handler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aizuda.snailjob.client.common.rpc.supports.http.HttpRequest;
|
||||
import com.aizuda.snailjob.client.common.rpc.supports.http.HttpResponse;
|
||||
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcResult;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.Metadata;
|
||||
import com.aizuda.snailjob.common.core.model.NettyResult;
|
||||
import com.aizuda.snailjob.common.core.model.SnailJobRequest;
|
||||
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
||||
import com.google.protobuf.Any;
|
||||
import com.google.protobuf.UnsafeByteOperations;
|
||||
import io.grpc.stub.ServerCalls;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import io.netty.handler.codec.http.HttpUtil;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* @author: opensnail
|
||||
* @date : 2024-08-22
|
||||
*/
|
||||
public class UnaryRequestHandler implements ServerCalls.UnaryMethod<GrpcSnailJobRequest, GrpcResult>{
|
||||
|
||||
|
||||
private final ThreadPoolExecutor threadPoolExecutor;
|
||||
private final SnailDispatcherRequestHandler dispatcher;
|
||||
public UnaryRequestHandler(final ThreadPoolExecutor dispatcherThreadPool,
|
||||
final SnailDispatcherRequestHandler handler) {
|
||||
this.threadPoolExecutor = dispatcherThreadPool;
|
||||
this.dispatcher = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(final GrpcSnailJobRequest snailJobRequest, final StreamObserver<GrpcResult> streamObserver) {
|
||||
|
||||
Metadata metadata = snailJobRequest.getMetadata();
|
||||
|
||||
GrpcRequest grpcRequest = GrpcRequest.builder()
|
||||
.httpRequest(new HttpRequest( metadata.getHeadersMap(), metadata.getUri()))
|
||||
.httpResponse(new HttpResponse())
|
||||
.snailJobRequest(snailJobRequest)
|
||||
.build();
|
||||
|
||||
// 执行任务
|
||||
threadPoolExecutor.execute(() -> {
|
||||
NettyResult nettyResult = null;
|
||||
try {
|
||||
nettyResult = dispatcher.dispatch(grpcRequest);
|
||||
} catch (Exception e) {
|
||||
nettyResult = new NettyResult(StatusEnum.NO.getStatus(), e.getMessage(), null, 0);
|
||||
} finally {
|
||||
GrpcResult grpcResult = GrpcResult.newBuilder()
|
||||
.setStatus(nettyResult.getStatus())
|
||||
.setMessage(Optional.ofNullable(nettyResult.getMessage()).orElse(StrUtil.EMPTY))
|
||||
.setData(Any.newBuilder()
|
||||
.setValue(UnsafeByteOperations.unsafeWrap(JsonUtil.toJsonString(nettyResult.getData()).getBytes()))
|
||||
.build())
|
||||
.build();
|
||||
|
||||
streamObserver.onNext(grpcResult);
|
||||
streamObserver.onCompleted();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,9 @@
|
||||
package com.aizuda.snailjob.client.common.rpc.supports.http;
|
||||
|
||||
import io.netty.handler.codec.http.HttpHeaders;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: opensnail
|
||||
* @date : 2024-04-12
|
||||
@ -10,10 +11,10 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
public class HttpRequest {
|
||||
private final HttpHeaders headers;
|
||||
private final Map<String, String> headers;
|
||||
private final String uri;
|
||||
|
||||
public HttpRequest(HttpHeaders headers, String uri) {
|
||||
public HttpRequest(Map<String, String> headers, String uri) {
|
||||
this.headers = headers;
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
@ -69,10 +69,69 @@
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-common</artifactId>
|
||||
</dependency>
|
||||
<!-- 根据message定义,生成java的model类 -->
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-protobuf</artifactId>
|
||||
<version>1.63.0</version>
|
||||
</dependency>
|
||||
<!-- 根据service定义,生成java的服务端代码和客户端代码 -->
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-stub</artifactId>
|
||||
<version>1.63.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
<version>3.25.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.api.grpc</groupId>
|
||||
<artifactId>proto-google-common-protos</artifactId>
|
||||
<version>2.43.0</version>
|
||||
</dependency>
|
||||
<!-- 生成的代码使用到了javax的注解 -->
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>javax.annotation-api</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>kr.motd.maven</groupId>
|
||||
<artifactId>os-maven-plugin</artifactId>
|
||||
<version>1.6.2</version>
|
||||
</extension>
|
||||
</extensions>
|
||||
<plugins>
|
||||
<!-- reuse when you need to update grpc model -->
|
||||
<!-- <plugin>-->
|
||||
<!-- <groupId>org.xolstice.maven.plugins</groupId>-->
|
||||
<!-- <artifactId>protobuf-maven-plugin</artifactId>-->
|
||||
<!-- <version>0.6.1</version>-->
|
||||
<!-- <configuration>-->
|
||||
<!-- <protocArtifact>com.google.protobuf:protoc:3.24.0:exe:${os.detected.classifier}</protocArtifact>-->
|
||||
<!-- <pluginId>grpc-java</pluginId>-->
|
||||
<!-- <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.63.0:exe:${os.detected.classifier}</pluginArtifact>-->
|
||||
<!-- <protoSourceRoot>${project.basedir}/src/main/proto</protoSourceRoot>-->
|
||||
<!-- <clearOutputDirectory>false</clearOutputDirectory>-->
|
||||
<!-- <!–通过插件生成的协议代码存放地址–>-->
|
||||
<!-- <outputDirectory>${basedir}/src/main/java</outputDirectory>-->
|
||||
<!-- </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>
|
||||
|
||||
@ -0,0 +1,800 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: snail_job_grpc_service.proto
|
||||
|
||||
package com.aizuda.snailjob.common.core.grpc.auto;
|
||||
|
||||
/**
|
||||
* Protobuf type {@code GrpcResult}
|
||||
*/
|
||||
public final class GrpcResult extends
|
||||
com.google.protobuf.GeneratedMessageV3 implements
|
||||
// @@protoc_insertion_point(message_implements:GrpcResult)
|
||||
GrpcResultOrBuilder {
|
||||
private static final long serialVersionUID = 0L;
|
||||
// Use GrpcResult.newBuilder() to construct.
|
||||
private GrpcResult(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
|
||||
super(builder);
|
||||
}
|
||||
private GrpcResult() {
|
||||
message_ = "";
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@SuppressWarnings({"unused"})
|
||||
protected java.lang.Object newInstance(
|
||||
UnusedPrivateParameter unused) {
|
||||
return new GrpcResult();
|
||||
}
|
||||
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return com.aizuda.snailjob.common.core.grpc.auto.SnailJobGrpcService.internal_static_GrpcResult_descriptor;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return com.aizuda.snailjob.common.core.grpc.auto.SnailJobGrpcService.internal_static_GrpcResult_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcResult.class, com.aizuda.snailjob.common.core.grpc.auto.GrpcResult.Builder.class);
|
||||
}
|
||||
|
||||
private int bitField0_;
|
||||
public static final int STATUS_FIELD_NUMBER = 1;
|
||||
private int status_ = 0;
|
||||
/**
|
||||
* <code>int32 status = 1;</code>
|
||||
* @return The status.
|
||||
*/
|
||||
@java.lang.Override
|
||||
public int getStatus() {
|
||||
return status_;
|
||||
}
|
||||
|
||||
public static final int MESSAGE_FIELD_NUMBER = 2;
|
||||
@SuppressWarnings("serial")
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public static final int DATA_FIELD_NUMBER = 3;
|
||||
private com.google.protobuf.Any data_;
|
||||
/**
|
||||
* <code>.google.protobuf.Any data = 3;</code>
|
||||
* @return Whether the data field is set.
|
||||
*/
|
||||
@java.lang.Override
|
||||
public boolean hasData() {
|
||||
return ((bitField0_ & 0x00000001) != 0);
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any data = 3;</code>
|
||||
* @return The data.
|
||||
*/
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Any getData() {
|
||||
return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_;
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any data = 3;</code>
|
||||
*/
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.AnyOrBuilder getDataOrBuilder() {
|
||||
return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_;
|
||||
}
|
||||
|
||||
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 (status_ != 0) {
|
||||
output.writeInt32(1, status_);
|
||||
}
|
||||
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(message_)) {
|
||||
com.google.protobuf.GeneratedMessageV3.writeString(output, 2, message_);
|
||||
}
|
||||
if (((bitField0_ & 0x00000001) != 0)) {
|
||||
output.writeMessage(3, getData());
|
||||
}
|
||||
getUnknownFields().writeTo(output);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public int getSerializedSize() {
|
||||
int size = memoizedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (status_ != 0) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeInt32Size(1, status_);
|
||||
}
|
||||
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(message_)) {
|
||||
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, message_);
|
||||
}
|
||||
if (((bitField0_ & 0x00000001) != 0)) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeMessageSize(3, getData());
|
||||
}
|
||||
size += getUnknownFields().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.aizuda.snailjob.common.core.grpc.auto.GrpcResult)) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcResult other = (com.aizuda.snailjob.common.core.grpc.auto.GrpcResult) obj;
|
||||
|
||||
if (getStatus()
|
||||
!= other.getStatus()) return false;
|
||||
if (!getMessage()
|
||||
.equals(other.getMessage())) return false;
|
||||
if (hasData() != other.hasData()) return false;
|
||||
if (hasData()) {
|
||||
if (!getData()
|
||||
.equals(other.getData())) return false;
|
||||
}
|
||||
if (!getUnknownFields().equals(other.getUnknownFields())) 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) + STATUS_FIELD_NUMBER;
|
||||
hash = (53 * hash) + getStatus();
|
||||
hash = (37 * hash) + MESSAGE_FIELD_NUMBER;
|
||||
hash = (53 * hash) + getMessage().hashCode();
|
||||
if (hasData()) {
|
||||
hash = (37 * hash) + DATA_FIELD_NUMBER;
|
||||
hash = (53 * hash) + getData().hashCode();
|
||||
}
|
||||
hash = (29 * hash) + getUnknownFields().hashCode();
|
||||
memoizedHashCode = hash;
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcResult parseFrom(
|
||||
java.nio.ByteBuffer data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcResult parseFrom(
|
||||
java.nio.ByteBuffer data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcResult parseFrom(
|
||||
com.google.protobuf.ByteString data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcResult parseFrom(
|
||||
com.google.protobuf.ByteString data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcResult parseFrom(byte[] data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcResult parseFrom(
|
||||
byte[] data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcResult parseFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input);
|
||||
}
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcResult 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.aizuda.snailjob.common.core.grpc.auto.GrpcResult parseDelimitedFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseDelimitedWithIOException(PARSER, input);
|
||||
}
|
||||
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcResult 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.aizuda.snailjob.common.core.grpc.auto.GrpcResult parseFrom(
|
||||
com.google.protobuf.CodedInputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input);
|
||||
}
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcResult 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.aizuda.snailjob.common.core.grpc.auto.GrpcResult 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 GrpcResult}
|
||||
*/
|
||||
public static final class Builder extends
|
||||
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
|
||||
// @@protoc_insertion_point(builder_implements:GrpcResult)
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcResultOrBuilder {
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return com.aizuda.snailjob.common.core.grpc.auto.SnailJobGrpcService.internal_static_GrpcResult_descriptor;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return com.aizuda.snailjob.common.core.grpc.auto.SnailJobGrpcService.internal_static_GrpcResult_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcResult.class, com.aizuda.snailjob.common.core.grpc.auto.GrpcResult.Builder.class);
|
||||
}
|
||||
|
||||
// Construct using com.aizuda.snailjob.common.core.grpc.auto.GrpcResult.newBuilder()
|
||||
private Builder() {
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
|
||||
private Builder(
|
||||
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
|
||||
super(parent);
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
private void maybeForceBuilderInitialization() {
|
||||
if (com.google.protobuf.GeneratedMessageV3
|
||||
.alwaysUseFieldBuilders) {
|
||||
getDataFieldBuilder();
|
||||
}
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder clear() {
|
||||
super.clear();
|
||||
bitField0_ = 0;
|
||||
status_ = 0;
|
||||
message_ = "";
|
||||
data_ = null;
|
||||
if (dataBuilder_ != null) {
|
||||
dataBuilder_.dispose();
|
||||
dataBuilder_ = null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptorForType() {
|
||||
return com.aizuda.snailjob.common.core.grpc.auto.SnailJobGrpcService.internal_static_GrpcResult_descriptor;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.aizuda.snailjob.common.core.grpc.auto.GrpcResult getDefaultInstanceForType() {
|
||||
return com.aizuda.snailjob.common.core.grpc.auto.GrpcResult.getDefaultInstance();
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.aizuda.snailjob.common.core.grpc.auto.GrpcResult build() {
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcResult result = buildPartial();
|
||||
if (!result.isInitialized()) {
|
||||
throw newUninitializedMessageException(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.aizuda.snailjob.common.core.grpc.auto.GrpcResult buildPartial() {
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcResult result = new com.aizuda.snailjob.common.core.grpc.auto.GrpcResult(this);
|
||||
if (bitField0_ != 0) { buildPartial0(result); }
|
||||
onBuilt();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void buildPartial0(com.aizuda.snailjob.common.core.grpc.auto.GrpcResult result) {
|
||||
int from_bitField0_ = bitField0_;
|
||||
if (((from_bitField0_ & 0x00000001) != 0)) {
|
||||
result.status_ = status_;
|
||||
}
|
||||
if (((from_bitField0_ & 0x00000002) != 0)) {
|
||||
result.message_ = message_;
|
||||
}
|
||||
int to_bitField0_ = 0;
|
||||
if (((from_bitField0_ & 0x00000004) != 0)) {
|
||||
result.data_ = dataBuilder_ == null
|
||||
? data_
|
||||
: dataBuilder_.build();
|
||||
to_bitField0_ |= 0x00000001;
|
||||
}
|
||||
result.bitField0_ |= to_bitField0_;
|
||||
}
|
||||
|
||||
@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.aizuda.snailjob.common.core.grpc.auto.GrpcResult) {
|
||||
return mergeFrom((com.aizuda.snailjob.common.core.grpc.auto.GrpcResult)other);
|
||||
} else {
|
||||
super.mergeFrom(other);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Builder mergeFrom(com.aizuda.snailjob.common.core.grpc.auto.GrpcResult other) {
|
||||
if (other == com.aizuda.snailjob.common.core.grpc.auto.GrpcResult.getDefaultInstance()) return this;
|
||||
if (other.getStatus() != 0) {
|
||||
setStatus(other.getStatus());
|
||||
}
|
||||
if (!other.getMessage().isEmpty()) {
|
||||
message_ = other.message_;
|
||||
bitField0_ |= 0x00000002;
|
||||
onChanged();
|
||||
}
|
||||
if (other.hasData()) {
|
||||
mergeData(other.getData());
|
||||
}
|
||||
this.mergeUnknownFields(other.getUnknownFields());
|
||||
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 {
|
||||
if (extensionRegistry == null) {
|
||||
throw new java.lang.NullPointerException();
|
||||
}
|
||||
try {
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
int tag = input.readTag();
|
||||
switch (tag) {
|
||||
case 0:
|
||||
done = true;
|
||||
break;
|
||||
case 8: {
|
||||
status_ = input.readInt32();
|
||||
bitField0_ |= 0x00000001;
|
||||
break;
|
||||
} // case 8
|
||||
case 18: {
|
||||
message_ = input.readStringRequireUtf8();
|
||||
bitField0_ |= 0x00000002;
|
||||
break;
|
||||
} // case 18
|
||||
case 26: {
|
||||
input.readMessage(
|
||||
getDataFieldBuilder().getBuilder(),
|
||||
extensionRegistry);
|
||||
bitField0_ |= 0x00000004;
|
||||
break;
|
||||
} // case 26
|
||||
default: {
|
||||
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
|
||||
done = true; // was an endgroup tag
|
||||
}
|
||||
break;
|
||||
} // default:
|
||||
} // switch (tag)
|
||||
} // while (!done)
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
throw e.unwrapIOException();
|
||||
} finally {
|
||||
onChanged();
|
||||
} // finally
|
||||
return this;
|
||||
}
|
||||
private int bitField0_;
|
||||
|
||||
private int status_ ;
|
||||
/**
|
||||
* <code>int32 status = 1;</code>
|
||||
* @return The status.
|
||||
*/
|
||||
@java.lang.Override
|
||||
public int getStatus() {
|
||||
return status_;
|
||||
}
|
||||
/**
|
||||
* <code>int32 status = 1;</code>
|
||||
* @param value The status to set.
|
||||
* @return This builder for chaining.
|
||||
*/
|
||||
public Builder setStatus(int value) {
|
||||
|
||||
status_ = value;
|
||||
bitField0_ |= 0x00000001;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>int32 status = 1;</code>
|
||||
* @return This builder for chaining.
|
||||
*/
|
||||
public Builder clearStatus() {
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
status_ = 0;
|
||||
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;
|
||||
bitField0_ |= 0x00000002;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>string message = 2;</code>
|
||||
* @return This builder for chaining.
|
||||
*/
|
||||
public Builder clearMessage() {
|
||||
message_ = getDefaultInstance().getMessage();
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
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;
|
||||
bitField0_ |= 0x00000002;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
private com.google.protobuf.Any data_;
|
||||
private com.google.protobuf.SingleFieldBuilderV3<
|
||||
com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> dataBuilder_;
|
||||
/**
|
||||
* <code>.google.protobuf.Any data = 3;</code>
|
||||
* @return Whether the data field is set.
|
||||
*/
|
||||
public boolean hasData() {
|
||||
return ((bitField0_ & 0x00000004) != 0);
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any data = 3;</code>
|
||||
* @return The data.
|
||||
*/
|
||||
public com.google.protobuf.Any getData() {
|
||||
if (dataBuilder_ == null) {
|
||||
return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_;
|
||||
} else {
|
||||
return dataBuilder_.getMessage();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any data = 3;</code>
|
||||
*/
|
||||
public Builder setData(com.google.protobuf.Any value) {
|
||||
if (dataBuilder_ == null) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
data_ = value;
|
||||
} else {
|
||||
dataBuilder_.setMessage(value);
|
||||
}
|
||||
bitField0_ |= 0x00000004;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any data = 3;</code>
|
||||
*/
|
||||
public Builder setData(
|
||||
com.google.protobuf.Any.Builder builderForValue) {
|
||||
if (dataBuilder_ == null) {
|
||||
data_ = builderForValue.build();
|
||||
} else {
|
||||
dataBuilder_.setMessage(builderForValue.build());
|
||||
}
|
||||
bitField0_ |= 0x00000004;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any data = 3;</code>
|
||||
*/
|
||||
public Builder mergeData(com.google.protobuf.Any value) {
|
||||
if (dataBuilder_ == null) {
|
||||
if (((bitField0_ & 0x00000004) != 0) &&
|
||||
data_ != null &&
|
||||
data_ != com.google.protobuf.Any.getDefaultInstance()) {
|
||||
getDataBuilder().mergeFrom(value);
|
||||
} else {
|
||||
data_ = value;
|
||||
}
|
||||
} else {
|
||||
dataBuilder_.mergeFrom(value);
|
||||
}
|
||||
if (data_ != null) {
|
||||
bitField0_ |= 0x00000004;
|
||||
onChanged();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any data = 3;</code>
|
||||
*/
|
||||
public Builder clearData() {
|
||||
bitField0_ = (bitField0_ & ~0x00000004);
|
||||
data_ = null;
|
||||
if (dataBuilder_ != null) {
|
||||
dataBuilder_.dispose();
|
||||
dataBuilder_ = null;
|
||||
}
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any data = 3;</code>
|
||||
*/
|
||||
public com.google.protobuf.Any.Builder getDataBuilder() {
|
||||
bitField0_ |= 0x00000004;
|
||||
onChanged();
|
||||
return getDataFieldBuilder().getBuilder();
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any data = 3;</code>
|
||||
*/
|
||||
public com.google.protobuf.AnyOrBuilder getDataOrBuilder() {
|
||||
if (dataBuilder_ != null) {
|
||||
return dataBuilder_.getMessageOrBuilder();
|
||||
} else {
|
||||
return data_ == null ?
|
||||
com.google.protobuf.Any.getDefaultInstance() : data_;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any data = 3;</code>
|
||||
*/
|
||||
private com.google.protobuf.SingleFieldBuilderV3<
|
||||
com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>
|
||||
getDataFieldBuilder() {
|
||||
if (dataBuilder_ == null) {
|
||||
dataBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
|
||||
com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>(
|
||||
getData(),
|
||||
getParentForChildren(),
|
||||
isClean());
|
||||
data_ = null;
|
||||
}
|
||||
return dataBuilder_;
|
||||
}
|
||||
@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:GrpcResult)
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(class_scope:GrpcResult)
|
||||
private static final com.aizuda.snailjob.common.core.grpc.auto.GrpcResult DEFAULT_INSTANCE;
|
||||
static {
|
||||
DEFAULT_INSTANCE = new com.aizuda.snailjob.common.core.grpc.auto.GrpcResult();
|
||||
}
|
||||
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcResult getDefaultInstance() {
|
||||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
private static final com.google.protobuf.Parser<GrpcResult>
|
||||
PARSER = new com.google.protobuf.AbstractParser<GrpcResult>() {
|
||||
@java.lang.Override
|
||||
public GrpcResult parsePartialFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
Builder builder = newBuilder();
|
||||
try {
|
||||
builder.mergeFrom(input, extensionRegistry);
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
throw e.setUnfinishedMessage(builder.buildPartial());
|
||||
} catch (com.google.protobuf.UninitializedMessageException e) {
|
||||
throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial());
|
||||
} catch (java.io.IOException e) {
|
||||
throw new com.google.protobuf.InvalidProtocolBufferException(e)
|
||||
.setUnfinishedMessage(builder.buildPartial());
|
||||
}
|
||||
return builder.buildPartial();
|
||||
}
|
||||
};
|
||||
|
||||
public static com.google.protobuf.Parser<GrpcResult> parser() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Parser<GrpcResult> getParserForType() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.aizuda.snailjob.common.core.grpc.auto.GrpcResult getDefaultInstanceForType() {
|
||||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,42 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: snail_job_grpc_service.proto
|
||||
|
||||
package com.aizuda.snailjob.common.core.grpc.auto;
|
||||
|
||||
public interface GrpcResultOrBuilder extends
|
||||
// @@protoc_insertion_point(interface_extends:GrpcResult)
|
||||
com.google.protobuf.MessageOrBuilder {
|
||||
|
||||
/**
|
||||
* <code>int32 status = 1;</code>
|
||||
* @return The status.
|
||||
*/
|
||||
int getStatus();
|
||||
|
||||
/**
|
||||
* <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();
|
||||
|
||||
/**
|
||||
* <code>.google.protobuf.Any data = 3;</code>
|
||||
* @return Whether the data field is set.
|
||||
*/
|
||||
boolean hasData();
|
||||
/**
|
||||
* <code>.google.protobuf.Any data = 3;</code>
|
||||
* @return The data.
|
||||
*/
|
||||
com.google.protobuf.Any getData();
|
||||
/**
|
||||
* <code>.google.protobuf.Any data = 3;</code>
|
||||
*/
|
||||
com.google.protobuf.AnyOrBuilder getDataOrBuilder();
|
||||
}
|
||||
@ -0,0 +1,783 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: snail_job_grpc_service.proto
|
||||
|
||||
package com.aizuda.snailjob.common.core.grpc.auto;
|
||||
|
||||
/**
|
||||
* Protobuf type {@code GrpcSnailJobRequest}
|
||||
*/
|
||||
public final class GrpcSnailJobRequest extends
|
||||
com.google.protobuf.GeneratedMessageV3 implements
|
||||
// @@protoc_insertion_point(message_implements:GrpcSnailJobRequest)
|
||||
GrpcSnailJobRequestOrBuilder {
|
||||
private static final long serialVersionUID = 0L;
|
||||
// Use GrpcSnailJobRequest.newBuilder() to construct.
|
||||
private GrpcSnailJobRequest(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
|
||||
super(builder);
|
||||
}
|
||||
private GrpcSnailJobRequest() {
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@SuppressWarnings({"unused"})
|
||||
protected java.lang.Object newInstance(
|
||||
UnusedPrivateParameter unused) {
|
||||
return new GrpcSnailJobRequest();
|
||||
}
|
||||
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return com.aizuda.snailjob.common.core.grpc.auto.SnailJobGrpcService.internal_static_GrpcSnailJobRequest_descriptor;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return com.aizuda.snailjob.common.core.grpc.auto.SnailJobGrpcService.internal_static_GrpcSnailJobRequest_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest.class, com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest.Builder.class);
|
||||
}
|
||||
|
||||
private int bitField0_;
|
||||
public static final int METADATA_FIELD_NUMBER = 2;
|
||||
private com.aizuda.snailjob.common.core.grpc.auto.Metadata metadata_;
|
||||
/**
|
||||
* <code>.Metadata metadata = 2;</code>
|
||||
* @return Whether the metadata field is set.
|
||||
*/
|
||||
@java.lang.Override
|
||||
public boolean hasMetadata() {
|
||||
return ((bitField0_ & 0x00000001) != 0);
|
||||
}
|
||||
/**
|
||||
* <code>.Metadata metadata = 2;</code>
|
||||
* @return The metadata.
|
||||
*/
|
||||
@java.lang.Override
|
||||
public com.aizuda.snailjob.common.core.grpc.auto.Metadata getMetadata() {
|
||||
return metadata_ == null ? com.aizuda.snailjob.common.core.grpc.auto.Metadata.getDefaultInstance() : metadata_;
|
||||
}
|
||||
/**
|
||||
* <code>.Metadata metadata = 2;</code>
|
||||
*/
|
||||
@java.lang.Override
|
||||
public com.aizuda.snailjob.common.core.grpc.auto.MetadataOrBuilder getMetadataOrBuilder() {
|
||||
return metadata_ == null ? com.aizuda.snailjob.common.core.grpc.auto.Metadata.getDefaultInstance() : metadata_;
|
||||
}
|
||||
|
||||
public static final int BODY_FIELD_NUMBER = 3;
|
||||
private com.google.protobuf.Any body_;
|
||||
/**
|
||||
* <code>.google.protobuf.Any body = 3;</code>
|
||||
* @return Whether the body field is set.
|
||||
*/
|
||||
@java.lang.Override
|
||||
public boolean hasBody() {
|
||||
return ((bitField0_ & 0x00000002) != 0);
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any body = 3;</code>
|
||||
* @return The body.
|
||||
*/
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Any getBody() {
|
||||
return body_ == null ? com.google.protobuf.Any.getDefaultInstance() : body_;
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any body = 3;</code>
|
||||
*/
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.AnyOrBuilder getBodyOrBuilder() {
|
||||
return body_ == null ? com.google.protobuf.Any.getDefaultInstance() : body_;
|
||||
}
|
||||
|
||||
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 (((bitField0_ & 0x00000001) != 0)) {
|
||||
output.writeMessage(2, getMetadata());
|
||||
}
|
||||
if (((bitField0_ & 0x00000002) != 0)) {
|
||||
output.writeMessage(3, getBody());
|
||||
}
|
||||
getUnknownFields().writeTo(output);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public int getSerializedSize() {
|
||||
int size = memoizedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (((bitField0_ & 0x00000001) != 0)) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeMessageSize(2, getMetadata());
|
||||
}
|
||||
if (((bitField0_ & 0x00000002) != 0)) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeMessageSize(3, getBody());
|
||||
}
|
||||
size += getUnknownFields().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.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest)) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest other = (com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest) obj;
|
||||
|
||||
if (hasMetadata() != other.hasMetadata()) return false;
|
||||
if (hasMetadata()) {
|
||||
if (!getMetadata()
|
||||
.equals(other.getMetadata())) return false;
|
||||
}
|
||||
if (hasBody() != other.hasBody()) return false;
|
||||
if (hasBody()) {
|
||||
if (!getBody()
|
||||
.equals(other.getBody())) return false;
|
||||
}
|
||||
if (!getUnknownFields().equals(other.getUnknownFields())) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public int hashCode() {
|
||||
if (memoizedHashCode != 0) {
|
||||
return memoizedHashCode;
|
||||
}
|
||||
int hash = 41;
|
||||
hash = (19 * hash) + getDescriptor().hashCode();
|
||||
if (hasMetadata()) {
|
||||
hash = (37 * hash) + METADATA_FIELD_NUMBER;
|
||||
hash = (53 * hash) + getMetadata().hashCode();
|
||||
}
|
||||
if (hasBody()) {
|
||||
hash = (37 * hash) + BODY_FIELD_NUMBER;
|
||||
hash = (53 * hash) + getBody().hashCode();
|
||||
}
|
||||
hash = (29 * hash) + getUnknownFields().hashCode();
|
||||
memoizedHashCode = hash;
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest parseFrom(
|
||||
java.nio.ByteBuffer data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest parseFrom(
|
||||
java.nio.ByteBuffer data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest parseFrom(
|
||||
com.google.protobuf.ByteString data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest parseFrom(
|
||||
com.google.protobuf.ByteString data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest parseFrom(byte[] data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest parseFrom(
|
||||
byte[] data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest parseFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input);
|
||||
}
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest 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.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest parseDelimitedFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseDelimitedWithIOException(PARSER, input);
|
||||
}
|
||||
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest 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.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest parseFrom(
|
||||
com.google.protobuf.CodedInputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input);
|
||||
}
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest 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.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest 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 GrpcSnailJobRequest}
|
||||
*/
|
||||
public static final class Builder extends
|
||||
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
|
||||
// @@protoc_insertion_point(builder_implements:GrpcSnailJobRequest)
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequestOrBuilder {
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return com.aizuda.snailjob.common.core.grpc.auto.SnailJobGrpcService.internal_static_GrpcSnailJobRequest_descriptor;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return com.aizuda.snailjob.common.core.grpc.auto.SnailJobGrpcService.internal_static_GrpcSnailJobRequest_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest.class, com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest.Builder.class);
|
||||
}
|
||||
|
||||
// Construct using com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest.newBuilder()
|
||||
private Builder() {
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
|
||||
private Builder(
|
||||
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
|
||||
super(parent);
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
private void maybeForceBuilderInitialization() {
|
||||
if (com.google.protobuf.GeneratedMessageV3
|
||||
.alwaysUseFieldBuilders) {
|
||||
getMetadataFieldBuilder();
|
||||
getBodyFieldBuilder();
|
||||
}
|
||||
}
|
||||
@java.lang.Override
|
||||
public Builder clear() {
|
||||
super.clear();
|
||||
bitField0_ = 0;
|
||||
metadata_ = null;
|
||||
if (metadataBuilder_ != null) {
|
||||
metadataBuilder_.dispose();
|
||||
metadataBuilder_ = null;
|
||||
}
|
||||
body_ = null;
|
||||
if (bodyBuilder_ != null) {
|
||||
bodyBuilder_.dispose();
|
||||
bodyBuilder_ = null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptorForType() {
|
||||
return com.aizuda.snailjob.common.core.grpc.auto.SnailJobGrpcService.internal_static_GrpcSnailJobRequest_descriptor;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest getDefaultInstanceForType() {
|
||||
return com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest.getDefaultInstance();
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest build() {
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest result = buildPartial();
|
||||
if (!result.isInitialized()) {
|
||||
throw newUninitializedMessageException(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest buildPartial() {
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest result = new com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest(this);
|
||||
if (bitField0_ != 0) { buildPartial0(result); }
|
||||
onBuilt();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void buildPartial0(com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest result) {
|
||||
int from_bitField0_ = bitField0_;
|
||||
int to_bitField0_ = 0;
|
||||
if (((from_bitField0_ & 0x00000001) != 0)) {
|
||||
result.metadata_ = metadataBuilder_ == null
|
||||
? metadata_
|
||||
: metadataBuilder_.build();
|
||||
to_bitField0_ |= 0x00000001;
|
||||
}
|
||||
if (((from_bitField0_ & 0x00000002) != 0)) {
|
||||
result.body_ = bodyBuilder_ == null
|
||||
? body_
|
||||
: bodyBuilder_.build();
|
||||
to_bitField0_ |= 0x00000002;
|
||||
}
|
||||
result.bitField0_ |= to_bitField0_;
|
||||
}
|
||||
|
||||
@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.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest) {
|
||||
return mergeFrom((com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest)other);
|
||||
} else {
|
||||
super.mergeFrom(other);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Builder mergeFrom(com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest other) {
|
||||
if (other == com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest.getDefaultInstance()) return this;
|
||||
if (other.hasMetadata()) {
|
||||
mergeMetadata(other.getMetadata());
|
||||
}
|
||||
if (other.hasBody()) {
|
||||
mergeBody(other.getBody());
|
||||
}
|
||||
this.mergeUnknownFields(other.getUnknownFields());
|
||||
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 {
|
||||
if (extensionRegistry == null) {
|
||||
throw new java.lang.NullPointerException();
|
||||
}
|
||||
try {
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
int tag = input.readTag();
|
||||
switch (tag) {
|
||||
case 0:
|
||||
done = true;
|
||||
break;
|
||||
case 18: {
|
||||
input.readMessage(
|
||||
getMetadataFieldBuilder().getBuilder(),
|
||||
extensionRegistry);
|
||||
bitField0_ |= 0x00000001;
|
||||
break;
|
||||
} // case 18
|
||||
case 26: {
|
||||
input.readMessage(
|
||||
getBodyFieldBuilder().getBuilder(),
|
||||
extensionRegistry);
|
||||
bitField0_ |= 0x00000002;
|
||||
break;
|
||||
} // case 26
|
||||
default: {
|
||||
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
|
||||
done = true; // was an endgroup tag
|
||||
}
|
||||
break;
|
||||
} // default:
|
||||
} // switch (tag)
|
||||
} // while (!done)
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
throw e.unwrapIOException();
|
||||
} finally {
|
||||
onChanged();
|
||||
} // finally
|
||||
return this;
|
||||
}
|
||||
private int bitField0_;
|
||||
|
||||
private com.aizuda.snailjob.common.core.grpc.auto.Metadata metadata_;
|
||||
private com.google.protobuf.SingleFieldBuilderV3<
|
||||
com.aizuda.snailjob.common.core.grpc.auto.Metadata, com.aizuda.snailjob.common.core.grpc.auto.Metadata.Builder, com.aizuda.snailjob.common.core.grpc.auto.MetadataOrBuilder> metadataBuilder_;
|
||||
/**
|
||||
* <code>.Metadata metadata = 2;</code>
|
||||
* @return Whether the metadata field is set.
|
||||
*/
|
||||
public boolean hasMetadata() {
|
||||
return ((bitField0_ & 0x00000001) != 0);
|
||||
}
|
||||
/**
|
||||
* <code>.Metadata metadata = 2;</code>
|
||||
* @return The metadata.
|
||||
*/
|
||||
public com.aizuda.snailjob.common.core.grpc.auto.Metadata getMetadata() {
|
||||
if (metadataBuilder_ == null) {
|
||||
return metadata_ == null ? com.aizuda.snailjob.common.core.grpc.auto.Metadata.getDefaultInstance() : metadata_;
|
||||
} else {
|
||||
return metadataBuilder_.getMessage();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>.Metadata metadata = 2;</code>
|
||||
*/
|
||||
public Builder setMetadata(com.aizuda.snailjob.common.core.grpc.auto.Metadata value) {
|
||||
if (metadataBuilder_ == null) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
metadata_ = value;
|
||||
} else {
|
||||
metadataBuilder_.setMessage(value);
|
||||
}
|
||||
bitField0_ |= 0x00000001;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.Metadata metadata = 2;</code>
|
||||
*/
|
||||
public Builder setMetadata(
|
||||
com.aizuda.snailjob.common.core.grpc.auto.Metadata.Builder builderForValue) {
|
||||
if (metadataBuilder_ == null) {
|
||||
metadata_ = builderForValue.build();
|
||||
} else {
|
||||
metadataBuilder_.setMessage(builderForValue.build());
|
||||
}
|
||||
bitField0_ |= 0x00000001;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.Metadata metadata = 2;</code>
|
||||
*/
|
||||
public Builder mergeMetadata(com.aizuda.snailjob.common.core.grpc.auto.Metadata value) {
|
||||
if (metadataBuilder_ == null) {
|
||||
if (((bitField0_ & 0x00000001) != 0) &&
|
||||
metadata_ != null &&
|
||||
metadata_ != com.aizuda.snailjob.common.core.grpc.auto.Metadata.getDefaultInstance()) {
|
||||
getMetadataBuilder().mergeFrom(value);
|
||||
} else {
|
||||
metadata_ = value;
|
||||
}
|
||||
} else {
|
||||
metadataBuilder_.mergeFrom(value);
|
||||
}
|
||||
if (metadata_ != null) {
|
||||
bitField0_ |= 0x00000001;
|
||||
onChanged();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.Metadata metadata = 2;</code>
|
||||
*/
|
||||
public Builder clearMetadata() {
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
metadata_ = null;
|
||||
if (metadataBuilder_ != null) {
|
||||
metadataBuilder_.dispose();
|
||||
metadataBuilder_ = null;
|
||||
}
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.Metadata metadata = 2;</code>
|
||||
*/
|
||||
public com.aizuda.snailjob.common.core.grpc.auto.Metadata.Builder getMetadataBuilder() {
|
||||
bitField0_ |= 0x00000001;
|
||||
onChanged();
|
||||
return getMetadataFieldBuilder().getBuilder();
|
||||
}
|
||||
/**
|
||||
* <code>.Metadata metadata = 2;</code>
|
||||
*/
|
||||
public com.aizuda.snailjob.common.core.grpc.auto.MetadataOrBuilder getMetadataOrBuilder() {
|
||||
if (metadataBuilder_ != null) {
|
||||
return metadataBuilder_.getMessageOrBuilder();
|
||||
} else {
|
||||
return metadata_ == null ?
|
||||
com.aizuda.snailjob.common.core.grpc.auto.Metadata.getDefaultInstance() : metadata_;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>.Metadata metadata = 2;</code>
|
||||
*/
|
||||
private com.google.protobuf.SingleFieldBuilderV3<
|
||||
com.aizuda.snailjob.common.core.grpc.auto.Metadata, com.aizuda.snailjob.common.core.grpc.auto.Metadata.Builder, com.aizuda.snailjob.common.core.grpc.auto.MetadataOrBuilder>
|
||||
getMetadataFieldBuilder() {
|
||||
if (metadataBuilder_ == null) {
|
||||
metadataBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
|
||||
com.aizuda.snailjob.common.core.grpc.auto.Metadata, com.aizuda.snailjob.common.core.grpc.auto.Metadata.Builder, com.aizuda.snailjob.common.core.grpc.auto.MetadataOrBuilder>(
|
||||
getMetadata(),
|
||||
getParentForChildren(),
|
||||
isClean());
|
||||
metadata_ = null;
|
||||
}
|
||||
return metadataBuilder_;
|
||||
}
|
||||
|
||||
private com.google.protobuf.Any body_;
|
||||
private com.google.protobuf.SingleFieldBuilderV3<
|
||||
com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> bodyBuilder_;
|
||||
/**
|
||||
* <code>.google.protobuf.Any body = 3;</code>
|
||||
* @return Whether the body field is set.
|
||||
*/
|
||||
public boolean hasBody() {
|
||||
return ((bitField0_ & 0x00000002) != 0);
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any body = 3;</code>
|
||||
* @return The body.
|
||||
*/
|
||||
public com.google.protobuf.Any getBody() {
|
||||
if (bodyBuilder_ == null) {
|
||||
return body_ == null ? com.google.protobuf.Any.getDefaultInstance() : body_;
|
||||
} else {
|
||||
return bodyBuilder_.getMessage();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any body = 3;</code>
|
||||
*/
|
||||
public Builder setBody(com.google.protobuf.Any value) {
|
||||
if (bodyBuilder_ == null) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
body_ = value;
|
||||
} else {
|
||||
bodyBuilder_.setMessage(value);
|
||||
}
|
||||
bitField0_ |= 0x00000002;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any body = 3;</code>
|
||||
*/
|
||||
public Builder setBody(
|
||||
com.google.protobuf.Any.Builder builderForValue) {
|
||||
if (bodyBuilder_ == null) {
|
||||
body_ = builderForValue.build();
|
||||
} else {
|
||||
bodyBuilder_.setMessage(builderForValue.build());
|
||||
}
|
||||
bitField0_ |= 0x00000002;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any body = 3;</code>
|
||||
*/
|
||||
public Builder mergeBody(com.google.protobuf.Any value) {
|
||||
if (bodyBuilder_ == null) {
|
||||
if (((bitField0_ & 0x00000002) != 0) &&
|
||||
body_ != null &&
|
||||
body_ != com.google.protobuf.Any.getDefaultInstance()) {
|
||||
getBodyBuilder().mergeFrom(value);
|
||||
} else {
|
||||
body_ = value;
|
||||
}
|
||||
} else {
|
||||
bodyBuilder_.mergeFrom(value);
|
||||
}
|
||||
if (body_ != null) {
|
||||
bitField0_ |= 0x00000002;
|
||||
onChanged();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any body = 3;</code>
|
||||
*/
|
||||
public Builder clearBody() {
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
body_ = null;
|
||||
if (bodyBuilder_ != null) {
|
||||
bodyBuilder_.dispose();
|
||||
bodyBuilder_ = null;
|
||||
}
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any body = 3;</code>
|
||||
*/
|
||||
public com.google.protobuf.Any.Builder getBodyBuilder() {
|
||||
bitField0_ |= 0x00000002;
|
||||
onChanged();
|
||||
return getBodyFieldBuilder().getBuilder();
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any body = 3;</code>
|
||||
*/
|
||||
public com.google.protobuf.AnyOrBuilder getBodyOrBuilder() {
|
||||
if (bodyBuilder_ != null) {
|
||||
return bodyBuilder_.getMessageOrBuilder();
|
||||
} else {
|
||||
return body_ == null ?
|
||||
com.google.protobuf.Any.getDefaultInstance() : body_;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>.google.protobuf.Any body = 3;</code>
|
||||
*/
|
||||
private com.google.protobuf.SingleFieldBuilderV3<
|
||||
com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>
|
||||
getBodyFieldBuilder() {
|
||||
if (bodyBuilder_ == null) {
|
||||
bodyBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
|
||||
com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>(
|
||||
getBody(),
|
||||
getParentForChildren(),
|
||||
isClean());
|
||||
body_ = null;
|
||||
}
|
||||
return bodyBuilder_;
|
||||
}
|
||||
@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:GrpcSnailJobRequest)
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(class_scope:GrpcSnailJobRequest)
|
||||
private static final com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest DEFAULT_INSTANCE;
|
||||
static {
|
||||
DEFAULT_INSTANCE = new com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest();
|
||||
}
|
||||
|
||||
public static com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest getDefaultInstance() {
|
||||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
private static final com.google.protobuf.Parser<GrpcSnailJobRequest>
|
||||
PARSER = new com.google.protobuf.AbstractParser<GrpcSnailJobRequest>() {
|
||||
@java.lang.Override
|
||||
public GrpcSnailJobRequest parsePartialFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
Builder builder = newBuilder();
|
||||
try {
|
||||
builder.mergeFrom(input, extensionRegistry);
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
throw e.setUnfinishedMessage(builder.buildPartial());
|
||||
} catch (com.google.protobuf.UninitializedMessageException e) {
|
||||
throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial());
|
||||
} catch (java.io.IOException e) {
|
||||
throw new com.google.protobuf.InvalidProtocolBufferException(e)
|
||||
.setUnfinishedMessage(builder.buildPartial());
|
||||
}
|
||||
return builder.buildPartial();
|
||||
}
|
||||
};
|
||||
|
||||
public static com.google.protobuf.Parser<GrpcSnailJobRequest> parser() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Parser<GrpcSnailJobRequest> getParserForType() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest getDefaultInstanceForType() {
|
||||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: snail_job_grpc_service.proto
|
||||
|
||||
package com.aizuda.snailjob.common.core.grpc.auto;
|
||||
|
||||
public interface GrpcSnailJobRequestOrBuilder extends
|
||||
// @@protoc_insertion_point(interface_extends:GrpcSnailJobRequest)
|
||||
com.google.protobuf.MessageOrBuilder {
|
||||
|
||||
/**
|
||||
* <code>.Metadata metadata = 2;</code>
|
||||
* @return Whether the metadata field is set.
|
||||
*/
|
||||
boolean hasMetadata();
|
||||
/**
|
||||
* <code>.Metadata metadata = 2;</code>
|
||||
* @return The metadata.
|
||||
*/
|
||||
com.aizuda.snailjob.common.core.grpc.auto.Metadata getMetadata();
|
||||
/**
|
||||
* <code>.Metadata metadata = 2;</code>
|
||||
*/
|
||||
com.aizuda.snailjob.common.core.grpc.auto.MetadataOrBuilder getMetadataOrBuilder();
|
||||
|
||||
/**
|
||||
* <code>.google.protobuf.Any body = 3;</code>
|
||||
* @return Whether the body field is set.
|
||||
*/
|
||||
boolean hasBody();
|
||||
/**
|
||||
* <code>.google.protobuf.Any body = 3;</code>
|
||||
* @return The body.
|
||||
*/
|
||||
com.google.protobuf.Any getBody();
|
||||
/**
|
||||
* <code>.google.protobuf.Any body = 3;</code>
|
||||
*/
|
||||
com.google.protobuf.AnyOrBuilder getBodyOrBuilder();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,79 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: snail_job_grpc_service.proto
|
||||
|
||||
package com.aizuda.snailjob.common.core.grpc.auto;
|
||||
|
||||
public interface MetadataOrBuilder extends
|
||||
// @@protoc_insertion_point(interface_extends:Metadata)
|
||||
com.google.protobuf.MessageOrBuilder {
|
||||
|
||||
/**
|
||||
* <code>string type = 3;</code>
|
||||
* @return The type.
|
||||
*/
|
||||
java.lang.String getType();
|
||||
/**
|
||||
* <code>string type = 3;</code>
|
||||
* @return The bytes for type.
|
||||
*/
|
||||
com.google.protobuf.ByteString
|
||||
getTypeBytes();
|
||||
|
||||
/**
|
||||
* <code>map<string, string> headers = 7;</code>
|
||||
*/
|
||||
int getHeadersCount();
|
||||
/**
|
||||
* <code>map<string, string> headers = 7;</code>
|
||||
*/
|
||||
boolean containsHeaders(
|
||||
java.lang.String key);
|
||||
/**
|
||||
* Use {@link #getHeadersMap()} instead.
|
||||
*/
|
||||
@java.lang.Deprecated
|
||||
java.util.Map<java.lang.String, java.lang.String>
|
||||
getHeaders();
|
||||
/**
|
||||
* <code>map<string, string> headers = 7;</code>
|
||||
*/
|
||||
java.util.Map<java.lang.String, java.lang.String>
|
||||
getHeadersMap();
|
||||
/**
|
||||
* <code>map<string, string> headers = 7;</code>
|
||||
*/
|
||||
/* nullable */
|
||||
java.lang.String getHeadersOrDefault(
|
||||
java.lang.String key,
|
||||
/* nullable */
|
||||
java.lang.String defaultValue);
|
||||
/**
|
||||
* <code>map<string, string> headers = 7;</code>
|
||||
*/
|
||||
java.lang.String getHeadersOrThrow(
|
||||
java.lang.String key);
|
||||
|
||||
/**
|
||||
* <code>string clientIp = 8;</code>
|
||||
* @return The clientIp.
|
||||
*/
|
||||
java.lang.String getClientIp();
|
||||
/**
|
||||
* <code>string clientIp = 8;</code>
|
||||
* @return The bytes for clientIp.
|
||||
*/
|
||||
com.google.protobuf.ByteString
|
||||
getClientIpBytes();
|
||||
|
||||
/**
|
||||
* <code>string uri = 9;</code>
|
||||
* @return The uri.
|
||||
*/
|
||||
java.lang.String getUri();
|
||||
/**
|
||||
* <code>string uri = 9;</code>
|
||||
* @return The bytes for uri.
|
||||
*/
|
||||
com.google.protobuf.ByteString
|
||||
getUriBytes();
|
||||
}
|
||||
@ -0,0 +1,293 @@
|
||||
package com.aizuda.snailjob.common.core.grpc.auto;
|
||||
|
||||
import static io.grpc.MethodDescriptor.generateFullMethodName;
|
||||
|
||||
/**
|
||||
*/
|
||||
@javax.annotation.Generated(
|
||||
value = "by gRPC proto compiler (version 1.63.0)",
|
||||
comments = "Source: snail_job_grpc_service.proto")
|
||||
@io.grpc.stub.annotations.GrpcGenerated
|
||||
public final class RequestGrpc {
|
||||
|
||||
private RequestGrpc() {}
|
||||
|
||||
public static final java.lang.String SERVICE_NAME = "Request";
|
||||
|
||||
// Static method descriptors that strictly reflect the proto.
|
||||
private static volatile io.grpc.MethodDescriptor<com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest,
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcResult> getRequestMethod;
|
||||
|
||||
@io.grpc.stub.annotations.RpcMethod(
|
||||
fullMethodName = SERVICE_NAME + '/' + "request",
|
||||
requestType = com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest.class,
|
||||
responseType = com.aizuda.snailjob.common.core.grpc.auto.GrpcResult.class,
|
||||
methodType = io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
public static io.grpc.MethodDescriptor<com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest,
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcResult> getRequestMethod() {
|
||||
io.grpc.MethodDescriptor<com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest, com.aizuda.snailjob.common.core.grpc.auto.GrpcResult> getRequestMethod;
|
||||
if ((getRequestMethod = RequestGrpc.getRequestMethod) == null) {
|
||||
synchronized (RequestGrpc.class) {
|
||||
if ((getRequestMethod = RequestGrpc.getRequestMethod) == null) {
|
||||
RequestGrpc.getRequestMethod = getRequestMethod =
|
||||
io.grpc.MethodDescriptor.<com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest, com.aizuda.snailjob.common.core.grpc.auto.GrpcResult>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "request"))
|
||||
.setSampledToLocalTracing(true)
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcResult.getDefaultInstance()))
|
||||
.setSchemaDescriptor(new RequestMethodDescriptorSupplier("request"))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
return getRequestMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new async stub that supports all call types for the service
|
||||
*/
|
||||
public static RequestStub newStub(io.grpc.Channel channel) {
|
||||
io.grpc.stub.AbstractStub.StubFactory<RequestStub> factory =
|
||||
new io.grpc.stub.AbstractStub.StubFactory<RequestStub>() {
|
||||
@java.lang.Override
|
||||
public RequestStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
|
||||
return new RequestStub(channel, callOptions);
|
||||
}
|
||||
};
|
||||
return RequestStub.newStub(factory, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new blocking-style stub that supports unary and streaming output calls on the service
|
||||
*/
|
||||
public static RequestBlockingStub newBlockingStub(
|
||||
io.grpc.Channel channel) {
|
||||
io.grpc.stub.AbstractStub.StubFactory<RequestBlockingStub> factory =
|
||||
new io.grpc.stub.AbstractStub.StubFactory<RequestBlockingStub>() {
|
||||
@java.lang.Override
|
||||
public RequestBlockingStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
|
||||
return new RequestBlockingStub(channel, callOptions);
|
||||
}
|
||||
};
|
||||
return RequestBlockingStub.newStub(factory, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ListenableFuture-style stub that supports unary calls on the service
|
||||
*/
|
||||
public static RequestFutureStub newFutureStub(
|
||||
io.grpc.Channel channel) {
|
||||
io.grpc.stub.AbstractStub.StubFactory<RequestFutureStub> factory =
|
||||
new io.grpc.stub.AbstractStub.StubFactory<RequestFutureStub>() {
|
||||
@java.lang.Override
|
||||
public RequestFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
|
||||
return new RequestFutureStub(channel, callOptions);
|
||||
}
|
||||
};
|
||||
return RequestFutureStub.newStub(factory, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public interface AsyncService {
|
||||
|
||||
/**
|
||||
*/
|
||||
default void request(com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest request,
|
||||
io.grpc.stub.StreamObserver<com.aizuda.snailjob.common.core.grpc.auto.GrpcResult> responseObserver) {
|
||||
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getRequestMethod(), responseObserver);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class for the server implementation of the service Request.
|
||||
*/
|
||||
public static abstract class RequestImplBase
|
||||
implements io.grpc.BindableService, AsyncService {
|
||||
|
||||
@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
|
||||
return RequestGrpc.bindService(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A stub to allow clients to do asynchronous rpc calls to service Request.
|
||||
*/
|
||||
public static final class RequestStub
|
||||
extends io.grpc.stub.AbstractAsyncStub<RequestStub> {
|
||||
private RequestStub(
|
||||
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
|
||||
super(channel, callOptions);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected RequestStub build(
|
||||
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
|
||||
return new RequestStub(channel, callOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void request(com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest request,
|
||||
io.grpc.stub.StreamObserver<com.aizuda.snailjob.common.core.grpc.auto.GrpcResult> responseObserver) {
|
||||
io.grpc.stub.ClientCalls.asyncUnaryCall(
|
||||
getChannel().newCall(getRequestMethod(), getCallOptions()), request, responseObserver);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A stub to allow clients to do synchronous rpc calls to service Request.
|
||||
*/
|
||||
public static final class RequestBlockingStub
|
||||
extends io.grpc.stub.AbstractBlockingStub<RequestBlockingStub> {
|
||||
private RequestBlockingStub(
|
||||
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
|
||||
super(channel, callOptions);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected RequestBlockingStub build(
|
||||
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
|
||||
return new RequestBlockingStub(channel, callOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.aizuda.snailjob.common.core.grpc.auto.GrpcResult request(com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest request) {
|
||||
return io.grpc.stub.ClientCalls.blockingUnaryCall(
|
||||
getChannel(), getRequestMethod(), getCallOptions(), request);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A stub to allow clients to do ListenableFuture-style rpc calls to service Request.
|
||||
*/
|
||||
public static final class RequestFutureStub
|
||||
extends io.grpc.stub.AbstractFutureStub<RequestFutureStub> {
|
||||
private RequestFutureStub(
|
||||
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
|
||||
super(channel, callOptions);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected RequestFutureStub build(
|
||||
io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
|
||||
return new RequestFutureStub(channel, callOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<com.aizuda.snailjob.common.core.grpc.auto.GrpcResult> request(
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest request) {
|
||||
return io.grpc.stub.ClientCalls.futureUnaryCall(
|
||||
getChannel().newCall(getRequestMethod(), getCallOptions()), request);
|
||||
}
|
||||
}
|
||||
|
||||
private static final int METHODID_REQUEST = 0;
|
||||
|
||||
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 AsyncService serviceImpl;
|
||||
private final int methodId;
|
||||
|
||||
MethodHandlers(AsyncService 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_REQUEST:
|
||||
serviceImpl.request((com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest) request,
|
||||
(io.grpc.stub.StreamObserver<com.aizuda.snailjob.common.core.grpc.auto.GrpcResult>) 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final io.grpc.ServerServiceDefinition bindService(AsyncService service) {
|
||||
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
|
||||
.addMethod(
|
||||
getRequestMethod(),
|
||||
io.grpc.stub.ServerCalls.asyncUnaryCall(
|
||||
new MethodHandlers<
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest,
|
||||
com.aizuda.snailjob.common.core.grpc.auto.GrpcResult>(
|
||||
service, METHODID_REQUEST)))
|
||||
.build();
|
||||
}
|
||||
|
||||
private static abstract class RequestBaseDescriptorSupplier
|
||||
implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier {
|
||||
RequestBaseDescriptorSupplier() {}
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
|
||||
return com.aizuda.snailjob.common.core.grpc.auto.SnailJobGrpcService.getDescriptor();
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() {
|
||||
return getFileDescriptor().findServiceByName("Request");
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RequestFileDescriptorSupplier
|
||||
extends RequestBaseDescriptorSupplier {
|
||||
RequestFileDescriptorSupplier() {}
|
||||
}
|
||||
|
||||
private static final class RequestMethodDescriptorSupplier
|
||||
extends RequestBaseDescriptorSupplier
|
||||
implements io.grpc.protobuf.ProtoMethodDescriptorSupplier {
|
||||
private final java.lang.String methodName;
|
||||
|
||||
RequestMethodDescriptorSupplier(java.lang.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 (RequestGrpc.class) {
|
||||
result = serviceDescriptor;
|
||||
if (result == null) {
|
||||
serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME)
|
||||
.setSchemaDescriptor(new RequestFileDescriptorSupplier())
|
||||
.addMethod(getRequestMethod())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,96 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: snail_job_grpc_service.proto
|
||||
|
||||
package com.aizuda.snailjob.common.core.grpc.auto;
|
||||
|
||||
public final class SnailJobGrpcService {
|
||||
private SnailJobGrpcService() {}
|
||||
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_Metadata_descriptor;
|
||||
static final
|
||||
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
internal_static_Metadata_fieldAccessorTable;
|
||||
static final com.google.protobuf.Descriptors.Descriptor
|
||||
internal_static_Metadata_HeadersEntry_descriptor;
|
||||
static final
|
||||
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
internal_static_Metadata_HeadersEntry_fieldAccessorTable;
|
||||
static final com.google.protobuf.Descriptors.Descriptor
|
||||
internal_static_GrpcSnailJobRequest_descriptor;
|
||||
static final
|
||||
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
internal_static_GrpcSnailJobRequest_fieldAccessorTable;
|
||||
static final com.google.protobuf.Descriptors.Descriptor
|
||||
internal_static_GrpcResult_descriptor;
|
||||
static final
|
||||
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
internal_static_GrpcResult_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\034snail_job_grpc_service.proto\032\031google/p" +
|
||||
"rotobuf/any.proto\032\037google/protobuf/times" +
|
||||
"tamp.proto\"\220\001\n\010Metadata\022\014\n\004type\030\003 \001(\t\022\'\n" +
|
||||
"\007headers\030\007 \003(\0132\026.Metadata.HeadersEntry\022\020" +
|
||||
"\n\010clientIp\030\010 \001(\t\022\013\n\003uri\030\t \001(\t\032.\n\014Headers" +
|
||||
"Entry\022\013\n\003key\030\001 \001(\t\022\r\n\005value\030\002 \001(\t:\0028\001\"V\n" +
|
||||
"\023GrpcSnailJobRequest\022\033\n\010metadata\030\002 \001(\0132\t" +
|
||||
".Metadata\022\"\n\004body\030\003 \001(\0132\024.google.protobu" +
|
||||
"f.Any\"Q\n\nGrpcResult\022\016\n\006status\030\001 \001(\005\022\017\n\007m" +
|
||||
"essage\030\002 \001(\t\022\"\n\004data\030\003 \001(\0132\024.google.prot" +
|
||||
"obuf.Any29\n\007Request\022.\n\007request\022\024.GrpcSna" +
|
||||
"ilJobRequest\032\013.GrpcResult\"\000B-\n)com.aizud" +
|
||||
"a.snailjob.common.core.grpc.autoP\001b\006prot" +
|
||||
"o3"
|
||||
};
|
||||
descriptor = com.google.protobuf.Descriptors.FileDescriptor
|
||||
.internalBuildGeneratedFileFrom(descriptorData,
|
||||
new com.google.protobuf.Descriptors.FileDescriptor[] {
|
||||
com.google.protobuf.AnyProto.getDescriptor(),
|
||||
com.google.protobuf.TimestampProto.getDescriptor(),
|
||||
});
|
||||
internal_static_Metadata_descriptor =
|
||||
getDescriptor().getMessageTypes().get(0);
|
||||
internal_static_Metadata_fieldAccessorTable = new
|
||||
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
|
||||
internal_static_Metadata_descriptor,
|
||||
new java.lang.String[] { "Type", "Headers", "ClientIp", "Uri", });
|
||||
internal_static_Metadata_HeadersEntry_descriptor =
|
||||
internal_static_Metadata_descriptor.getNestedTypes().get(0);
|
||||
internal_static_Metadata_HeadersEntry_fieldAccessorTable = new
|
||||
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
|
||||
internal_static_Metadata_HeadersEntry_descriptor,
|
||||
new java.lang.String[] { "Key", "Value", });
|
||||
internal_static_GrpcSnailJobRequest_descriptor =
|
||||
getDescriptor().getMessageTypes().get(1);
|
||||
internal_static_GrpcSnailJobRequest_fieldAccessorTable = new
|
||||
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
|
||||
internal_static_GrpcSnailJobRequest_descriptor,
|
||||
new java.lang.String[] { "Metadata", "Body", });
|
||||
internal_static_GrpcResult_descriptor =
|
||||
getDescriptor().getMessageTypes().get(2);
|
||||
internal_static_GrpcResult_fieldAccessorTable = new
|
||||
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
|
||||
internal_static_GrpcResult_descriptor,
|
||||
new java.lang.String[] { "Status", "Message", "Data", });
|
||||
com.google.protobuf.AnyProto.getDescriptor();
|
||||
com.google.protobuf.TimestampProto.getDescriptor();
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(outer_class_scope)
|
||||
}
|
||||
@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@ -51,6 +52,13 @@ public class JsonUtil {
|
||||
return JsonMapper.toJavaObject(jsonString, clazz);
|
||||
}
|
||||
|
||||
|
||||
public static <T> T parseObject(InputStream inputStream, Class<T> clazz) {
|
||||
return JsonMapper.toJavaObject(inputStream, clazz);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 将JSON 数组字符串转Java 对象集合
|
||||
*
|
||||
@ -265,6 +273,14 @@ public class JsonUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T toJavaObject(InputStream inputStream, Class<T> clazz) {
|
||||
try {
|
||||
return objectMapper.readValue(inputStream, clazz);
|
||||
} catch (IOException e) {
|
||||
throw new SnailJobCommonException("Json转对象失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Json 字符串转JAVA 对象
|
||||
*
|
||||
|
||||
@ -0,0 +1,53 @@
|
||||
|
||||
/*
|
||||
* Copyright 1999-2020 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
import "google/protobuf/any.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_package = "com.aizuda.snailjob.common.core.grpc.auto";
|
||||
|
||||
message Metadata {
|
||||
string type = 3;
|
||||
map<string, string> headers = 7;
|
||||
string clientIp = 8;
|
||||
string uri = 9;
|
||||
}
|
||||
|
||||
message GrpcSnailJobRequest {
|
||||
Metadata metadata = 2;
|
||||
google.protobuf.Any body = 3;
|
||||
}
|
||||
|
||||
message GrpcResult {
|
||||
int32 status = 1;
|
||||
string message = 2;
|
||||
google.protobuf.Any data = 3;
|
||||
}
|
||||
|
||||
service Request {
|
||||
rpc request (GrpcSnailJobRequest) returns (GrpcResult) {
|
||||
}
|
||||
}
|
||||
|
||||
//service BiRequestStream {
|
||||
// // Sends a biStreamRequest
|
||||
// rpc requestBiStream (stream Payload) returns (stream Payload) {
|
||||
// }
|
||||
//}
|
||||
@ -92,6 +92,20 @@
|
||||
<groupId>com.aizuda</groupId>
|
||||
<artifactId>snail-job-common-log</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.devh</groupId>
|
||||
<artifactId>grpc-client-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-netty-shaded</artifactId>
|
||||
<version>1.63.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.devh</groupId>
|
||||
<artifactId>grpc-server-spring-boot-starter</artifactId>
|
||||
<version>3.1.0.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.scala-lang</groupId>
|
||||
<artifactId>scala-library</artifactId>
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
package com.aizuda.snailjob.server.common.dto;
|
||||
|
||||
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcResult;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* netty客户端请求模型
|
||||
*
|
||||
* @author: opensnail
|
||||
* @date : 2023-07-24 09:32
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class GrpcRequest {
|
||||
|
||||
private GrpcSnailJobRequest snailJobRequest;
|
||||
|
||||
private StreamObserver<GrpcResult> streamObserver;
|
||||
|
||||
private String uri;
|
||||
|
||||
}
|
||||
@ -0,0 +1,134 @@
|
||||
package com.aizuda.snailjob.server.common.rpc.client;
|
||||
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcResult;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.Metadata;
|
||||
import com.aizuda.snailjob.common.log.SnailJobLog;
|
||||
import com.aizuda.snailjob.server.common.triple.Pair;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.protobuf.Any;
|
||||
import com.google.protobuf.UnsafeByteOperations;
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
import io.grpc.MethodDescriptor;
|
||||
import io.grpc.protobuf.ProtoUtils;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.handler.codec.http.HttpHeaders;
|
||||
import io.netty.handler.codec.http.HttpMethod;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.net.ConnectException;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author opensnail
|
||||
* @date 2023-05-13
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@Slf4j
|
||||
public class GrpcChannel {
|
||||
private GrpcChannel() {
|
||||
}
|
||||
|
||||
private static ConcurrentHashMap<Pair<String, String>, ManagedChannel> CHANNEL_MAP = new ConcurrentHashMap<>(16);
|
||||
|
||||
public static void setChannel(String hostId, String ip, ManagedChannel channel) {
|
||||
CHANNEL_MAP.put(Pair.of(hostId, ip), channel);
|
||||
}
|
||||
|
||||
public static void removeChannel(ManagedChannel channel) {
|
||||
CHANNEL_MAP.forEach((key, value) -> {
|
||||
if (value.equals(channel)) {
|
||||
CHANNEL_MAP.remove(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送数据
|
||||
*
|
||||
* @param url url地址
|
||||
* @param body 请求的消息体
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public static ListenableFuture<GrpcResult> send(String hostId, String hostIp, Integer port, String url, String body, Map<String, String> headersMap) throws InterruptedException {
|
||||
|
||||
ManagedChannel channel = CHANNEL_MAP.get(Pair.of(hostId, hostIp));
|
||||
if (Objects.isNull(channel) || !channel.isShutdown() || !channel.isShutdown()) {
|
||||
channel = connect(hostId, hostIp, port);
|
||||
if (Objects.isNull(channel)) {
|
||||
SnailJobLog.LOCAL.error("send message but channel is null url:[{}] method:[{}] body:[{}] ", url, body);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Metadata metadata = Metadata
|
||||
.newBuilder()
|
||||
.setUri(url)
|
||||
.putAllHeaders(headersMap)
|
||||
.build();
|
||||
Any build = Any.newBuilder().setValue(UnsafeByteOperations.unsafeWrap(body.getBytes()))
|
||||
.build();
|
||||
GrpcSnailJobRequest snailJobRequest = GrpcSnailJobRequest
|
||||
.newBuilder()
|
||||
.setMetadata(metadata)
|
||||
.setBody(build)
|
||||
.build();
|
||||
|
||||
MethodDescriptor<GrpcSnailJobRequest, GrpcResult> methodDescriptor =
|
||||
MethodDescriptor.<GrpcSnailJobRequest, GrpcResult>newBuilder()
|
||||
.setType(MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(MethodDescriptor.generateFullMethodName("UnaryRequest", "unaryRequest"))
|
||||
.setRequestMarshaller(ProtoUtils.marshaller(GrpcSnailJobRequest.getDefaultInstance()))
|
||||
.setResponseMarshaller(ProtoUtils.marshaller(GrpcResult.getDefaultInstance()))
|
||||
.build();
|
||||
|
||||
// 创建动态代理调用方法
|
||||
return io.grpc.stub.ClientCalls.futureUnaryCall(
|
||||
channel.newCall(methodDescriptor, io.grpc.CallOptions.DEFAULT),
|
||||
snailJobRequest);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接客户端
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static ManagedChannel connect(String hostId, String ip, Integer port) {
|
||||
|
||||
try {
|
||||
ManagedChannel channel = ManagedChannelBuilder.forAddress(ip, port)
|
||||
.usePlaintext()
|
||||
.build();
|
||||
GrpcChannel.setChannel(hostId, ip, channel);
|
||||
|
||||
return channel;
|
||||
} catch (Exception e) {
|
||||
exceptionHandler(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接失败处理
|
||||
*
|
||||
* @param cause
|
||||
*/
|
||||
private static void exceptionHandler(Throwable cause) {
|
||||
if (cause instanceof ConnectException) {
|
||||
SnailJobLog.LOCAL.error("connect error:{}", cause.getMessage());
|
||||
} else if (cause instanceof ClosedChannelException) {
|
||||
SnailJobLog.LOCAL.error("connect error:{}", "client has destroy");
|
||||
} else {
|
||||
SnailJobLog.LOCAL.error("connect error:", cause);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,263 @@
|
||||
package com.aizuda.snailjob.server.common.rpc.client;
|
||||
|
||||
import cn.hutool.core.date.StopWatch;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.aizuda.snailjob.common.core.constant.SystemConstants;
|
||||
import com.aizuda.snailjob.common.core.context.SnailSpringContext;
|
||||
import com.aizuda.snailjob.common.core.exception.SnailJobRemotingTimeOutException;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcResult;
|
||||
import com.aizuda.snailjob.common.core.model.Result;
|
||||
import com.aizuda.snailjob.common.core.model.SnailJobRequest;
|
||||
import com.aizuda.snailjob.common.core.rpc.RpcContext;
|
||||
import com.aizuda.snailjob.common.core.rpc.SnailJobFuture;
|
||||
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
||||
import com.aizuda.snailjob.common.core.util.NetUtil;
|
||||
import com.aizuda.snailjob.common.log.SnailJobLog;
|
||||
import com.aizuda.snailjob.server.common.cache.CacheRegisterTable;
|
||||
import com.aizuda.snailjob.server.common.cache.CacheToken;
|
||||
import com.aizuda.snailjob.server.common.dto.RegisterNodeInfo;
|
||||
import com.aizuda.snailjob.server.common.exception.SnailJobServerException;
|
||||
import com.aizuda.snailjob.server.common.handler.ClientNodeAllocateHandler;
|
||||
import com.aizuda.snailjob.server.common.rpc.client.annotation.Body;
|
||||
import com.aizuda.snailjob.server.common.rpc.client.annotation.Header;
|
||||
import com.aizuda.snailjob.server.common.rpc.client.annotation.Mapping;
|
||||
import com.aizuda.snailjob.server.common.rpc.client.annotation.Param;
|
||||
import com.fasterxml.jackson.databind.util.ByteBufferBackedInputStream;
|
||||
import com.github.rholder.retry.RetryException;
|
||||
import com.github.rholder.retry.RetryListener;
|
||||
import com.github.rholder.retry.Retryer;
|
||||
import com.github.rholder.retry.RetryerBuilder;
|
||||
import com.github.rholder.retry.StopStrategies;
|
||||
import com.github.rholder.retry.WaitStrategies;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import io.netty.handler.codec.http.DefaultHttpHeaders;
|
||||
import io.netty.handler.codec.http.HttpHeaders;
|
||||
import io.netty.handler.codec.http.HttpMethod;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 请求处理器
|
||||
*
|
||||
* @author: opensnail
|
||||
* @date : 2023-05-11 21:45
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Slf4j
|
||||
public class GrpcClientInvokeHandler implements InvocationHandler {
|
||||
|
||||
private final String groupName;
|
||||
private String hostId;
|
||||
private String hostIp;
|
||||
private Integer hostPort;
|
||||
private final boolean failRetry;
|
||||
private final int retryTimes;
|
||||
private final int retryInterval;
|
||||
private final RetryListener retryListener;
|
||||
private final boolean failover;
|
||||
private final Integer routeKey;
|
||||
private final String allocKey;
|
||||
private final Integer executorTimeout;
|
||||
private final String namespaceId;
|
||||
private final boolean async;
|
||||
|
||||
public GrpcClientInvokeHandler(final String groupName, final RegisterNodeInfo registerNodeInfo,
|
||||
final boolean failRetry, final int retryTimes,
|
||||
final int retryInterval, final RetryListener retryListener, final Integer routeKey, final String allocKey,
|
||||
final boolean failover, final Integer executorTimeout, final String namespaceId) {
|
||||
this.groupName = groupName;
|
||||
this.hostId = registerNodeInfo.getHostId();
|
||||
this.hostPort = registerNodeInfo.getHostPort();
|
||||
this.hostIp = registerNodeInfo.getHostIp();
|
||||
this.failRetry = failRetry;
|
||||
this.retryTimes = retryTimes;
|
||||
this.retryInterval = retryInterval;
|
||||
this.retryListener = retryListener;
|
||||
this.failover = failover;
|
||||
this.routeKey = routeKey;
|
||||
this.allocKey = allocKey;
|
||||
this.executorTimeout = executorTimeout;
|
||||
this.namespaceId = namespaceId;
|
||||
this.async = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
|
||||
Mapping annotation = method.getAnnotation(Mapping.class);
|
||||
Assert.notNull(annotation, () -> new SnailJobServerException("@Mapping cannot be null"));
|
||||
|
||||
if (failover) {
|
||||
return doFailoverHandler(method, args, annotation);
|
||||
}
|
||||
|
||||
return requestRemote(method, args, annotation, 1);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Result doFailoverHandler(final Method method, final Object[] args, final Mapping annotation)
|
||||
throws Throwable {
|
||||
Set<RegisterNodeInfo> serverNodeSet = CacheRegisterTable.getServerNodeSet(groupName, namespaceId);
|
||||
|
||||
// 最多调用size次
|
||||
int size = serverNodeSet.size();
|
||||
for (int count = 1; count <= size; count++) {
|
||||
log.debug("Start request client. count:[{}] clientId:[{}] clientAddr:[{}:{}] serverIp:[{}]", count, hostId,
|
||||
hostIp, hostPort, NetUtil.getLocalIpStr());
|
||||
Result result = requestRemote(method, args, annotation, count);
|
||||
if (Objects.nonNull(result)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
throw new SnailJobServerException("No available nodes.");
|
||||
}
|
||||
|
||||
private Result requestRemote(Method method, Object[] args, Mapping mapping, int count) throws Throwable {
|
||||
|
||||
try {
|
||||
|
||||
// 参数解析
|
||||
ParseParasResult parasResult = doParseParams(method, args);
|
||||
|
||||
// 若是POST请求,请求体不能是null
|
||||
if (RequestMethod.POST.name().equals(mapping.method().name())) {
|
||||
Assert.notNull(parasResult.body, () -> new SnailJobServerException("body cannot be null"));
|
||||
}
|
||||
|
||||
Retryer<Result> retryer = buildResultRetryer();
|
||||
|
||||
Map<String, String> requestHeaders = parasResult.requestHeaders;
|
||||
// 统一设置Token
|
||||
requestHeaders.put(SystemConstants.SNAIL_JOB_AUTH_TOKEN, CacheToken.get(groupName, namespaceId));
|
||||
|
||||
// SnailJobRequest snailJobRequest = new SnailJobRequest(args);
|
||||
Result result = retryer.call(() -> {
|
||||
|
||||
ListenableFuture<GrpcResult> future = GrpcChannel.send(hostId, hostIp, hostPort,
|
||||
mapping.path(), JsonUtil.toJsonString(args), requestHeaders);
|
||||
|
||||
SnailJobLog.LOCAL.debug("request complete requestId:[{}] 耗时:[{}ms]", 0);
|
||||
if (async) {
|
||||
// 暂时不支持异步调用
|
||||
return null;
|
||||
} else {
|
||||
Assert.notNull(future, () -> new SnailJobServerException("completableFuture is null"));
|
||||
GrpcResult grpcResult = future.get(Optional.ofNullable(executorTimeout).orElse(20), TimeUnit.SECONDS);
|
||||
ByteBuffer byteBuffer = grpcResult.getData().getValue().asReadOnlyByteBuffer();
|
||||
Object obj = JsonUtil.parseObject(new ByteBufferBackedInputStream(byteBuffer), Object.class);
|
||||
return new Result(grpcResult.getStatus(), grpcResult.getMessage(), obj);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
log.debug("Request client success. count:[{}] clientId:[{}] clientAddr:[{}:{}] serverIp:[{}]", count,
|
||||
hostId,
|
||||
hostIp, hostPort, NetUtil.getLocalIpStr());
|
||||
|
||||
return result;
|
||||
} catch (ExecutionException ex) {
|
||||
// 网络异常 TimeoutException |
|
||||
if (ex.getCause() instanceof SnailJobRemotingTimeOutException && failover) {
|
||||
log.error("request client I/O error, count:[{}] clientId:[{}] clientAddr:[{}:{}] serverIp:[{}]", count,
|
||||
hostId, hostIp, hostPort, NetUtil.getLocalIpStr(), ex);
|
||||
|
||||
// 进行路由剔除处理
|
||||
CacheRegisterTable.remove(groupName, namespaceId, hostId);
|
||||
// 重新选一个可用的客户端节点
|
||||
ClientNodeAllocateHandler clientNodeAllocateHandler = SnailSpringContext.getBean(
|
||||
ClientNodeAllocateHandler.class);
|
||||
RegisterNodeInfo serverNode = clientNodeAllocateHandler.getServerNode(allocKey, groupName, namespaceId,
|
||||
routeKey);
|
||||
// 这里表示无可用节点
|
||||
if (Objects.isNull(serverNode)) {
|
||||
throw ex.getCause();
|
||||
}
|
||||
|
||||
this.hostId = serverNode.getHostId();
|
||||
this.hostPort = serverNode.getHostPort();
|
||||
this.hostIp = serverNode.getHostIp();
|
||||
|
||||
} else {
|
||||
// 其他异常继续抛出
|
||||
log.error("request client error.count:[{}] clientId:[{}] clientAddr:[{}:{}] serverIp:[{}]", count,
|
||||
hostId, hostIp, hostPort, NetUtil.getLocalIpStr(), ex);
|
||||
throw ex.getCause();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.error("request client unknown exception. count:[{}] clientId:[{}] clientAddr:[{}:{}] serverIp:[{}]",
|
||||
count, hostId, hostIp, hostPort, NetUtil.getLocalIpStr(), ex);
|
||||
|
||||
Throwable throwable = ex;
|
||||
if (ex.getClass().isAssignableFrom(RetryException.class)) {
|
||||
RetryException re = (RetryException) ex;
|
||||
throwable = re.getLastFailedAttempt().getExceptionCause();
|
||||
if (throwable.getCause() instanceof SnailJobRemotingTimeOutException) {
|
||||
// 若重试之后该接口仍然有问题,进行路由剔除处理
|
||||
CacheRegisterTable.remove(groupName, namespaceId, hostId);
|
||||
}
|
||||
}
|
||||
|
||||
throw throwable;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Retryer<Result> buildResultRetryer() {
|
||||
Retryer<Result> retryer = RetryerBuilder.<Result>newBuilder()
|
||||
.retryIfException(throwable -> failRetry)
|
||||
.withStopStrategy(StopStrategies.stopAfterAttempt(retryTimes <= 0 ? 1 : retryTimes))
|
||||
.withWaitStrategy(WaitStrategies.fixedWait(Math.max(retryInterval, 0), TimeUnit.SECONDS))
|
||||
.withRetryListener(retryListener)
|
||||
.build();
|
||||
return retryer;
|
||||
}
|
||||
|
||||
private ParseParasResult doParseParams(Method method, Object[] args) {
|
||||
|
||||
Object body = null;
|
||||
Map<String, String> requestHeaders = new HashMap<>();
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
// 解析参数
|
||||
Parameter[] parameters = method.getParameters();
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
Parameter parameter = parameters[i];
|
||||
if (parameter.isAnnotationPresent(Body.class)) {
|
||||
body = args[i];
|
||||
} else if ((parameter.isAnnotationPresent(Header.class))) {
|
||||
requestHeaders.put(SystemConstants.SNAIL_JOB_HEAD_KEY, JsonUtil.toJsonString(args[i]));
|
||||
} else if ((parameter.isAnnotationPresent(Param.class))) {
|
||||
paramMap.put(parameter.getAnnotation(Param.class).name(), args[i]);
|
||||
} else {
|
||||
throw new SnailJobServerException("parameter error");
|
||||
}
|
||||
}
|
||||
|
||||
ParseParasResult parseParasResult = new ParseParasResult();
|
||||
parseParasResult.setBody(body);
|
||||
parseParasResult.setParamMap(paramMap);
|
||||
parseParasResult.setRequestHeaders(requestHeaders);
|
||||
return parseParasResult;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class ParseParasResult {
|
||||
|
||||
private Object body = null;
|
||||
private Map<String, String> requestHeaders;
|
||||
private Map<String, Object> paramMap;
|
||||
}
|
||||
}
|
||||
@ -105,12 +105,17 @@ public class RequestBuilder<T, R> {
|
||||
throw new SnailJobServerException("class not found exception to: [{}]", clintInterface.getName());
|
||||
}
|
||||
|
||||
// todo 测试先注释
|
||||
RpcClientInvokeHandler clientInvokeHandler = new RpcClientInvokeHandler(
|
||||
nodeInfo.getGroupName(), nodeInfo, failRetry, retryTimes, retryInterval,
|
||||
retryListener, routeKey, allocKey, failover, executorTimeout, nodeInfo.getNamespaceId());
|
||||
|
||||
GrpcClientInvokeHandler grpcClientInvokeHandler = new GrpcClientInvokeHandler(
|
||||
nodeInfo.getGroupName(), nodeInfo, failRetry, retryTimes, retryInterval,
|
||||
retryListener, routeKey, allocKey, failover, executorTimeout, nodeInfo.getNamespaceId());
|
||||
|
||||
return (T) Proxy.newProxyInstance(clintInterface.getClassLoader(),
|
||||
new Class[]{clintInterface}, clientInvokeHandler);
|
||||
new Class[]{clintInterface}, grpcClientInvokeHandler);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
package com.aizuda.snailjob.server.common.rpc.server;
|
||||
|
||||
import io.grpc.Context;
|
||||
import io.grpc.Contexts;
|
||||
import io.grpc.Metadata;
|
||||
import io.grpc.ServerCall;
|
||||
import io.grpc.ServerCall.Listener;
|
||||
import io.grpc.ServerCallHandler;
|
||||
import io.grpc.ServerInterceptor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author: opensnail
|
||||
* @date : 2024-08-22
|
||||
*/
|
||||
@Slf4j
|
||||
public class GrpcInterceptor implements ServerInterceptor {
|
||||
|
||||
@Override
|
||||
public <ReqT, RespT> Listener<ReqT> interceptCall(final ServerCall<ReqT, RespT> serverCall, final Metadata metadata,
|
||||
final ServerCallHandler<ReqT, RespT> serverCallHandler) {
|
||||
String fullMethodName = serverCall.getMethodDescriptor().getFullMethodName();
|
||||
long start = System.currentTimeMillis();
|
||||
Context context = Context.current();
|
||||
|
||||
try {
|
||||
return Contexts.interceptCall(context, serverCall, metadata, serverCallHandler);
|
||||
} finally {
|
||||
log.info("method invoked: {} cast:{}ms", fullMethodName, System.currentTimeMillis() - start);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,169 @@
|
||||
package com.aizuda.snailjob.server.common.rpc.server;
|
||||
|
||||
import akka.actor.AbstractActor;
|
||||
import cn.hutool.core.net.url.UrlBuilder;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aizuda.snailjob.common.core.context.SnailSpringContext;
|
||||
import com.aizuda.snailjob.common.core.enums.HeadersEnum;
|
||||
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcResult;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.Metadata;
|
||||
import com.aizuda.snailjob.common.core.model.NettyResult;
|
||||
import com.aizuda.snailjob.common.core.model.SnailJobRequest;
|
||||
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
||||
import com.aizuda.snailjob.common.log.SnailJobLog;
|
||||
import com.aizuda.snailjob.server.common.HttpRequestHandler;
|
||||
import com.aizuda.snailjob.server.common.Register;
|
||||
import com.aizuda.snailjob.server.common.akka.ActorGenerator;
|
||||
import com.aizuda.snailjob.server.common.cache.CacheToken;
|
||||
import com.aizuda.snailjob.server.common.dto.GrpcRequest;
|
||||
import com.aizuda.snailjob.server.common.exception.SnailJobServerException;
|
||||
import com.aizuda.snailjob.server.common.register.ClientRegister;
|
||||
import com.aizuda.snailjob.server.common.register.RegisterContext;
|
||||
import com.fasterxml.jackson.databind.util.ByteBufferBackedInputStream;
|
||||
import com.google.protobuf.Any;
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.UnsafeByteOperations;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
||||
import io.netty.handler.codec.http.DefaultHttpHeaders;
|
||||
import io.netty.handler.codec.http.FullHttpResponse;
|
||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||
import io.netty.handler.codec.http.HttpHeaderValues;
|
||||
import io.netty.handler.codec.http.HttpHeaders;
|
||||
import io.netty.handler.codec.http.HttpMethod;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.handler.codec.http.HttpVersion;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.aizuda.snailjob.common.core.alarm.AlarmContext.build;
|
||||
|
||||
/**
|
||||
* 处理netty客户端请求
|
||||
*
|
||||
* @author: opensnail
|
||||
* @date : 2023-07-24 09:20
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@Component(ActorGenerator.REQUEST_HANDLER_ACTOR)
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
@Slf4j
|
||||
public class GrpcRequestHandlerActor extends AbstractActor {
|
||||
|
||||
@Override
|
||||
public Receive createReceive() {
|
||||
return receiveBuilder().match(GrpcRequest.class, grpcRequest -> {
|
||||
GrpcSnailJobRequest grpcSnailJobRequest = grpcRequest.getSnailJobRequest();
|
||||
Metadata metadata = grpcSnailJobRequest.getMetadata();
|
||||
final String uri = metadata.getUri();
|
||||
if (StrUtil.isBlank(uri)) {
|
||||
SnailJobLog.LOCAL.error("uri can not be null");
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, String> headersMap = metadata.getHeadersMap();
|
||||
String result = "";
|
||||
try {
|
||||
SnailJobRequest request = new SnailJobRequest();
|
||||
Any body = grpcSnailJobRequest.getBody();
|
||||
ByteString byteString = body.getValue();
|
||||
ByteBuffer byteBuffer = byteString.asReadOnlyByteBuffer();
|
||||
Object[] objects = JsonUtil.parseObject(new ByteBufferBackedInputStream(byteBuffer), Object[].class);
|
||||
request.setArgs(objects);
|
||||
result = doProcess(uri, JsonUtil.toJsonString(request), headersMap);
|
||||
} catch (Exception e) {
|
||||
SnailJobLog.LOCAL.error("http request error. [{}]",grpcSnailJobRequest, e);
|
||||
result = JsonUtil.toJsonString(new NettyResult(StatusEnum.NO.getStatus(), e.getMessage(), null, 0));
|
||||
} finally {
|
||||
|
||||
NettyResult nettyResult = JsonUtil.parseObject(result, NettyResult.class);
|
||||
StreamObserver<GrpcResult> streamObserver = grpcRequest.getStreamObserver();
|
||||
GrpcResult grpcResult = GrpcResult.newBuilder()
|
||||
.setStatus(nettyResult.getStatus())
|
||||
.setMessage(Optional.ofNullable(nettyResult.getMessage()).orElse(StrUtil.EMPTY))
|
||||
.setData(Any.newBuilder()
|
||||
.setValue(UnsafeByteOperations.unsafeWrap(JsonUtil.toJsonString(nettyResult.getData()).getBytes()))
|
||||
.build())
|
||||
.build();
|
||||
|
||||
streamObserver.onNext(grpcResult);
|
||||
streamObserver.onCompleted();
|
||||
getContext().stop(getSelf());
|
||||
}
|
||||
|
||||
|
||||
}).build();
|
||||
}
|
||||
|
||||
private String doProcess(String uri, String content, Map<String, String> headersMap) {
|
||||
|
||||
Register register = SnailSpringContext.getBean(ClientRegister.BEAN_NAME, Register.class);
|
||||
|
||||
String hostId = headersMap.get(HeadersEnum.HOST_ID.getKey());
|
||||
String hostIp = headersMap.get(HeadersEnum.HOST_IP.getKey());
|
||||
Integer hostPort = Integer.valueOf(headersMap.get(HeadersEnum.HOST_PORT.getKey()));
|
||||
String groupName = headersMap.get(HeadersEnum.GROUP_NAME.getKey());
|
||||
String namespace = headersMap.get(HeadersEnum.NAMESPACE.getKey());
|
||||
String token = headersMap.get(HeadersEnum.TOKEN.getKey());
|
||||
|
||||
if (StrUtil.isBlank(token) || !CacheToken.get(groupName, namespace).equals(token)) {
|
||||
throw new SnailJobServerException("Token authentication failed. [namespace:{} groupName:{} token:{}]",
|
||||
namespace, groupName, token);
|
||||
}
|
||||
|
||||
// 注册版本 此后后续版本将迁移至BeatHttpRequestHandler 只处理beat的心态注册
|
||||
RegisterContext registerContext = new RegisterContext();
|
||||
registerContext.setGroupName(groupName);
|
||||
registerContext.setHostPort(hostPort);
|
||||
registerContext.setHostIp(hostIp);
|
||||
registerContext.setHostId(hostId);
|
||||
registerContext.setUri(uri);
|
||||
registerContext.setNamespaceId(namespace);
|
||||
boolean result = register.register(registerContext);
|
||||
if (!result) {
|
||||
SnailJobLog.LOCAL.warn("client register error. groupName:[{}]", groupName);
|
||||
}
|
||||
|
||||
DefaultHttpHeaders headers = new DefaultHttpHeaders();
|
||||
headersMap.forEach(headers::add);
|
||||
|
||||
UrlBuilder builder = UrlBuilder.ofHttp(uri);
|
||||
Collection<HttpRequestHandler> httpRequestHandlers = SnailSpringContext.getContext()
|
||||
.getBeansOfType(HttpRequestHandler.class).values();
|
||||
for (HttpRequestHandler httpRequestHandler : httpRequestHandlers) {
|
||||
if (httpRequestHandler.supports(builder.getPathStr())) {
|
||||
return httpRequestHandler.doHandler(content, builder, headers);
|
||||
}
|
||||
}
|
||||
|
||||
throw new SnailJobServerException("No matching handler found. Path:[{}] method:[{}]", builder.getPathStr());
|
||||
}
|
||||
|
||||
/**
|
||||
* write response
|
||||
*/
|
||||
private void writeResponse(ChannelHandlerContext ctx, boolean keepAlive, String responseJson) {
|
||||
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK,
|
||||
Unpooled.copiedBuffer(responseJson, CharsetUtil.UTF_8));
|
||||
response.headers().set(HttpHeaderNames.CONTENT_TYPE,
|
||||
HttpHeaderValues.APPLICATION_JSON);
|
||||
response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
|
||||
if (keepAlive) {
|
||||
response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
|
||||
}
|
||||
ctx.writeAndFlush(response);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package com.aizuda.snailjob.server.common.rpc.server;
|
||||
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcResult;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest;
|
||||
import io.grpc.MethodDescriptor;
|
||||
import io.grpc.ServerBuilder;
|
||||
import io.grpc.ServerCallHandler;
|
||||
import io.grpc.ServerServiceDefinition;
|
||||
import io.grpc.protobuf.ProtoUtils;
|
||||
import io.grpc.stub.ServerCalls;
|
||||
import net.devh.boot.grpc.server.serverfactory.GrpcServerConfigurer;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class GrpcServerConsumerConfig implements GrpcServerConfigurer {
|
||||
|
||||
@Override
|
||||
public void accept(ServerBuilder<?> serverBuilder) {
|
||||
// 创建服务定义
|
||||
ServerServiceDefinition serviceDefinition = createServiceDefinition(
|
||||
"UnaryRequest", "unaryRequest",
|
||||
new UnaryRequestHandler());
|
||||
serverBuilder.addService(serviceDefinition);
|
||||
serverBuilder.intercept(new GrpcInterceptor());
|
||||
}
|
||||
|
||||
public static ServerServiceDefinition createServiceDefinition(
|
||||
String serviceName,
|
||||
String methodName,
|
||||
ServerCalls.UnaryMethod<GrpcSnailJobRequest, GrpcResult> unaryMethod) {
|
||||
|
||||
MethodDescriptor<GrpcSnailJobRequest, GrpcResult> methodDescriptor =
|
||||
MethodDescriptor.<GrpcSnailJobRequest, GrpcResult>newBuilder()
|
||||
.setType(MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(MethodDescriptor.generateFullMethodName(serviceName, methodName))
|
||||
.setRequestMarshaller(ProtoUtils.marshaller(GrpcSnailJobRequest.getDefaultInstance()))
|
||||
.setResponseMarshaller(ProtoUtils.marshaller(GrpcResult.getDefaultInstance()))
|
||||
.build();
|
||||
|
||||
ServerCallHandler<GrpcSnailJobRequest, GrpcResult> callHandler = ServerCalls.asyncUnaryCall(unaryMethod);
|
||||
|
||||
return ServerServiceDefinition.builder(serviceName)
|
||||
.addMethod(methodDescriptor, callHandler)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@ -87,9 +87,9 @@ public class NettyHttpServer implements Runnable, Lifecycle {
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
thread = new Thread(this);
|
||||
thread.setDaemon(true);
|
||||
thread.start();
|
||||
// thread = new Thread(this);
|
||||
// thread.setDaemon(true);
|
||||
// thread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -36,8 +36,8 @@ import java.util.Collection;
|
||||
* @date : 2023-07-24 09:20
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@Component(ActorGenerator.REQUEST_HANDLER_ACTOR)
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
//@Component(ActorGenerator.REQUEST_HANDLER_ACTOR)
|
||||
//@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
@Slf4j
|
||||
public class RequestHandlerActor extends AbstractActor {
|
||||
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
package com.aizuda.snailjob.server.common.rpc.server;
|
||||
|
||||
import akka.actor.ActorRef;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcResult;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.GrpcSnailJobRequest;
|
||||
import com.aizuda.snailjob.common.core.grpc.auto.Metadata;
|
||||
import com.aizuda.snailjob.server.common.akka.ActorGenerator;
|
||||
import com.aizuda.snailjob.server.common.dto.GrpcRequest;
|
||||
import com.aizuda.snailjob.server.common.dto.NettyHttpRequest;
|
||||
import io.grpc.stub.ServerCalls;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import io.netty.handler.codec.http.HttpUtil;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
/**
|
||||
* @author: opensnail
|
||||
* @date : 2024-08-22
|
||||
*/
|
||||
public class UnaryRequestHandler implements ServerCalls.UnaryMethod<GrpcSnailJobRequest, GrpcResult>{
|
||||
|
||||
@Override
|
||||
public void invoke(final GrpcSnailJobRequest snailJobRequest, final StreamObserver<GrpcResult> streamObserver) {
|
||||
// 处理请求并返回响应
|
||||
// GrpcResult result = GrpcResult.newBuilder().setMessage("调度成功").setStatus(1).build();
|
||||
|
||||
Metadata metadata = snailJobRequest.getMetadata();
|
||||
GrpcRequest grpcRequest = GrpcRequest.builder()
|
||||
.uri(metadata.getUri())
|
||||
.snailJobRequest(snailJobRequest)
|
||||
.streamObserver(streamObserver)
|
||||
.build();
|
||||
|
||||
ActorRef actorRef = ActorGenerator.requestHandlerActor();
|
||||
actorRef.tell(grpcRequest, actorRef);
|
||||
|
||||
// // 发送响应
|
||||
// streamObserver.onNext(result);
|
||||
// streamObserver.onCompleted();
|
||||
}
|
||||
}
|
||||
@ -36,7 +36,7 @@ public class SnailJobServerApplication {
|
||||
SpringApplication.run(SnailJobServerApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
// @Bean
|
||||
public ApplicationRunner nettyStartupChecker(NettyHttpServer nettyHttpServer, ServletWebServerFactory serverFactory) {
|
||||
return args -> {
|
||||
// 最长自旋10秒,保证nettyHttpServer启动完成
|
||||
|
||||
@ -75,6 +75,9 @@ logging:
|
||||
# level:
|
||||
# ## 方便调试 SQL
|
||||
# com.aizuda.snailjob.template.datasource.persistence.mapper: debug
|
||||
grpc:
|
||||
server:
|
||||
port: 1788
|
||||
|
||||
snail-job:
|
||||
retry-pull-page-size: 1000 # 拉取重试数据的每批次的大小
|
||||
|
||||
Loading…
Reference in New Issue
Block a user