Skip to content

Commit

Permalink
DUBBO-505 客户端路由的条件没有匹配消费者地址,而误匹配了注册中心地址
Browse files Browse the repository at this point in the history
  • Loading branch information
liangfei0201 committed Jul 19, 2012
1 parent 3db678f commit 1972d70
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,24 @@ public abstract class AbstractDirectory<T> implements Directory<T> {
private final URL url ;

private volatile boolean destroyed = false;

private volatile List<Router> routers;

private volatile URL consumerUrl ;

private volatile List<Router> routers;

public AbstractDirectory(URL url) {
this(url, null);
}

public AbstractDirectory(URL url, List<Router> routers) {
this(url, url, routers);
}

public AbstractDirectory(URL url, List<Router> routers) {
public AbstractDirectory(URL url, URL consumerUrl, List<Router> routers) {
if (url == null)
throw new IllegalArgumentException("url == null");
this.url = url;
this.url = url;
this.consumerUrl = consumerUrl;
setRouters(routers);
}

Expand All @@ -68,7 +75,7 @@ public List<Invoker<T>> list(Invocation invocation) throws RpcException {
for (Router router: localRouters){
try {
if (router.getUrl() == null || router.getUrl().getParameter(Constants.RUNTIME_KEY, true)) {
invokers = router.route(invokers, getUrl(), invocation);
invokers = router.route(invokers, getConsumerUrl(), invocation);
}
} catch (Throwable t) {
logger.error("Failed to execute router: " + getUrl() + ", cause: " + t.getMessage(), t);
Expand All @@ -84,8 +91,16 @@ public URL getUrl() {

public List<Router> getRouters(){
return routers;
}

}

public URL getConsumerUrl() {
return consumerUrl;
}

public void setConsumerUrl(URL consumerUrl) {
this.consumerUrl = consumerUrl;
}

protected void setRouters(List<Router> routers){
// copy list
routers = routers == null ? new ArrayList<Router>() : new ArrayList<Router>(routers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify

private final boolean multiGroup;

private URL subscribeUrl;

private volatile boolean forbidden = false;

private volatile URL overrideDirectoryUrl; // 构造时初始化,断言不为null,并且总是赋非null值
Expand Down Expand Up @@ -131,7 +129,7 @@ public void setRegistry(Registry registry) {
}

public void subscribe(URL url) {
this.subscribeUrl = url;
setConsumerUrl(url);
registry.subscribe(url, this);
}

Expand All @@ -141,8 +139,8 @@ public void destroy() {
}
// unsubscribe.
try {
if(subscribeUrl != null && registry != null && registry.isAvailable()) {
registry.unsubscribe(subscribeUrl, this);
if(getConsumerUrl() != null && registry != null && registry.isAvailable()) {
registry.unsubscribe(getConsumerUrl(), this);
}
} catch (Throwable t) {
logger.warn("unexpeced error when unsubscribe service " + serviceKey + "from registry" + registry.getUrl(), t);
Expand Down Expand Up @@ -456,7 +454,7 @@ private List<Invoker<T>> route(List<Invoker<T>> invokers, String method) {
if (routers != null) {
for (Router router : routers) {
if (router.getUrl() != null && ! router.getUrl().getParameter(Constants.RUNTIME_KEY, true)) {
invokers = router.route(invokers, getUrl(), invocation);
invokers = router.route(invokers, getConsumerUrl(), invocation);
}
}
}
Expand Down

0 comments on commit 1972d70

Please sign in to comment.