From 967ab641dd35cee7e9b6d2b4b210077ac20e5980 Mon Sep 17 00:00:00 2001 From: CalvinKirs Date: Tue, 26 Jan 2021 01:18:47 +0800 Subject: [PATCH] fix bug and code style --- .../remote/serialize/ProtoStuffUtils.java | 17 +++++------------ .../dolphinscheduler/rpc/client/IRpcClient.java | 1 - .../rpc/client/RpcRequestTable.java | 9 ++++----- .../rpc/codec/NettyDecoder.java | 9 ++++----- .../rpc/codec/NettyEncoder.java | 7 +++---- .../rpc/config/ServiceBean.java | 1 - .../rpc/remote/NettyServer.java | 4 ++-- .../dolphinscheduler/rpc/UserService.java | 2 +- 8 files changed, 19 insertions(+), 31 deletions(-) diff --git a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/serialize/ProtoStuffUtils.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/serialize/ProtoStuffUtils.java index 189b1a4791..8284171fc1 100644 --- a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/serialize/ProtoStuffUtils.java +++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/serialize/ProtoStuffUtils.java @@ -17,14 +17,14 @@ package org.apache.dolphinscheduler.remote.serialize; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + import io.protostuff.LinkedBuffer; import io.protostuff.ProtostuffIOUtil; import io.protostuff.Schema; import io.protostuff.runtime.RuntimeSchema; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - /** * ProtoStuffUtils */ @@ -49,20 +49,13 @@ public class ProtoStuffUtils { @SuppressWarnings("unchecked") private static Schema getSchema(Class clazz) { - Schema schema = (Schema) schemaCache.get(clazz); - if (schema == null) { - schema = RuntimeSchema.getSchema(clazz); - if (schema != null) { - schemaCache.put(clazz, schema); - } - } - return schema; + return (Schema) schemaCache.computeIfAbsent(clazz, RuntimeSchema::createFrom); } public static T deserialize(byte[] bytes, Class clazz) { Schema schema = getSchema(clazz); T obj = schema.newMessage(); - if(null==obj){ + if (null == obj) { return null; } ProtostuffIOUtil.mergeFrom(bytes, obj, schema); diff --git a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/client/IRpcClient.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/client/IRpcClient.java index 979a979e88..609d3b1aed 100644 --- a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/client/IRpcClient.java +++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/client/IRpcClient.java @@ -24,7 +24,6 @@ import org.apache.dolphinscheduler.remote.utils.Host; */ public interface IRpcClient { - T create(Class clazz, Host host) throws Exception; } diff --git a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/client/RpcRequestTable.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/client/RpcRequestTable.java index f3cdff4f77..5f5e32e486 100644 --- a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/client/RpcRequestTable.java +++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/client/RpcRequestTable.java @@ -24,18 +24,17 @@ import java.util.concurrent.ConcurrentHashMap; */ public class RpcRequestTable { - private static ConcurrentHashMap requestMap = new ConcurrentHashMap<>(); - public static void put(String requestId,RpcRequestCache rpcRequestCache){ - requestMap.put(requestId,rpcRequestCache); + public static void put(String requestId, RpcRequestCache rpcRequestCache) { + requestMap.put(requestId, rpcRequestCache); } - public static RpcRequestCache get(String requestId){ + public static RpcRequestCache get(String requestId) { return requestMap.get(requestId); } - public static void remove(String requestId){ + public static void remove(String requestId) { requestMap.remove(requestId); } diff --git a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/codec/NettyDecoder.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/codec/NettyDecoder.java index a9a1466788..d44ed0408d 100644 --- a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/codec/NettyDecoder.java +++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/codec/NettyDecoder.java @@ -17,14 +17,14 @@ package org.apache.dolphinscheduler.rpc.codec; -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; - import org.apache.dolphinscheduler.remote.serialize.ProtoStuffUtils; import java.util.List; +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; + /** * NettyDecoder */ @@ -32,7 +32,6 @@ public class NettyDecoder extends ByteToMessageDecoder { private Class genericClass; - public NettyDecoder(Class genericClass) { this.genericClass = genericClass; } diff --git a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/codec/NettyEncoder.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/codec/NettyEncoder.java index ae9f1c9722..280fefc78c 100644 --- a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/codec/NettyEncoder.java +++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/codec/NettyEncoder.java @@ -17,15 +17,14 @@ package org.apache.dolphinscheduler.rpc.codec; +import org.apache.dolphinscheduler.remote.serialize.ProtoStuffUtils; + import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; -import org.apache.dolphinscheduler.remote.serialize.ProtoStuffUtils; - /** - * @author jiangli - * @date 2021-01-12 18:52 + * NettyEncoder */ public class NettyEncoder extends MessageToByteEncoder { diff --git a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/config/ServiceBean.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/config/ServiceBean.java index f51f35b3e6..f1c9e01767 100644 --- a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/config/ServiceBean.java +++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/config/ServiceBean.java @@ -25,7 +25,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; - import org.reflections.Reflections; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/remote/NettyServer.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/remote/NettyServer.java index 52b6b4e422..3ca602a4a1 100644 --- a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/remote/NettyServer.java +++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/remote/NettyServer.java @@ -18,10 +18,10 @@ package org.apache.dolphinscheduler.rpc.remote; import org.apache.dolphinscheduler.remote.config.NettyServerConfig; -import org.apache.dolphinscheduler.rpc.codec.NettyDecoder; -import org.apache.dolphinscheduler.rpc.codec.NettyEncoder; import org.apache.dolphinscheduler.remote.utils.Constants; import org.apache.dolphinscheduler.remote.utils.NettyUtils; +import org.apache.dolphinscheduler.rpc.codec.NettyDecoder; +import org.apache.dolphinscheduler.rpc.codec.NettyEncoder; import org.apache.dolphinscheduler.rpc.common.RpcRequest; import org.apache.dolphinscheduler.rpc.common.RpcResponse; diff --git a/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/rpc/UserService.java b/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/rpc/UserService.java index 025735c1d3..432d06dbb1 100644 --- a/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/rpc/UserService.java +++ b/dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/rpc/UserService.java @@ -23,7 +23,7 @@ import org.apache.dolphinscheduler.rpc.base.RpcService; * UserService */ @RpcService("IUserService") -public class UserService implements IUserService{ +public class UserService implements IUserService { @Override public Boolean say(String s) {