提交 b13a4c86 编写于 作者: H huangli

[ISSUE 2883] [Part G] Optimise parse performance for SendMessageRequestHeaderV2

上级 3183122c
...@@ -19,8 +19,10 @@ package org.apache.rocketmq.broker.processor; ...@@ -19,8 +19,10 @@ package org.apache.rocketmq.broker.processor;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Random; import java.util.Random;
import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.broker.BrokerController;
import org.apache.rocketmq.broker.mqtrace.SendMessageContext; import org.apache.rocketmq.broker.mqtrace.SendMessageContext;
...@@ -288,9 +290,7 @@ public abstract class AbstractSendMessageProcessor extends AsyncNettyRequestProc ...@@ -288,9 +290,7 @@ public abstract class AbstractSendMessageProcessor extends AsyncNettyRequestProc
switch (request.getCode()) { switch (request.getCode()) {
case RequestCode.SEND_BATCH_MESSAGE: case RequestCode.SEND_BATCH_MESSAGE:
case RequestCode.SEND_MESSAGE_V2: case RequestCode.SEND_MESSAGE_V2:
requestHeaderV2 = requestHeaderV2 = decodeSendMessageHeaderV2(request);
(SendMessageRequestHeaderV2) request
.decodeCommandCustomHeader(SendMessageRequestHeaderV2.class);
case RequestCode.SEND_MESSAGE: case RequestCode.SEND_MESSAGE:
if (null == requestHeaderV2) { if (null == requestHeaderV2) {
requestHeader = requestHeader =
...@@ -305,6 +305,73 @@ public abstract class AbstractSendMessageProcessor extends AsyncNettyRequestProc ...@@ -305,6 +305,73 @@ public abstract class AbstractSendMessageProcessor extends AsyncNettyRequestProc
return requestHeader; return requestHeader;
} }
private SendMessageRequestHeaderV2 decodeSendMessageHeaderV2(RemotingCommand request) {
SendMessageRequestHeaderV2 r = new SendMessageRequestHeaderV2();
HashMap<String, String> fields = request.getExtFields();
if (fields == null) {
// keep same behavior with CommandCustomHeader.decodeCommandCustomHeader
return r;
}
String s = fields.get("a");
Objects.requireNonNull(s, "the custom field <a> is null");
r.setA(s);
s = fields.get("b");
Objects.requireNonNull(s, "the custom field <b> is null");
r.setB(s);
s = fields.get("c");
Objects.requireNonNull(s, "the custom field <c> is null");
r.setC(s);
s = fields.get("d");
Objects.requireNonNull(s, "the custom field <d> is null");
r.setD(Integer.parseInt(s));
s = fields.get("e");
Objects.requireNonNull(s, "the custom field <e> is null");
r.setE(Integer.parseInt(s));
s = fields.get("f");
Objects.requireNonNull(s, "the custom field <f> is null");
r.setF(Integer.parseInt(s));
s = fields.get("g");
Objects.requireNonNull(s, "the custom field <g> is null");
r.setG(Long.parseLong(s));
s = fields.get("h");
Objects.requireNonNull(s, "the custom field <h> is null");
r.setH(Integer.parseInt(s));
s = fields.get("i");
if (s != null) {
r.setI(s);
}
s = fields.get("j");
if (s != null) {
r.setJ(Integer.parseInt(s));
}
s = fields.get("k");
if (s != null) {
r.setK(Boolean.parseBoolean(s));
}
s = fields.get("l");
if (s != null) {
r.setL(Integer.parseInt(s));
}
s = fields.get("m");
if (s != null) {
r.setM(Boolean.parseBoolean(s));
}
return r;
}
public void executeSendMessageHookAfter(final RemotingCommand response, final SendMessageContext context) { public void executeSendMessageHookAfter(final RemotingCommand response, final SendMessageContext context) {
if (hasSendMessageHook()) { if (hasSendMessageHook()) {
for (SendMessageHook hook : this.sendMessageHookList) { for (SendMessageHook hook : this.sendMessageHookList) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册