Skip to content

Commit

Permalink
revert from 2.2.0 by chao.liuc
Browse files Browse the repository at this point in the history
git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@1845 1a56cb94-b969-4eaa-88fa-be21384802f2
  • Loading branch information
william.liangf committed May 24, 2012
1 parent 84644d0 commit 9cf1788
Show file tree
Hide file tree
Showing 114 changed files with 1,380 additions and 15,571 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
*/
package com.alibaba.dubbo.rpc.cluster.configurator;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.cluster.Configurator;
Expand All @@ -44,33 +40,8 @@ public URL getUrl() {
}

public URL configure(URL url) {
if (configuratorUrl == null || configuratorUrl.getHost() == null
|| url == null || url.getHost() == null) {
return url;
}
if (Constants.ANYHOST_VALUE.equals(configuratorUrl.getHost())
|| url.getHost().equals(configuratorUrl.getHost())) {
String configApplication = configuratorUrl.getParameter(Constants.APPLICATION_KEY, configuratorUrl.getUsername());
String currentApplication = url.getParameter(Constants.APPLICATION_KEY, url.getUsername());
if (configApplication == null || Constants.ANY_VALUE.equals(configApplication)
|| configApplication.equals(currentApplication)) {
if (configuratorUrl.getPort() == 0 || url.getPort() == configuratorUrl.getPort()) {
Set<String> condtionKeys = new HashSet<String>();
for (Map.Entry<String, String> entry : configuratorUrl.getParameters().entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (key.startsWith("~") || Constants.APPLICATION_KEY.equals(key)
|| Constants.SIDE_KEY.equals(key)) {
condtionKeys.add(key);
if (value != null && ! Constants.ANY_VALUE.equals(value)
&& ! value.equals(url.getParameter(key.startsWith("~") ? key.substring(1) : key))) {
return url;
}
}
}
return doConfigure(url, configuratorUrl.removeParameters(condtionKeys));
}
}
if (isMatch(getUrl(), url)) {
return doConfigure(url);
}
return url;
}
Expand All @@ -81,11 +52,30 @@ public int compareTo(Configurator o) {
}
return getUrl().getHost().compareTo(o.getUrl().getHost());
}

protected abstract URL doConfigure(URL currentUrl, URL configUrl);

public static void main(String[] args) {
System.out.println(URL.encode("timeout=100"));

private boolean isMatch(URL configuratorUrl, URL providerUrl) {
if (configuratorUrl == null || configuratorUrl.getHost() == null
|| providerUrl == null || providerUrl.getHost() == null) {
return false;
}
/*if (! providerUrl.getServiceKey().equals(configuratorUrl.getServiceKey())) {
return false;
}*/
if (Constants.ANYHOST_VALUE.equals(configuratorUrl.getHost())
|| providerUrl.getHost().equals(configuratorUrl.getHost())) {
String configApplication = configuratorUrl.getParameter(Constants.APPLICATION_KEY, configuratorUrl.getUsername());
String providerApplication = providerUrl.getParameter(Constants.APPLICATION_KEY, providerUrl.getUsername());
if (configApplication == null || configApplication.equals(providerApplication)) {
if (configuratorUrl.getPort() > 0) {
return providerUrl.getPort() == configuratorUrl.getPort();
} else {
return true;
}
}
}
return false;
}

protected abstract URL doConfigure(URL url);

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public AbsentConfigurator(URL url) {
super(url);
}

public URL doConfigure(URL currentUrl, URL configUrl) {
return currentUrl.addParametersIfAbsent(configUrl.getParameters());
public URL doConfigure(URL url) {
return url.addParametersIfAbsent(getUrl().getParameters());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public OverrideConfigurator(URL url) {
super(url);
}

public URL doConfigure(URL currentUrl, URL configUrl) {
return currentUrl.addParameters(configUrl.getParameters());
public URL doConfigure(URL providerUrl) {
return providerUrl.addParameters(getUrl().getParameters());
}

}
4 changes: 0 additions & 4 deletions dubbo-common/src/main/java/com/alibaba/dubbo/common/URL.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,6 @@ public int getPort() {
return port;
}

public int getPort(int defaultPort) {
return port == 0 ? defaultPort : port;
}

public String getAddress() {
return port <= 0 ? host : host + ":" + port;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public static boolean isMatch(URL consumerUrl, URL providerUrl) {
String providerClassifier = providerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE);
return (Constants.ANY_VALUE.equals(consumerGroup) || StringUtils.isEquals(consumerGroup, providerGroup) || StringUtils.isContains(consumerGroup, providerGroup))
&& (Constants.ANY_VALUE.equals(consumerVersion) || StringUtils.isEquals(consumerVersion, providerVersion))
&& (consumerClassifier == null || Constants.ANY_VALUE.equals(consumerClassifier) || StringUtils.isEquals(consumerClassifier, providerClassifier));
&& (Constants.ANY_VALUE.equals(consumerClassifier) || StringUtils.isEquals(consumerClassifier, providerClassifier));
}

public static boolean isMatchGlobPattern(String pattern, String value, URL param) {
Expand Down
Loading

0 comments on commit 9cf1788

Please sign in to comment.