Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
Rocketmq
提交
6ae619c4
R
Rocketmq
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
Rocketmq
与 Fork 源项目一致
Fork自
Apache RocketMQ / Rocketmq
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rocketmq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
6ae619c4
编写于
7月 14, 2018
作者:
J
Jaskey
提交者:
von gosling
7月 14, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Invoke callback at once when channel is close (#95)
上级
b75af6b0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
53 addition
and
22 deletion
+53
-22
client/src/test/java/org/apache/rocketmq/client/impl/MQClientAPIImplTest.java
.../org/apache/rocketmq/client/impl/MQClientAPIImplTest.java
+1
-1
remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingAbstract.java
...apache/rocketmq/remoting/netty/NettyRemotingAbstract.java
+35
-16
remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingClient.java
...g/apache/rocketmq/remoting/netty/NettyRemotingClient.java
+1
-1
remoting/src/main/java/org/apache/rocketmq/remoting/netty/ResponseFuture.java
...va/org/apache/rocketmq/remoting/netty/ResponseFuture.java
+16
-4
未找到文件。
client/src/test/java/org/apache/rocketmq/client/impl/MQClientAPIImplTest.java
浏览文件 @
6ae619c4
...
...
@@ -162,7 +162,7 @@ public class MQClientAPIImplTest {
public
Object
answer
(
InvocationOnMock
mock
)
throws
Throwable
{
InvokeCallback
callback
=
mock
.
getArgument
(
3
);
RemotingCommand
request
=
mock
.
getArgument
(
1
);
ResponseFuture
responseFuture
=
new
ResponseFuture
(
request
.
getOpaque
(),
3
*
1000
,
null
,
null
);
ResponseFuture
responseFuture
=
new
ResponseFuture
(
null
,
request
.
getOpaque
(),
3
*
1000
,
null
,
null
);
responseFuture
.
setResponseCommand
(
createSuccessResponse
(
request
));
callback
.
operationComplete
(
responseFuture
);
return
null
;
...
...
remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingAbstract.java
浏览文件 @
6ae619c4
...
...
@@ -364,7 +364,7 @@ public abstract class NettyRemotingAbstract {
final
int
opaque
=
request
.
getOpaque
();
try
{
final
ResponseFuture
responseFuture
=
new
ResponseFuture
(
opaque
,
timeoutMillis
,
null
,
null
);
final
ResponseFuture
responseFuture
=
new
ResponseFuture
(
channel
,
opaque
,
timeoutMillis
,
null
,
null
);
this
.
responseTable
.
put
(
opaque
,
responseFuture
);
final
SocketAddress
addr
=
channel
.
remoteAddress
();
channel
.
writeAndFlush
(
request
).
addListener
(
new
ChannelFutureListener
()
{
...
...
@@ -407,8 +407,7 @@ public abstract class NettyRemotingAbstract {
boolean
acquired
=
this
.
semaphoreAsync
.
tryAcquire
(
timeoutMillis
,
TimeUnit
.
MILLISECONDS
);
if
(
acquired
)
{
final
SemaphoreReleaseOnlyOnce
once
=
new
SemaphoreReleaseOnlyOnce
(
this
.
semaphoreAsync
);
final
ResponseFuture
responseFuture
=
new
ResponseFuture
(
opaque
,
timeoutMillis
,
invokeCallback
,
once
);
final
ResponseFuture
responseFuture
=
new
ResponseFuture
(
channel
,
opaque
,
timeoutMillis
,
invokeCallback
,
once
);
this
.
responseTable
.
put
(
opaque
,
responseFuture
);
try
{
channel
.
writeAndFlush
(
request
).
addListener
(
new
ChannelFutureListener
()
{
...
...
@@ -417,20 +416,8 @@ public abstract class NettyRemotingAbstract {
if
(
f
.
isSuccess
())
{
responseFuture
.
setSendRequestOK
(
true
);
return
;
}
else
{
responseFuture
.
setSendRequestOK
(
false
);
}
responseFuture
.
putResponse
(
null
);
responseTable
.
remove
(
opaque
);
try
{
executeInvokeCallback
(
responseFuture
);
}
catch
(
Throwable
e
)
{
log
.
warn
(
"excute callback in writeAndFlush addListener, and callback throw"
,
e
);
}
finally
{
responseFuture
.
release
();
}
requestFail
(
opaque
);
log
.
warn
(
"send a request command to channel <{}> failed."
,
RemotingHelper
.
parseChannelRemoteAddr
(
channel
));
}
});
...
...
@@ -455,6 +442,38 @@ public abstract class NettyRemotingAbstract {
}
}
private
void
requestFail
(
final
int
opaque
)
{
ResponseFuture
responseFuture
=
responseTable
.
remove
(
opaque
);
if
(
responseFuture
!=
null
)
{
responseFuture
.
setSendRequestOK
(
false
);
responseFuture
.
putResponse
(
null
);
try
{
executeInvokeCallback
(
responseFuture
);
}
catch
(
Throwable
e
)
{
log
.
warn
(
"execute callback in requestFail, and callback throw"
,
e
);
}
finally
{
responseFuture
.
release
();
}
}
}
/**
* mark the request of the specified channel as fail and to invoke fail callback immediately
* @param channel the channel which is close already
*/
protected
void
failFast
(
final
Channel
channel
)
{
Iterator
<
Entry
<
Integer
,
ResponseFuture
>>
it
=
responseTable
.
entrySet
().
iterator
();
while
(
it
.
hasNext
())
{
Entry
<
Integer
,
ResponseFuture
>
entry
=
it
.
next
();
if
(
entry
.
getValue
().
getProcessChannel
()
==
channel
)
{
Integer
opaque
=
entry
.
getKey
();
if
(
opaque
!=
null
)
{
requestFail
(
opaque
);
}
}
}
}
public
void
invokeOnewayImpl
(
final
Channel
channel
,
final
RemotingCommand
request
,
final
long
timeoutMillis
)
throws
InterruptedException
,
RemotingTooMuchRequestException
,
RemotingTimeoutException
,
RemotingSendRequestException
{
request
.
markOnewayRPC
();
...
...
remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingClient.java
浏览文件 @
6ae619c4
...
...
@@ -660,7 +660,7 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti
log
.
info
(
"NETTY CLIENT PIPELINE: CLOSE {}"
,
remoteAddress
);
closeChannel
(
ctx
.
channel
());
super
.
close
(
ctx
,
promise
);
NettyRemotingClient
.
this
.
failFast
(
ctx
.
channel
());
if
(
NettyRemotingClient
.
this
.
channelEventListener
!=
null
)
{
NettyRemotingClient
.
this
.
putNettyEvent
(
new
NettyEvent
(
NettyEventType
.
CLOSE
,
remoteAddress
,
ctx
.
channel
()));
}
...
...
remoting/src/main/java/org/apache/rocketmq/remoting/netty/ResponseFuture.java
浏览文件 @
6ae619c4
...
...
@@ -16,6 +16,7 @@
*/
package
org.apache.rocketmq.remoting.netty
;
import
io.netty.channel.Channel
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicBoolean
;
...
...
@@ -25,6 +26,7 @@ import org.apache.rocketmq.remoting.protocol.RemotingCommand;
public
class
ResponseFuture
{
private
final
int
opaque
;
private
final
Channel
processChannel
;
private
final
long
timeoutMillis
;
private
final
InvokeCallback
invokeCallback
;
private
final
long
beginTimestamp
=
System
.
currentTimeMillis
();
...
...
@@ -37,9 +39,10 @@ public class ResponseFuture {
private
volatile
boolean
sendRequestOK
=
true
;
private
volatile
Throwable
cause
;
public
ResponseFuture
(
int
opaque
,
long
timeoutMillis
,
InvokeCallback
invokeCallback
,
public
ResponseFuture
(
Channel
channel
,
int
opaque
,
long
timeoutMillis
,
InvokeCallback
invokeCallback
,
SemaphoreReleaseOnlyOnce
once
)
{
this
.
opaque
=
opaque
;
this
.
processChannel
=
channel
;
this
.
timeoutMillis
=
timeoutMillis
;
this
.
invokeCallback
=
invokeCallback
;
this
.
once
=
once
;
...
...
@@ -114,11 +117,20 @@ public class ResponseFuture {
return
opaque
;
}
public
Channel
getProcessChannel
()
{
return
processChannel
;
}
@Override
public
String
toString
()
{
return
"ResponseFuture [responseCommand="
+
responseCommand
+
", sendRequestOK="
+
sendRequestOK
+
", cause="
+
cause
+
", opaque="
+
opaque
+
", timeoutMillis="
+
timeoutMillis
+
", invokeCallback="
+
invokeCallback
+
", beginTimestamp="
+
beginTimestamp
return
"ResponseFuture [responseCommand="
+
responseCommand
+
", sendRequestOK="
+
sendRequestOK
+
", cause="
+
cause
+
", opaque="
+
opaque
+
", processChannel="
+
processChannel
+
", timeoutMillis="
+
timeoutMillis
+
", invokeCallback="
+
invokeCallback
+
", beginTimestamp="
+
beginTimestamp
+
", countDownLatch="
+
countDownLatch
+
"]"
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录