Skip to content

Commit

Permalink
Merge pull request #776 from caorong/master
Browse files Browse the repository at this point in the history
fix get channel error every 2.1 billion request
  • Loading branch information
rayzhang0603 authored Dec 3, 2018
2 parents ccb2a66 + a28a038 commit a315054
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void createConnections() {
}

protected Channel getChannel() throws MotanServiceException {
int index = MathUtil.getNonNegative(idx.getAndIncrement());
int index = MathUtil.getNonNegativeRange24bit(idx.getAndIncrement());
Channel channel;

for (int i = index; i < connections + index; i++) {
Expand Down
11 changes: 11 additions & 0 deletions motan-core/src/main/java/com/weibo/api/motan/util/MathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,15 @@ public static long parseLong(String longStr, long defaultValue){
public static int getNonNegative(int originValue){
return 0x7fffffff & originValue;
}

/**
* 通过二进制位操作将originValue转化为非负数:
* 范围在[0-16777215] 之间
*
* @param originValue
* @return
*/
public static int getNonNegativeRange24bit(int originValue) {
return 0x00ffffff & originValue;
}
}

0 comments on commit a315054

Please # to comment.