Skip to content

Dubbo route compareTo method donot work correctly #3249

Closed

Description

@cvictory

有如下问题:
1.java中要求 A.compareTo(B)和B.compareTo(A)得到的结果,应该是等价的。但是ScriptRoute里

` @Override
    public int compareTo(Router o) {
        if (o == null || o.getClass() != ScriptRouter.class) {
            return 1;
        }
        ScriptRouter c = (ScriptRouter) o;
        return this.priority == c.priority ? rule.compareTo(c.rule) : (this.priority > c.priority ? 1 : -1);
    }

想让ScriptRoute.compareTo(others) 等价于 others.compareTo(scriptRoute), 其实部分其他script如果自定义了自己的compareTo也会存在这个问题。

  1. 2.6和2.7兼容的问题
    2.6和2.7的顺序要怎么满足合理需求的同时,同时能满足前面的第一点要求。

先做个记录,问题待细化。

---------transplate

Have the following questions:
1.java requires that the results obtained by A.compareTo(B) and B.compareTo(A) should be equivalent. But in ScriptRoute

` @Override
     Public int compareTo(Router o) {
         If (o == null || o.getClass() != ScriptRouter.class) {
             Return 1;
         }
         ScriptRouter c = (ScriptRouter) o;
         Return this.priority == c.priority ? rule.compareTo(c.rule) : (this.priority > c.priority ? 1 : -1);
     }

let ScriptRoute.compareTo(others) to be equivalent to others.compareTo(scriptRoute). In fact, some other scripts have this problem if they customize their compareTo.

  1. 2.6 and 2.7 compatible issues
    How the order of 2.6 and 2.7 can meet the reasonable requirements, while meeting the first point requirements.

Make a record first, and the problem is to be refined.

Activity

  1. carryxyh commented on Jan 16, 2019

    @carryxyh
    Member

    第一个问题在master上已经修复了,那位提交者没有提交到2.6.x分支上,可以艾特他再提交一个到2.6.x上好了

  2. beiwei30 commented on Feb 2, 2019

    @beiwei30
    Member

    @cvictory is this fixed on both 2.7 and 2.6?

  3. lexburner commented on Feb 12, 2019

    @lexburner
    Contributor

    I have submitted the pr to fix this problem on both 2.7 and 2.6. The method compareTo is no need to
    overwrite in the most cases since the method getPriority existing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions