Skip to content

Commit

Permalink
Merge pull request apache#3083 beiwei30/incubator-dubbo, more code re…
Browse files Browse the repository at this point in the history
…view.

* refactor ScriptRouter

* refactor TagRouter

* refactor AbstractConfiguratorListener

* make sure parameter should not be null

* correct comments

* make ReferenceConfigurationListener private static

* avoid dup code in init

* add fixme for potential useless code

* clean up useless variables

* move methods into UrlUtils

* make method private

* reformat javadoc

* avoid dup code

* reformat log message

* reformat log message

* reformat the code

* remove useless imports

* remove useless code

* refactor ScriptRouter

* refactor TagRouter

* refactor AbstractConfiguratorListener

* Add comment

* Fix UT

* make sure parameter should not be null

* correct comments

* make ReferenceConfigurationListener private static

* Revert demo changes

* Revert code to avoid NPE in RPC wire after providers are cleared.

* make ListenableRouter code thread safe

* Fix UT

* Remove assert check to continue with execute.

* avoid dup code in init

* solve compile error

* add fixme for potential useless code

* clean up useless variables

* move methods into UrlUtils

* make method private

* reformat javadoc

* avoid dup code

* reformat log message

* reformat log message

* reformat the code

* remove useless imports

* remove useless code

* code review comments from @khanimteyaz

* code review from @khanimteyaz
  • Loading branch information
beiwei30 authored and khanimteyaz committed Jan 18, 2019
1 parent f1b2e41 commit 772a213
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ public void initWithRouters(List<Router> builtinRouters) {
this.sort();
}

public void addRouter(Router router) {
this.routers.add(router);
}

/**
* If we use route:// protocol in version before 2.7.0, each URL will generate a Router instance, so we should
* keep the routers up to date, that is, each time router URLs changes, we should update the routers list, only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.dubbo.rpc.cluster.Router;
import org.apache.dubbo.rpc.cluster.RouterChain;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -96,8 +96,7 @@ public void setRouterChain(RouterChain<T> routerChain) {
}

protected void addRouters(List<Router> routers) {
// copy list
routers = routers == null ? new ArrayList<>() : new ArrayList<>(routers);
routers = routers == null ? Collections.emptyList() : routers;
routerChain.addRouters(routers);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static org.apache.dubbo.common.Constants.CATEGORY_KEY;
import static org.apache.dubbo.common.Constants.CONFIGURATORS_CATEGORY;
import static org.apache.dubbo.common.Constants.DEFAULT_CATEGORY;
import static org.apache.dubbo.common.Constants.OVERRIDE_PROTOCOL;
import static org.apache.dubbo.common.Constants.PROVIDERS_CATEGORY;
import static org.apache.dubbo.common.Constants.ROUTERS_CATEGORY;
import static org.apache.dubbo.common.Constants.ROUTE_PROTOCOL;

public class UrlUtils {

/**
Expand Down Expand Up @@ -343,14 +351,14 @@ public static URL getEmptyUrl(String service, String category) {
service = service.substring(0, i);
}
return URL.valueOf(Constants.EMPTY_PROTOCOL + "://0.0.0.0/" + service + URL_PARAM_STARTING_SYMBOL
+ Constants.CATEGORY_KEY + "=" + category
+ CATEGORY_KEY + "=" + category
+ (group == null ? "" : "&" + Constants.GROUP_KEY + "=" + group)
+ (version == null ? "" : "&" + Constants.VERSION_KEY + "=" + version));
}

public static boolean isMatchCategory(String category, String categories) {
if (categories == null || categories.length() == 0) {
return Constants.DEFAULT_CATEGORY.equals(category);
return DEFAULT_CATEGORY.equals(category);
} else if (categories.contains(Constants.ANY_VALUE)) {
return true;
} else if (categories.contains(Constants.REMOVE_VALUE_PREFIX)) {
Expand All @@ -370,8 +378,8 @@ public static boolean isMatch(URL consumerUrl, URL providerUrl) {
return false;
}

if (!isMatchCategory(providerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY),
consumerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY))) {
if (!isMatchCategory(providerUrl.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY),
consumerUrl.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY))) {
return false;
}
if (!providerUrl.getParameter(Constants.ENABLED_KEY, true)
Expand Down Expand Up @@ -445,6 +453,22 @@ public static List<URL> classifyUrls(List<URL> urls, Predicate<URL> predicate) {
return urls.stream().filter(predicate).collect(Collectors.toList());
}

public static boolean isConfigurator(URL url) {
return OVERRIDE_PROTOCOL.equals(url.getProtocol()) ||
CONFIGURATORS_CATEGORY.equals(url.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY));
}

public static boolean isRoute(URL url) {
return ROUTE_PROTOCOL.equals(url.getProtocol()) ||
ROUTERS_CATEGORY.equals(url.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY));
}

public static boolean isProvider(URL url) {
return !OVERRIDE_PROTOCOL.equals(url.getProtocol()) &&
!ROUTE_PROTOCOL.equals(url.getProtocol()) &&
PROVIDERS_CATEGORY.equals(url.getParameter(CATEGORY_KEY, PROVIDERS_CATEGORY));
}

/**
* Check if the given value matches the given pattern. The pattern supports wildcard "*".
*
Expand All @@ -459,4 +483,4 @@ static boolean isItemMatch(String pattern, String value) {
return "*".equals(pattern) || pattern.equals(value);
}
}
}
}
Loading

0 comments on commit 772a213

Please sign in to comment.