forked from chenld/RocketMQ
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bae9f3c
commit 2477c5a
Showing
1 changed file
with
10 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,8 @@ | |
/** | ||
* 平均分配队列算法 | ||
* | ||
* @author shijia.wxr<[email protected]> | ||
* @author fuchong<[email protected]> | ||
* @author manhong.yqd<[email protected]> | ||
* @since 2013-7-24 | ||
*/ | ||
public class AllocateMessageQueueAveragely implements AllocateMessageQueueStrategy { | ||
|
@@ -46,14 +47,14 @@ public List<MessageQueue> allocate(String currentCID, List<MessageQueue> mqAll, | |
return result; | ||
} | ||
|
||
int index = cidAll.indexOf(currentCID); | ||
int averageSize = (mqAll.size() <= cidAll.size()) ? 1 : mqAll.size() / cidAll.size(); | ||
int mod = mqAll.size() % cidAll.size(); | ||
int startIndex = index * averageSize; | ||
int endIndex = Math.min((index + 1) * averageSize, mqAll.size()); | ||
for (int i = startIndex; i < endIndex; i++) { | ||
result.add(mqAll.get(i % mqAll.size())); | ||
} | ||
int index = cidAll.indexOf(currentCID); | ||
int averageSize = (mqAll.size() <= cidAll.size()) ? 1 : mqAll.size() / cidAll.size(); | ||
int mod = mqAll.size() % cidAll.size(); | ||
int startIndex = index * averageSize; | ||
int endIndex = Math.min((index + 1) * averageSize, mqAll.size()); | ||
for (int i = startIndex; i < endIndex; i++) { | ||
result.add(mqAll.get(i % mqAll.size())); | ||
} | ||
|
||
// 如果当前的consumerId最后一个且还有剩下的队列,应该把最后队列都放到当前consumerId队列里 | ||
boolean isAddRemainQueue = (index == cidAll.size() - 1) && mod > 0; | ||
|