@@ -89,6 +116,7 @@ public class ConditionRouter implements Router, Comparable<Router> {
while(matcher.find()){// Try to match one by one
Stringseparator=matcher.group(1);
Stringcontent=matcher.group(2);
// System.out.println(separator + "\t" + content); // add by 芋艿,方便大家看
// Start part of the condition expression.
if(separator==null||separator.length()==0){
pair=newMatchPair();
...
...
@@ -105,64 +133,60 @@ public class ConditionRouter implements Router, Comparable<Router> {
}
// The Value in the KV part.
elseif("=".equals(separator)){
if(pair==null)
thrownewParseException("Illegal route rule \""
+rule+"\", The error char '"+separator
+"' at index "+matcher.start()+" before \""
+content+"\".",matcher.start());
if(pair==null){
thrownewParseException("Illegal route rule \""+rule+"\", The error char '"+separator+"' at index "+matcher.start()+" before \""+content+"\".",matcher.start());
}
values=pair.matches;
values.add(content);
}
// The Value in the KV part.
elseif("!=".equals(separator)){
if(pair==null)
thrownewParseException("Illegal route rule \""
+rule+"\", The error char '"+separator
+"' at index "+matcher.start()+" before \""
+content+"\".",matcher.start());
if(pair==null){
thrownewParseException("Illegal route rule \""+rule+"\", The error char '"+separator+"' at index "+matcher.start()+" before \""+content+"\".",matcher.start());
}
values=pair.mismatches;
values.add(content);
}
// The Value in the KV part, if Value have more than one items.
elseif(",".equals(separator)){// Should be seperateed by ','
if(values==null||values.isEmpty())
thrownewParseException("Illegal route rule \""
+rule+"\", The error char '"+separator
+"' at index "+matcher.start()+" before \""
+content+"\".",matcher.start());
if(values==null||values.isEmpty()){
thrownewParseException("Illegal route rule \""+rule+"\", The error char '"+separator+"' at index "+matcher.start()+" before \""+content+"\".",matcher.start());
+matcher.start()+" before \""+content+"\".",matcher.start());
thrownewParseException("Illegal route rule \""+rule+"\", The error char '"+separator+"' at index "+matcher.start()+" before \""+content+"\".",matcher.start());
logger.warn("The route result is empty and force execute. consumer: "+NetUtils.getLocalHost()+", service: "+url.getServiceKey()+", router: "+url.getParameterAndDecoded(Constants.RULE_KEY));
returnresult;
...
...
@@ -170,21 +194,10 @@ public class ConditionRouter implements Router, Comparable<Router> {
//Note the implicit contract (although the description is added to the interface declaration, but extensibility is a problem. The practice placed in the attachement needs to be improved)
//directory will return a list of normal invokers if Constants.INVOCATION_NEED_MOCK is present in invocation, otherwise, a list of mock invokers will return.
// directory will return a list of normal invokers if Constants.INVOCATION_NEED_MOCK is present in invocation, otherwise, a list of mock invokers will return.
// directory 根据 invocation 中 attachment 是否有 Constants.INVOCATION_NEED_MOCK,来判断获取的是 normal invokers or mock invokers
try{
invokers=directory.list(invocation);
}catch(RpcExceptione){
if(logger.isInfoEnabled()){
logger.info("Exception when try to invoke mock. Get mock invokers error for service:"
+", will contruct a new mock with 'new MockInvoker()'.",e);
logger.info("Exception when try to invoke mock. Get mock invokers error for service:"+directory.getUrl().getServiceInterface()+", method:"+invocation.getMethodName()+", will contruct a new mock with 'new MockInvoker()'.",e);
thrownewIllegalStateException("The mock implementation class "+mockClass.getName()+" not implement interface "+interfaceClass.getName());
}
// 校验是否有默认构造方法
try{
mockClass.getConstructor(newClass<?>[0]);
mockClass.getConstructor();
}catch(NoSuchMethodExceptione){
thrownewIllegalStateException("No such empty constructor \"public "+mockClass.getSimpleName()+"()\" in mock implementation class "+mockClass.getName());
thrownewIllegalStateException("No such empty constructor \"public "+mockClass.getSimpleName()+"()\" in mock implemention class "+mockClass.getName(),e);
thrownewIllegalStateException("No such empty constructor \"public "+mockClass.getSimpleName()+"()\" in mock implemention class "+mockClass.getName(),e);