Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,31 @@ public interface Router extends Comparable<Router> {
*/
<T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException;

/**
* priority
*
* @return
*/
Integer getPriority();
Comment thread
beiwei30 marked this conversation as resolved.
Outdated

/**
* compare Router
*
* @param o
* @return
*/
@Override
default int compareTo(Router o) {
if (o == null) {
throw new IllegalArgumentException();
}
if (this.getPriority().equals(o.getPriority())) {
if (o.getUrl() == null) {
return -1;
}
return getUrl().toFullString().compareTo(o.getUrl().toFullString());
} else {
return getPriority() > o.getPriority() ? 1 : -1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public <T> List<Invoker<T>> route(final List<Invoker<T>> invokers,
return invokers;
}

@Override
public Integer getPriority() {
return Integer.MAX_VALUE;
}

private <T> List<Invoker<T>> getMockedInvokers(final List<Invoker<T>> invokers) {
if (!hasMockProviders(invokers)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

/**
* ConditionRouter
*
*/
public class ConditionRouter implements Router {

Expand Down Expand Up @@ -178,17 +177,13 @@ public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation
}

@Override
public URL getUrl() {
return url;
public Integer getPriority() {
return priority;
}

@Override
public int compareTo(Router o) {
if (o == null || o.getClass() != ConditionRouter.class) {
return 1;
}
ConditionRouter c = (ConditionRouter) o;
return this.priority == c.priority ? url.toFullString().compareTo(c.url.toFullString()) : (this.priority > c.priority ? 1 : -1);
public URL getUrl() {
return url;
}

boolean matchWhen(URL url, Invocation invocation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

/**
* ScriptRouter
*
*/
public class ScriptRouter implements Router {

Expand Down Expand Up @@ -114,13 +113,24 @@ public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation
}
}

@Override
public Integer getPriority() {
return priority;
}

@Override
public int compareTo(Router o) {
if (o == null || o.getClass() != ScriptRouter.class) {
return 1;
if (o == null) {
Comment thread
beiwei30 marked this conversation as resolved.
throw new IllegalArgumentException();
}
if (this.priority == o.getPriority()) {
if (o instanceof ScriptRouter) {
ScriptRouter c = (ScriptRouter) o;
return rule.compareTo(c.rule);
}
return 0;
} else {
return this.priority > o.getPriority() ? 1 : -1;
}
ScriptRouter c = (ScriptRouter) o;
return this.priority == c.priority ? rule.compareTo(c.rule) : (this.priority > c.priority ? 1 : -1);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation
}
}
}
// Normal request
// Normal request
} else {
for (Invoker<T> invoker : invokers) {
// Can't access tag invoker,only normal invoker should be selected
Expand All @@ -98,11 +98,7 @@ public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation
}

@Override
public int compareTo(Router o) {
if (o == null || o.getClass() != TagRouter.class) {
return 1;
}
TagRouter c = (TagRouter) o;
return this.priority == c.priority ? url.toFullString().compareTo(c.url.toFullString()) : (this.priority > c.priority ? 1 : -1);
public Integer getPriority() {
return priority;
}
}