jack870131 commented on a change in pull request #2169: URL: https://github.com/apache/rocketmq/pull/2169#discussion_r459445005
########## File path: broker/src/main/java/org/apache/rocketmq/broker/processor/AllocateMessageQueueProcessor.java ########## @@ -0,0 +1,129 @@ +/* + * 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.rocketmq.broker.processor; + +import io.netty.channel.ChannelHandlerContext; +import java.util.List; +import org.apache.rocketmq.broker.BrokerController; +import org.apache.rocketmq.common.AllocateMessageQueueStrategy; +import org.apache.rocketmq.common.constant.LoggerName; +import org.apache.rocketmq.common.message.MessageQueue; +import org.apache.rocketmq.common.protocol.RequestCode; +import org.apache.rocketmq.common.protocol.ResponseCode; +import org.apache.rocketmq.common.protocol.body.AllocateMessageQueueRequestBody; +import org.apache.rocketmq.common.protocol.header.AllocateMessageQueueRequestHeader; +import org.apache.rocketmq.common.protocol.header.AllocateMessageQueueResponseBody; +import org.apache.rocketmq.common.protocol.header.AllocateMessageQueueResponseHeader; +import org.apache.rocketmq.common.rebalance.AllocateMachineRoomNearby; +import org.apache.rocketmq.common.rebalance.AllocateMessageQueueAveragely; +import org.apache.rocketmq.common.rebalance.AllocateMessageQueueAveragelyByCircle; +import org.apache.rocketmq.common.rebalance.AllocateMessageQueueByConfig; +import org.apache.rocketmq.common.rebalance.AllocateMessageQueueByMachineRoom; +import org.apache.rocketmq.common.rebalance.AllocateMessageQueueConsistentHash; +import org.apache.rocketmq.logging.InternalLogger; +import org.apache.rocketmq.logging.InternalLoggerFactory; +import org.apache.rocketmq.remoting.exception.RemotingCommandException; +import org.apache.rocketmq.remoting.netty.NettyRequestProcessor; +import org.apache.rocketmq.remoting.protocol.RemotingCommand; + +public class AllocateMessageQueueProcessor implements NettyRequestProcessor { + private static final InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME); + + private final BrokerController brokerController; + + public AllocateMessageQueueProcessor(final BrokerController brokerController) { + this.brokerController = brokerController; + } + + @Override + public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) + throws RemotingCommandException { + switch (request.getCode()) { + case RequestCode.ALLOCATE_MESSAGE_QUEUE: + return this.allocateMessageQueue(ctx, request); + default: + break; + } + return null; + } + + private RemotingCommand allocateMessageQueue(ChannelHandlerContext ctx, RemotingCommand request) + throws RemotingCommandException { + final RemotingCommand response = + RemotingCommand.createResponseCommand(AllocateMessageQueueResponseHeader.class); + final AllocateMessageQueueRequestHeader requestHeader = + (AllocateMessageQueueRequestHeader) request.decodeCommandCustomHeader(AllocateMessageQueueRequestHeader.class); + final AllocateMessageQueueRequestBody requestBody = AllocateMessageQueueRequestBody.decode(request.getBody(), + AllocateMessageQueueRequestBody.class); + + AllocateMessageQueueStrategy strategy = null; + String strategyName = requestHeader.getStrategyName(); Review comment: Updated. I had added the try/catch statement for the strategy.allocate() method, which could enhance the consistency here. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
