Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pentaLiker
DolphinScheduler
提交
0f622845
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,发现更多精彩内容 >>
提交
0f622845
编写于
1月 28, 2021
作者:
C
CalvinKirs
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add rpc protocol
上级
d1658e91
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
281 addition
and
5 deletion
+281
-5
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/client/ConsumerInterceptor.java
...ache/dolphinscheduler/rpc/client/ConsumerInterceptor.java
+1
-1
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/codec/NettyDecoder.java
...a/org/apache/dolphinscheduler/rpc/codec/NettyDecoder.java
+7
-2
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/codec/NettyEncoder.java
...a/org/apache/dolphinscheduler/rpc/codec/NettyEncoder.java
+1
-1
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/protocol/MessageHeader.java
...g/apache/dolphinscheduler/rpc/protocol/MessageHeader.java
+95
-0
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/protocol/RpcProtocol.java
...org/apache/dolphinscheduler/rpc/protocol/RpcProtocol.java
+41
-0
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/serializer/ProtoStuffSerializer.java
...dolphinscheduler/rpc/serializer/ProtoStuffSerializer.java
+62
-0
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/serializer/ProtoStuffUtils.java
...ache/dolphinscheduler/rpc/serializer/ProtoStuffUtils.java
+1
-1
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/serializer/RpcSerializer.java
...apache/dolphinscheduler/rpc/serializer/RpcSerializer.java
+45
-0
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/serializer/Serializer.java
...rg/apache/dolphinscheduler/rpc/serializer/Serializer.java
+28
-0
未找到文件。
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/client/ConsumerInterceptor.java
浏览文件 @
0f622845
...
...
@@ -40,7 +40,7 @@ public class ConsumerInterceptor {
private
NettyClient
nettyClient
=
NettyClient
.
getInstance
();
public
ConsumerInterceptor
(
Host
host
)
{
ConsumerInterceptor
(
Host
host
)
{
this
.
host
=
host
;
}
...
...
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/codec/NettyDecoder.java
浏览文件 @
0f622845
...
...
@@ -17,7 +17,9 @@
package
org.apache.dolphinscheduler.rpc.codec
;
import
org.apache.dolphinscheduler.remote.serialize.ProtoStuffUtils
;
import
org.apache.dolphinscheduler.rpc.serializer.ProtoStuffUtils
;
import
org.apache.dolphinscheduler.rpc.serializer.RpcSerializer
;
import
org.apache.dolphinscheduler.rpc.serializer.Serializer
;
import
java.util.List
;
...
...
@@ -49,9 +51,12 @@ public class NettyDecoder extends ByteToMessageDecoder {
if
(
byteBuf
.
readableBytes
()
<
dataLength
)
{
byteBuf
.
resetReaderIndex
();
}
byte
serializerType
=
1
;
byte
[]
data
=
new
byte
[
dataLength
];
byteBuf
.
readBytes
(
data
);
Object
obj
=
ProtoStuffUtils
.
deserialize
(
data
,
genericClass
);
Serializer
serializer
=
RpcSerializer
.
getSerializerByType
(
serializerType
);
Object
obj
=
serializer
.
deserialize
(
data
,
genericClass
);
list
.
add
(
obj
);
}
}
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/codec/NettyEncoder.java
浏览文件 @
0f622845
...
...
@@ -17,7 +17,7 @@
package
org.apache.dolphinscheduler.rpc.codec
;
import
org.apache.dolphinscheduler.r
emote.serialize
.ProtoStuffUtils
;
import
org.apache.dolphinscheduler.r
pc.serializer
.ProtoStuffUtils
;
import
io.netty.buffer.ByteBuf
;
import
io.netty.channel.ChannelHandlerContext
;
...
...
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/protocol/MessageHeader.java
0 → 100644
浏览文件 @
0f622845
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package
org.apache.dolphinscheduler.rpc.protocol
;
public
class
MessageHeader
{
private
byte
magic
=(
byte
)
0xbabe
;
/**
* context length
*/
private
int
contextLength
;
/**
* context
*/
private
byte
[]
context
;
private
String
requestId
;
private
byte
type
;
private
byte
status
;
private
byte
serialization
;
public
int
getContextLength
()
{
return
contextLength
;
}
public
void
setContextLength
(
int
contextLength
)
{
this
.
contextLength
=
contextLength
;
}
public
byte
[]
getContext
()
{
return
context
;
}
public
void
setContext
(
byte
[]
context
)
{
this
.
context
=
context
;
}
public
String
getRequestId
()
{
return
requestId
;
}
public
void
setRequestId
(
String
requestId
)
{
this
.
requestId
=
requestId
;
}
public
byte
getType
()
{
return
type
;
}
public
void
setType
(
byte
type
)
{
this
.
type
=
type
;
}
public
byte
getStatus
()
{
return
status
;
}
public
void
setStatus
(
byte
status
)
{
this
.
status
=
status
;
}
public
byte
getSerialization
()
{
return
serialization
;
}
public
void
setSerialization
(
byte
serialization
)
{
this
.
serialization
=
serialization
;
}
public
byte
getMagic
()
{
return
magic
;
}
}
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/protocol/RpcProtocol.java
0 → 100644
浏览文件 @
0f622845
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package
org.apache.dolphinscheduler.rpc.protocol
;
public
class
RpcProtocol
<
T
>{
private
MessageHeader
msgHeader
;
private
T
body
;
public
MessageHeader
getMsgHeader
()
{
return
msgHeader
;
}
public
void
setMsgHeader
(
MessageHeader
msgHeader
)
{
this
.
msgHeader
=
msgHeader
;
}
public
T
getBody
()
{
return
body
;
}
public
void
setBody
(
T
body
)
{
this
.
body
=
body
;
}
}
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/serializer/ProtoStuffSerializer.java
0 → 100644
浏览文件 @
0f622845
package
org.apache.dolphinscheduler.rpc.serializer
;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
import
java.io.IOException
;
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
;
public
class
ProtoStuffSerializer
implements
Serializer
{
private
static
LinkedBuffer
buffer
=
LinkedBuffer
.
allocate
(
LinkedBuffer
.
DEFAULT_BUFFER_SIZE
);
private
static
Map
<
Class
<?>,
Schema
<?>>
schemaCache
=
new
ConcurrentHashMap
<>();
@SuppressWarnings
(
"unchecked"
)
private
static
<
T
>
Schema
<
T
>
getSchema
(
Class
<
T
>
clazz
)
{
return
(
Schema
<
T
>)
schemaCache
.
computeIfAbsent
(
clazz
,
RuntimeSchema:
:
createFrom
);
}
@Override
public
<
T
>
byte
[]
serialize
(
T
obj
)
throws
IOException
{
Class
<
T
>
clazz
=
(
Class
<
T
>)
obj
.
getClass
();
Schema
<
T
>
schema
=
getSchema
(
clazz
);
byte
[]
data
;
try
{
data
=
ProtostuffIOUtil
.
toByteArray
(
obj
,
schema
,
buffer
);
}
finally
{
buffer
.
clear
();
}
return
data
;
}
@Override
public
<
T
>
T
deserialize
(
byte
[]
data
,
Class
<
T
>
clz
)
throws
IOException
{
Schema
<
T
>
schema
=
getSchema
(
clz
);
T
obj
=
schema
.
newMessage
();
if
(
null
==
obj
)
{
return
null
;
}
ProtostuffIOUtil
.
mergeFrom
(
data
,
obj
,
schema
);
return
obj
;
}
}
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/r
emote/serialize
/ProtoStuffUtils.java
→
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/r
pc/serializer
/ProtoStuffUtils.java
浏览文件 @
0f622845
...
...
@@ -15,7 +15,7 @@
* limitations under the License.
*/
package
org.apache.dolphinscheduler.r
emote.serialize
;
package
org.apache.dolphinscheduler.r
pc.serializer
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/serializer/RpcSerializer.java
0 → 100644
浏览文件 @
0f622845
package
org.apache.dolphinscheduler.rpc.serializer
;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
import
java.util.HashMap
;
public
enum
RpcSerializer
{
PROTOSTUFF
((
byte
)
1
,
new
ProtoStuffSerializer
());
byte
type
;
Serializer
serializer
;
RpcSerializer
(
byte
type
,
Serializer
serializer
)
{
this
.
type
=
type
;
this
.
serializer
=
serializer
;
}
private
static
HashMap
<
Byte
,
Serializer
>
SERIALIZERS_MAP
=
new
HashMap
<>();
static
{
for
(
RpcSerializer
rpcSerializer
:
RpcSerializer
.
values
())
{
SERIALIZERS_MAP
.
put
(
rpcSerializer
.
type
,
rpcSerializer
.
serializer
);
}
}
public
static
Serializer
getSerializerByType
(
byte
type
)
{
return
SERIALIZERS_MAP
.
get
(
type
);
}
}
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/serializer/Serializer.java
0 → 100644
浏览文件 @
0f622845
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package
org.apache.dolphinscheduler.rpc.serializer
;
import
java.io.IOException
;
public
interface
Serializer
{
<
T
>
byte
[]
serialize
(
T
obj
)
throws
IOException
;
<
T
>
T
deserialize
(
byte
[]
data
,
Class
<
T
>
clz
)
throws
IOException
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录