@lexburner @kimmking
i think tree for statement can be combined one too, my impl:
@Override
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url,
Invocation invocation) throws RpcException {
// filter
List<Invoker<T>> result = new ArrayList<>();
// all invokers that don't have "tag" parameter in url is a normal
invoker
List<Invoker<T>> normalResult = new ArrayList<>();
try {
// Dynamic param
String tag = RpcContext.getContext().getAttachment(REQUEST_TAG_KEY);
for (Invoker<T> invoker : invokers) {
if
(StringUtils.isEmpty(invoker.getUrl().getParameter(TAG_KEY))) {
// all invokers that don't have "tag" parameter in url is a
normal invoker
normalResult.add(invoker);
} else {
if (invoker.getUrl().getParameter(TAG_KEY).equals(tag)) {
result.add(invoker);
}
}
}
// If no invoker be selected, downgrade to normal invokers
if (result.isEmpty()) {
return normalResult;
}
return result;
} catch (Exception e) {
logger.error("Route by tag error,return all invokers.", e);
}
// Downgrade to all invokers
return invokers;
}
[ Full content available at:
https://github.com/apache/incubator-dubbo/pull/2228 ]
This message was relayed via gitbox.apache.org for [email protected]