Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #8328] Fix map init #8329

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.rocketmq.proxy.remoting.pipeline.RequestPipeline;
import org.apache.rocketmq.remoting.netty.NettyRequestProcessor;
import org.apache.rocketmq.remoting.protocol.RemotingCommand;
import org.apache.rocketmq.remoting.protocol.RemotingSysResponseCode;
import org.apache.rocketmq.remoting.protocol.RequestCode;
import org.apache.rocketmq.remoting.protocol.ResponseCode;

Expand All @@ -45,14 +46,13 @@ public abstract class AbstractRemotingActivity implements NettyRequestProcessor
protected final MessagingProcessor messagingProcessor;
protected static final String BROKER_NAME_FIELD = "bname";
protected static final String BROKER_NAME_FIELD_FOR_SEND_MESSAGE_V2 = "n";
private static final Map<ProxyExceptionCode, Integer> PROXY_EXCEPTION_RESPONSE_CODE_MAP = new HashMap<ProxyExceptionCode, Integer>() {
{
put(ProxyExceptionCode.FORBIDDEN, ResponseCode.NO_PERMISSION);
put(ProxyExceptionCode.MESSAGE_PROPERTY_CONFLICT_WITH_TYPE, ResponseCode.MESSAGE_ILLEGAL);
put(ProxyExceptionCode.INTERNAL_SERVER_ERROR, ResponseCode.SYSTEM_ERROR);
put(ProxyExceptionCode.TRANSACTION_DATA_NOT_FOUND, ResponseCode.SUCCESS);
}
};
private static final Map<ProxyExceptionCode, Integer> PROXY_EXCEPTION_RESPONSE_CODE_MAP = new HashMap<>(8);
static {
PROXY_EXCEPTION_RESPONSE_CODE_MAP.put(ProxyExceptionCode.FORBIDDEN, ResponseCode.NO_PERMISSION);
PROXY_EXCEPTION_RESPONSE_CODE_MAP.put(ProxyExceptionCode.MESSAGE_PROPERTY_CONFLICT_WITH_TYPE, ResponseCode.MESSAGE_ILLEGAL);
PROXY_EXCEPTION_RESPONSE_CODE_MAP.put(ProxyExceptionCode.INTERNAL_SERVER_ERROR, RemotingSysResponseCode.SYSTEM_ERROR);
PROXY_EXCEPTION_RESPONSE_CODE_MAP.put(ProxyExceptionCode.TRANSACTION_DATA_NOT_FOUND, RemotingSysResponseCode.SUCCESS);
}
protected final RequestPipeline requestPipeline;

public AbstractRemotingActivity(RequestPipeline requestPipeline, MessagingProcessor messagingProcessor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,31 @@ public class RemotingHelper {

private static final Logger log = LoggerFactory.getLogger(LoggerName.ROCKETMQ_REMOTING_NAME);

public static final Map<Integer, String> REQUEST_CODE_MAP = new HashMap<Integer, String>() {
{
try {
Field[] f = RequestCode.class.getFields();
for (Field field : f) {
if (field.getType() == int.class) {
put((int) field.get(null), field.getName().toLowerCase());
}
public static final Map<Integer, String> REQUEST_CODE_MAP = new HashMap<>(256) ;

public static final Map<Integer, String> RESPONSE_CODE_MAP = new HashMap<>(128);

static {
try {
Field[] f = RequestCode.class.getFields();
for (Field field : f) {
if (field.getType() == int.class) {
REQUEST_CODE_MAP.put((int) field.get(null), field.getName().toLowerCase());
}
} catch (IllegalAccessException ignore) {
}
} catch (IllegalAccessException ignore) {
}
};

public static final Map<Integer, String> RESPONSE_CODE_MAP = new HashMap<Integer, String>() {
{
try {
Field[] f = ResponseCode.class.getFields();
for (Field field : f) {
if (field.getType() == int.class) {
put((int) field.get(null), field.getName().toLowerCase());
}
try {
Field[] f = ResponseCode.class.getFields();
for (Field field : f) {
if (field.getType() == int.class) {
RESPONSE_CODE_MAP.put((int) field.get(null), field.getName().toLowerCase());
}
} catch (IllegalAccessException ignore) {
}
} catch (IllegalAccessException ignore) {
}
};
}

public static <T> T getAttributeValue(AttributeKey<T> key, final Channel channel) {
if (channel.hasAttr(key)) {
Expand Down
Loading