Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pentaLiker
DolphinScheduler
提交
7a976f4c
DolphinScheduler
项目概览
pentaLiker
/
DolphinScheduler
与 Fork 源项目一致
Fork自
apache / DolphinScheduler
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DolphinScheduler
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7a976f4c
编写于
1月 26, 2021
作者:
C
CalvinKirs
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix code smell
上级
967ab641
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
49 addition
and
43 deletion
+49
-43
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/serialize/ProtoStuffUtils.java
...he/dolphinscheduler/remote/serialize/ProtoStuffUtils.java
+4
-0
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/client/ConsumerConfigCache.java
...ache/dolphinscheduler/rpc/client/ConsumerConfigCache.java
+4
-0
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/client/ConsumerInterceptor.java
...ache/dolphinscheduler/rpc/client/ConsumerInterceptor.java
+0
-3
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/client/RpcRequestTable.java
...g/apache/dolphinscheduler/rpc/client/RpcRequestTable.java
+4
-0
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/common/ConsumerConfigConstants.java
.../dolphinscheduler/rpc/common/ConsumerConfigConstants.java
+4
-0
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/common/ThreadPoolManager.java
...apache/dolphinscheduler/rpc/common/ThreadPoolManager.java
+5
-6
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/config/ServiceBean.java
...a/org/apache/dolphinscheduler/rpc/config/ServiceBean.java
+8
-3
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/remote/NettyClient.java
...a/org/apache/dolphinscheduler/rpc/remote/NettyClient.java
+3
-2
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/remote/NettyClientHandler.java
...pache/dolphinscheduler/rpc/remote/NettyClientHandler.java
+14
-21
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/remote/NettyServerHandler.java
...pache/dolphinscheduler/rpc/remote/NettyServerHandler.java
+3
-8
未找到文件。
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/serialize/ProtoStuffUtils.java
浏览文件 @
7a976f4c
...
...
@@ -30,6 +30,10 @@ import io.protostuff.runtime.RuntimeSchema;
*/
public
class
ProtoStuffUtils
{
private
ProtoStuffUtils
()
{
throw
new
IllegalStateException
(
"Utility class"
);
}
private
static
LinkedBuffer
buffer
=
LinkedBuffer
.
allocate
(
LinkedBuffer
.
DEFAULT_BUFFER_SIZE
);
private
static
Map
<
Class
<?>,
Schema
<?>>
schemaCache
=
new
ConcurrentHashMap
<>();
...
...
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/client/ConsumerConfigCache.java
浏览文件 @
7a976f4c
...
...
@@ -24,6 +24,10 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public
class
ConsumerConfigCache
{
private
ConsumerConfigCache
()
{
throw
new
IllegalStateException
(
"Utility class"
);
}
private
static
ConcurrentHashMap
<
String
,
ConsumerConfig
>
consumerMap
=
new
ConcurrentHashMap
<>();
public
static
ConsumerConfig
getConfigByServersName
(
String
serviceName
)
{
...
...
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/client/ConsumerInterceptor.java
浏览文件 @
7a976f4c
...
...
@@ -75,11 +75,8 @@ public class ConsumerInterceptor {
request
.
setClassName
(
method
.
getDeclaringClass
().
getSimpleName
());
request
.
setMethodName
(
method
.
getName
());
request
.
setParameterTypes
(
method
.
getParameterTypes
());
request
.
setParameters
(
args
);
String
serviceName
=
method
.
getDeclaringClass
().
getName
();
return
request
;
}
...
...
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/client/RpcRequestTable.java
浏览文件 @
7a976f4c
...
...
@@ -24,6 +24,10 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public
class
RpcRequestTable
{
private
RpcRequestTable
()
{
throw
new
IllegalStateException
(
"Utility class"
);
}
private
static
ConcurrentHashMap
<
String
,
RpcRequestCache
>
requestMap
=
new
ConcurrentHashMap
<>();
public
static
void
put
(
String
requestId
,
RpcRequestCache
rpcRequestCache
)
{
...
...
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/common/ConsumerConfigConstants.java
浏览文件 @
7a976f4c
...
...
@@ -22,6 +22,10 @@ package org.apache.dolphinscheduler.rpc.common;
*/
public
class
ConsumerConfigConstants
{
private
ConsumerConfigConstants
()
{
throw
new
IllegalStateException
(
"Utility class"
);
}
public
static
final
Boolean
DEFAULT_SYNC
=
false
;
public
static
final
Integer
DEFAULT_RETRIES
=
3
;
...
...
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/common/ThreadPoolManager.java
浏览文件 @
7a976f4c
...
...
@@ -29,13 +29,12 @@ public enum ThreadPoolManager {
ExecutorService
executorService
;
private
static
final
int
WORK_QUEUE_SIZE
=
200
;
private
static
final
long
KEEP_ALIVE_TIME
=
60
;
ThreadPoolManager
()
{
int
SIZE_WORK_QUEUE
=
200
;
long
KEEP_ALIVE_TIME
=
60
;
int
CORE_POOL_SIZE
=
Runtime
.
getRuntime
().
availableProcessors
()
*
2
;
int
MAXI_MUM_POOL_SIZE
=
CORE_POOL_SIZE
*
4
;
executorService
=
new
ThreadPoolExecutor
(
CORE_POOL_SIZE
,
MAXI_MUM_POOL_SIZE
,
KEEP_ALIVE_TIME
,
TimeUnit
.
SECONDS
,
new
ArrayBlockingQueue
<>(
SIZE_WORK_QUEUE
),
executorService
=
new
ThreadPoolExecutor
(
Runtime
.
getRuntime
().
availableProcessors
()
*
2
,
Runtime
.
getRuntime
().
availableProcessors
()
*
4
,
KEEP_ALIVE_TIME
,
TimeUnit
.
SECONDS
,
new
ArrayBlockingQueue
<>(
WORK_QUEUE_SIZE
),
new
DiscardPolicy
());
}
...
...
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/config/ServiceBean.java
浏览文件 @
7a976f4c
...
...
@@ -36,10 +36,14 @@ public class ServiceBean {
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ServiceBean
.
class
);
private
static
Map
<
String
,
Object
>
serviceMap
=
new
HashMap
<>();
private
static
Map
<
String
,
Class
>
serviceMap
=
new
HashMap
<>();
private
static
AtomicBoolean
initialized
=
new
AtomicBoolean
(
false
);
private
ServiceBean
()
{
throw
new
IllegalStateException
(
"Utility class"
);
}
private
static
synchronized
void
init
()
{
// todo config
Reflections
f
=
new
Reflections
(
"org/apache/dolphinscheduler/rpc"
);
...
...
@@ -47,16 +51,17 @@ public class ServiceBean {
list
.
forEach
(
rpcClass
->
{
RpcService
rpcService
=
rpcClass
.
getAnnotation
(
RpcService
.
class
);
serviceMap
.
put
(
rpcService
.
value
(),
rpcClass
);
logger
.
info
(
"load rpc service {}"
,
rpcService
.
value
());
});
}
public
static
Class
getServiceClass
(
String
className
)
{
if
(
initialized
.
get
())
{
return
(
Class
)
serviceMap
.
get
(
className
);
return
serviceMap
.
get
(
className
);
}
else
{
init
();
}
return
(
Class
)
serviceMap
.
get
(
className
);
return
serviceMap
.
get
(
className
);
}
}
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/remote/NettyClient.java
浏览文件 @
7a976f4c
...
...
@@ -199,7 +199,7 @@ public class NettyClient {
String
serviceName
=
request
.
getClassName
()
+
request
.
getMethodName
();
rpcRequestCache
.
setServiceName
(
serviceName
);
RpcFuture
future
=
null
;
if
(
!
async
)
{
if
(
Boolean
.
FALSE
.
equals
(
async
)
)
{
future
=
new
RpcFuture
(
request
);
rpcRequestCache
.
setRpcFuture
(
future
);
}
...
...
@@ -207,13 +207,14 @@ public class NettyClient {
channel
.
writeAndFlush
(
request
);
RpcResponse
result
=
null
;
if
(
async
)
{
if
(
Boolean
.
TRUE
.
equals
(
async
)
)
{
result
=
new
RpcResponse
();
result
.
setStatus
((
byte
)
0
);
result
.
setResult
(
true
);
return
result
;
}
try
{
assert
future
!=
null
;
result
=
future
.
get
();
}
catch
(
InterruptedException
|
ExecutionException
e
)
{
logger
.
error
(
"send msg error,service name is {}"
,
serviceName
,
e
);
...
...
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/remote/NettyClientHandler.java
浏览文件 @
7a976f4c
...
...
@@ -21,13 +21,13 @@ import org.apache.dolphinscheduler.rpc.client.ConsumerConfig;
import
org.apache.dolphinscheduler.rpc.client.ConsumerConfigCache
;
import
org.apache.dolphinscheduler.rpc.client.RpcRequestCache
;
import
org.apache.dolphinscheduler.rpc.client.RpcRequestTable
;
import
org.apache.dolphinscheduler.rpc.common.RequestEventType
;
import
org.apache.dolphinscheduler.rpc.common.RpcRequest
;
import
org.apache.dolphinscheduler.rpc.common.RpcResponse
;
import
org.apache.dolphinscheduler.rpc.common.ThreadPoolManager
;
import
org.apache.dolphinscheduler.rpc.future.RpcFuture
;
import
java.lang.reflect.InvocationTargetException
;
import
java.net.InetSocketAddress
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -36,7 +36,6 @@ import io.netty.channel.ChannelHandler;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.ChannelInboundHandlerAdapter
;
import
io.netty.handler.timeout.IdleStateEvent
;
import
io.netty.util.concurrent.FastThreadLocalThread
;
/**
* NettyClientHandler
...
...
@@ -47,11 +46,10 @@ public class NettyClientHandler extends ChannelInboundHandlerAdapter {
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
NettyClientHandler
.
class
);
private
final
ThreadPoolManager
threadPoolManager
=
ThreadPoolManager
.
INSTANCE
;
private
static
final
ThreadPoolManager
threadPoolManager
=
ThreadPoolManager
.
INSTANCE
;
@Override
public
void
channelInactive
(
ChannelHandlerContext
ctx
)
{
InetSocketAddress
address
=
(
InetSocketAddress
)
ctx
.
channel
().
remoteAddress
();
ctx
.
channel
().
close
();
}
...
...
@@ -70,7 +68,7 @@ public class NettyClientHandler extends ChannelInboundHandlerAdapter {
private
void
readHandler
(
RpcResponse
rsp
,
RpcRequestCache
rpcRequest
)
{
String
serviceName
=
rpcRequest
.
getServiceName
();
ConsumerConfig
consumerConfig
=
ConsumerConfigCache
.
getConfigByServersName
(
serviceName
);
if
(
!
consumerConfig
.
getAsync
(
))
{
if
(
Boolean
.
FALSE
.
equals
(
consumerConfig
.
getAsync
()
))
{
RpcFuture
future
=
rpcRequest
.
getRpcFuture
();
RpcRequestTable
.
remove
(
rsp
.
getRequestId
());
future
.
done
(
rsp
);
...
...
@@ -78,31 +76,26 @@ public class NettyClientHandler extends ChannelInboundHandlerAdapter {
}
//async
new
FastThreadLocalThread
(()
->
{
if
(
rsp
.
getStatus
()
==
0
)
{
try
{
if
(
rsp
.
getStatus
()
==
0
)
{
try
{
consumerConfig
.
getServiceCallBackClass
().
getDeclaredConstructor
().
newInstance
().
run
(
rsp
.
getResult
());
}
catch
(
InvocationTargetException
|
NoSuchMethodException
e
)
{
logger
.
error
(
"rpc call back error, serviceName {} "
,
serviceName
,
e
);
}
}
else
{
logger
.
error
(
"rpc response error ,serviceName {}"
,
serviceName
);
}
}
catch
(
InstantiationException
|
IllegalAccessException
e
)
{
logger
.
error
(
"execute async error,serviceName {}"
,
serviceName
,
e
);
consumerConfig
.
getServiceCallBackClass
().
getDeclaredConstructor
().
newInstance
().
run
(
rsp
.
getResult
());
}
catch
(
InstantiationException
|
IllegalAccessException
|
NoSuchMethodException
|
InvocationTargetException
e
)
{
logger
.
error
(
"rpc service call back error,serviceName {},rsp {}"
,
serviceName
,
rsp
);
}
}).
start
();
}
else
{
logger
.
error
(
"rpc response error ,serviceName {},rsp {}"
,
serviceName
,
rsp
);
}
}
@Override
public
void
userEventTriggered
(
ChannelHandlerContext
ctx
,
Object
evt
)
throws
Exception
{
if
(
evt
instanceof
IdleStateEvent
)
{
IdleStateEvent
event
=
(
IdleStateEvent
)
evt
;
RpcRequest
request
=
new
RpcRequest
();
request
.
setEventType
(
(
byte
)
0
);
request
.
setEventType
(
RequestEventType
.
HEARTBEAT
.
getType
()
);
ctx
.
channel
().
writeAndFlush
(
request
);
logger
.
debug
(
"send heart beat msg..."
);
...
...
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/remote/NettyServerHandler.java
浏览文件 @
7a976f4c
...
...
@@ -17,6 +17,7 @@
package
org.apache.dolphinscheduler.rpc.remote
;
import
org.apache.dolphinscheduler.rpc.common.RequestEventType
;
import
org.apache.dolphinscheduler.rpc.common.RpcRequest
;
import
org.apache.dolphinscheduler.rpc.common.RpcResponse
;
import
org.apache.dolphinscheduler.rpc.common.ThreadPoolManager
;
...
...
@@ -38,12 +39,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
NettyServerHandler
.
class
);
private
final
ThreadPoolManager
threadPoolManager
=
ThreadPoolManager
.
INSTANCE
;
@Override
public
void
channelRegistered
(
ChannelHandlerContext
ctx
)
throws
Exception
{
super
.
channelRegistered
(
ctx
);
}
private
static
final
ThreadPoolManager
threadPoolManager
=
ThreadPoolManager
.
INSTANCE
;
@Override
public
void
channelInactive
(
ChannelHandlerContext
ctx
)
{
...
...
@@ -61,7 +57,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
RpcRequest
req
=
(
RpcRequest
)
msg
;
if
(
req
.
getEventType
()
==
0
)
{
if
(
req
.
getEventType
()
.
equals
(
RequestEventType
.
HEARTBEAT
.
getType
())
)
{
logger
.
info
(
"accept heartbeat msg"
);
return
;
...
...
@@ -111,7 +107,6 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
@Override
public
void
exceptionCaught
(
ChannelHandlerContext
ctx
,
Throwable
cause
)
{
System
.
out
.
println
(
"exceptionCaught"
);
logger
.
error
(
"exceptionCaught : {}"
,
cause
.
getMessage
(),
cause
);
ctx
.
channel
().
close
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录