Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
touzizhuo03
Dubbo
提交
b575549c
D
Dubbo
项目概览
touzizhuo03
/
Dubbo
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Dubbo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
b575549c
编写于
6月 30, 2012
作者:
K
kimi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
DUBBO-424 Heartbeat response不应该在业务线程处理
上级
215e1405
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
233 addition
and
147 deletion
+233
-147
dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/support/header/HeaderExchangeHandler.java
...moting/exchange/support/header/HeaderExchangeHandler.java
+2
-2
dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/support/header/HeartbeatHandler.java
...bo/remoting/exchange/support/header/HeartbeatHandler.java
+123
-1
dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispather/ChannelHandlers.java
...a/dubbo/remoting/transport/dispather/ChannelHandlers.java
+34
-18
dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispather/WrappedChannelHandler.java
...o/remoting/transport/dispather/WrappedChannelHandler.java
+0
-16
dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispather/all/AllChannelHandler.java
...o/remoting/transport/dispather/all/AllChannelHandler.java
+5
-14
dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispather/connection/ConnectionOrderedChannelHandler.java
...dispather/connection/ConnectionOrderedChannelHandler.java
+7
-17
dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispather/execution/ExecutionChannelHandler.java
...ransport/dispather/execution/ExecutionChannelHandler.java
+1
-10
dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispather/message/MessageOnlyChannelHandler.java
...ransport/dispather/message/MessageOnlyChannelHandler.java
+7
-17
dubbo-remoting/dubbo-remoting-api/src/test/java/com/alibaba/dubbo/remoting/handler/ConnectChannelHandlerTest.java
...aba/dubbo/remoting/handler/ConnectChannelHandlerTest.java
+54
-52
未找到文件。
dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/support/header/HeaderExchangeHandler.java
浏览文件 @
b575549c
...
...
@@ -44,9 +44,9 @@ public class HeaderExchangeHandler implements ChannelHandlerDelegate {
protected
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
HeaderExchangeHandler
.
class
);
public
static
String
KEY_READ_TIMESTAMP
=
"READ_TIMESTAMP"
;
public
static
String
KEY_READ_TIMESTAMP
=
HeartbeatHandler
.
KEY_READ_TIMESTAMP
;
public
static
String
KEY_WRITE_TIMESTAMP
=
"WRITE_TIMESTAMP"
;
public
static
String
KEY_WRITE_TIMESTAMP
=
HeartbeatHandler
.
KEY_WRITE_TIMESTAMP
;
private
final
ExchangeHandler
handler
;
...
...
dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/exchange/support/header/HeartbeatHandler.java
浏览文件 @
b575549c
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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.
*/
package
com.alibaba.dubbo.remoting.exchange.support.header
;
import
com.alibaba.dubbo.common.logger.Logger
;
import
com.alibaba.dubbo.common.logger.LoggerFactory
;
import
com.alibaba.dubbo.remoting.Channel
;
import
com.alibaba.dubbo.remoting.ChannelHandler
;
import
com.alibaba.dubbo.remoting.RemotingException
;
import
com.alibaba.dubbo.remoting.exchange.Request
;
import
com.alibaba.dubbo.remoting.exchange.Response
;
import
com.alibaba.dubbo.remoting.transport.ChannelHandlerDelegate
;
/**
* @author <a href="mailto:gang.lvg@alibaba-inc.com">kimi</a>
*/
public
class
HeartbeatHandler
{
public
class
HeartbeatHandler
implements
ChannelHandlerDelegate
{
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
HeartbeatHandler
.
class
);
public
static
String
KEY_READ_TIMESTAMP
=
"READ_TIMESTAMP"
;
public
static
String
KEY_WRITE_TIMESTAMP
=
"WRITE_TIMESTAMP"
;
private
ChannelHandler
handler
;
public
HeartbeatHandler
(
ChannelHandler
handler
)
{
if
(
handler
==
null
)
{
throw
new
IllegalArgumentException
(
"handler == null"
);
}
this
.
handler
=
handler
;
}
public
ChannelHandler
getHandler
()
{
if
(
handler
instanceof
ChannelHandlerDelegate
)
{
return
((
ChannelHandlerDelegate
)
handler
).
getHandler
();
}
return
handler
;
}
public
void
connected
(
Channel
channel
)
throws
RemotingException
{
setReadTimestamp
(
channel
);
setWriteTimestamp
(
channel
);
handler
.
connected
(
channel
);
}
public
void
disconnected
(
Channel
channel
)
throws
RemotingException
{
clearReadTimestamp
(
channel
);
clearWriteTimestamp
(
channel
);
handler
.
disconnected
(
channel
);
}
public
void
sent
(
Channel
channel
,
Object
message
)
throws
RemotingException
{
setWriteTimestamp
(
channel
);
handler
.
sent
(
channel
,
message
);
}
public
void
received
(
Channel
channel
,
Object
message
)
throws
RemotingException
{
setReadTimestamp
(
channel
);
if
(
isHeartbeatRequest
(
message
))
{
Request
req
=
(
Request
)
message
;
if
(
req
.
isTwoWay
())
{
Response
res
=
new
Response
(
req
.
getId
(),
req
.
getVersion
());
res
.
setEvent
(
Response
.
HEARTBEAT_EVENT
);
channel
.
send
(
res
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
new
StringBuilder
(
32
)
.
append
(
"Receive heartbeat request and send heartbeat in thread "
)
.
append
(
Thread
.
currentThread
().
getName
())
.
toString
());
}
}
return
;
}
if
(
isHeartbeatResponse
(
message
))
{
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
new
StringBuilder
(
32
)
.
append
(
"Receive heartbeat response in thread "
)
.
append
(
Thread
.
currentThread
().
getName
())
.
toString
());
}
return
;
}
handler
.
received
(
channel
,
message
);
}
public
void
caught
(
Channel
channel
,
Throwable
exception
)
throws
RemotingException
{
handler
.
caught
(
channel
,
exception
);
}
private
void
setReadTimestamp
(
Channel
channel
)
{
channel
.
setAttribute
(
KEY_READ_TIMESTAMP
,
System
.
currentTimeMillis
());
}
private
void
setWriteTimestamp
(
Channel
channel
)
{
channel
.
setAttribute
(
KEY_WRITE_TIMESTAMP
,
System
.
currentTimeMillis
());
}
private
void
clearReadTimestamp
(
Channel
channel
)
{
channel
.
removeAttribute
(
KEY_READ_TIMESTAMP
);
}
private
void
clearWriteTimestamp
(
Channel
channel
)
{
channel
.
removeAttribute
(
KEY_WRITE_TIMESTAMP
);
}
private
boolean
isHeartbeatRequest
(
Object
message
)
{
return
message
instanceof
Request
&&
((
Request
)
message
).
isHeartbeat
();
}
private
boolean
isHeartbeatResponse
(
Object
message
)
{
return
message
instanceof
Response
&&
((
Response
)
message
).
isHeartbeat
();
}
}
dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispather/ChannelHandlers.java
浏览文件 @
b575549c
...
...
@@ -20,6 +20,7 @@ import com.alibaba.dubbo.common.URL;
import
com.alibaba.dubbo.common.extension.ExtensionLoader
;
import
com.alibaba.dubbo.remoting.ChannelHandler
;
import
com.alibaba.dubbo.remoting.Dispather
;
import
com.alibaba.dubbo.remoting.exchange.support.header.HeartbeatHandler
;
/**
* @author chao.liuc
...
...
@@ -28,8 +29,23 @@ import com.alibaba.dubbo.remoting.Dispather;
public
class
ChannelHandlers
{
public
static
ChannelHandler
wrap
(
ChannelHandler
handler
,
URL
url
){
return
ExtensionLoader
.
getExtensionLoader
(
Dispather
.
class
)
.
getAdaptiveExtension
().
dispath
(
handler
,
url
);
return
ChannelHandlers
.
getInstance
().
wrapInternal
(
handler
,
url
);
}
protected
ChannelHandlers
()
{}
protected
ChannelHandler
wrapInternal
(
ChannelHandler
handler
,
URL
url
)
{
return
new
HeartbeatHandler
(
ExtensionLoader
.
getExtensionLoader
(
Dispather
.
class
)
.
getAdaptiveExtension
().
dispath
(
handler
,
url
));
}
private
static
ChannelHandlers
INSTANCE
=
new
ChannelHandlers
();
protected
static
ChannelHandlers
getInstance
()
{
return
INSTANCE
;
}
static
void
setTestingChannelHandlers
(
ChannelHandlers
instance
)
{
INSTANCE
=
instance
;
}
}
\ No newline at end of file
dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispather/WrappedChannelHandler.java
浏览文件 @
b575549c
...
...
@@ -74,14 +74,6 @@ public class WrappedChannelHandler implements ChannelHandlerDelegate {
@SuppressWarnings
(
"deprecation"
)
public
void
received
(
Channel
channel
,
Object
message
)
throws
RemotingException
{
if
(
message
instanceof
Request
&&
((
Request
)
message
).
isHeartbeat
()){
Request
req
=
(
Request
)
message
;
if
(
req
.
isTwoWay
()){
Response
res
=
new
Response
(
req
.
getId
(),
req
.
getVersion
());
res
.
setHeartbeat
(
true
);
channel
.
send
(
res
);
}
}
handler
.
received
(
channel
,
message
);
}
...
...
@@ -105,12 +97,4 @@ public class WrappedChannelHandler implements ChannelHandlerDelegate {
return
url
;
}
protected
final
boolean
isHeartbeatResponse
(
Object
message
)
{
return
(
message
instanceof
Response
)
&&
((
Response
)
message
).
isHeartbeat
();
}
protected
void
setReadTimestamp
(
Channel
channel
)
{
channel
.
setAttribute
(
HeaderExchangeHandler
.
KEY_READ_TIMESTAMP
,
System
.
currentTimeMillis
());
}
}
\ No newline at end of file
dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispather/all/AllChannelHandler.java
浏览文件 @
b575549c
...
...
@@ -52,21 +52,12 @@ public class AllChannelHandler extends WrappedChannelHandler {
}
public
void
received
(
Channel
channel
,
Object
message
)
throws
RemotingException
{
//FIXME 包的依赖顺序有问题
if
(
message
instanceof
Request
&&
((
Request
)
message
).
isEvent
()){
super
.
received
(
channel
,
message
);
return
;
}
if
(!
isHeartbeatResponse
(
message
))
{
ExecutorService
cexecutor
=
getExecutorService
();
try
{
cexecutor
.
execute
(
new
ChannelEventRunnable
(
channel
,
handler
,
ChannelState
.
RECEIVED
,
message
));
}
catch
(
Throwable
t
)
{
throw
new
ExecutionException
(
message
,
channel
,
getClass
()
+
" error when process received event ."
,
t
);
}
}
else
{
setReadTimestamp
(
channel
);
}
}
public
void
caught
(
Channel
channel
,
Throwable
exception
)
throws
RemotingException
{
...
...
dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispather/connection/ConnectionOrderedChannelHandler.java
浏览文件 @
b575549c
...
...
@@ -69,13 +69,6 @@ public class ConnectionOrderedChannelHandler extends WrappedChannelHandler {
}
public
void
received
(
Channel
channel
,
Object
message
)
throws
RemotingException
{
//FIXME 包的依赖顺序有问题
if
(
message
instanceof
Request
&&
((
Request
)
message
).
isEvent
()){
super
.
received
(
channel
,
message
);
return
;
}
if
(!
isHeartbeatResponse
(
message
))
{
ExecutorService
cexecutor
=
executor
;
if
(
cexecutor
==
null
||
cexecutor
.
isShutdown
())
{
cexecutor
=
SHARED_EXECUTOR
;
...
...
@@ -85,9 +78,6 @@ public class ConnectionOrderedChannelHandler extends WrappedChannelHandler {
}
catch
(
Throwable
t
)
{
throw
new
ExecutionException
(
message
,
channel
,
getClass
()
+
" error when process received event ."
,
t
);
}
}
else
{
setReadTimestamp
(
channel
);
}
}
public
void
caught
(
Channel
channel
,
Throwable
exception
)
throws
RemotingException
{
...
...
dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispather/execution/ExecutionChannelHandler.java
浏览文件 @
b575549c
...
...
@@ -39,16 +39,7 @@ public class ExecutionChannelHandler extends WrappedChannelHandler {
}
public
void
received
(
Channel
channel
,
Object
message
)
throws
RemotingException
{
//FIXME 包的依赖顺序有问题
if
(
message
instanceof
Request
&&
((
Request
)
message
).
isEvent
()){
super
.
received
(
channel
,
message
);
return
;
}
if
(!
isHeartbeatResponse
(
message
))
{
executor
.
execute
(
new
ChannelEventRunnable
(
channel
,
handler
,
ChannelState
.
RECEIVED
,
message
));
}
else
{
setReadTimestamp
(
channel
);
}
}
public
void
caught
(
Channel
channel
,
Throwable
exception
)
throws
RemotingException
{
...
...
dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/dispather/message/MessageOnlyChannelHandler.java
浏览文件 @
b575549c
...
...
@@ -34,13 +34,6 @@ public class MessageOnlyChannelHandler extends WrappedChannelHandler {
}
public
void
received
(
Channel
channel
,
Object
message
)
throws
RemotingException
{
//FIXME 包的依赖顺序有问题
if
(
message
instanceof
Request
&&
((
Request
)
message
).
isEvent
()){
super
.
received
(
channel
,
message
);
return
;
}
if
(!
isHeartbeatResponse
(
message
))
{
ExecutorService
cexecutor
=
executor
;
if
(
cexecutor
==
null
||
cexecutor
.
isShutdown
())
{
cexecutor
=
SHARED_EXECUTOR
;
...
...
@@ -50,9 +43,6 @@ public class MessageOnlyChannelHandler extends WrappedChannelHandler {
}
catch
(
Throwable
t
)
{
throw
new
ExecutionException
(
message
,
channel
,
getClass
()
+
" error when process received event ."
,
t
);
}
}
else
{
setReadTimestamp
(
channel
);
}
}
}
\ No newline at end of file
dubbo-remoting/dubbo-remoting-api/src/test/java/com/alibaba/dubbo/remoting/handler/ConnectChannelHandlerTest.java
浏览文件 @
b575549c
...
...
@@ -21,6 +21,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import
junit.framework.Assert
;
import
org.junit.Before
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
com.alibaba.dubbo.remoting.ExecutionException
;
...
...
@@ -111,6 +112,7 @@ public class ConnectChannelHandlerTest extends WrappedChannelHandlerTest{
* 事件不通过线程池,直接在IO上执行
*/
@SuppressWarnings
(
"deprecation"
)
@Ignore
(
"Heartbeat is processed in HeartbeatHandler not WrappedChannelHandler."
)
@Test
public
void
test_Received_Event_invoke_direct
()
throws
RemotingException
{
handler
=
new
ConnectionOrderedChannelHandler
(
new
BizChannelHander
(
false
),
url
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录