Skip to content

Commit

Permalink
#4 修改样式,增加作者信息
Browse files Browse the repository at this point in the history
  • Loading branch information
vintagewang committed Jul 30, 2013
1 parent bae9f3c commit 2477c5a
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down

0 comments on commit 2477c5a

Please sign in to comment.