Package com.alibaba.dubbo.registry.common.route

Examples of com.alibaba.dubbo.registry.common.route.RouteRule


          }
          if(route.getService()!=null && !route.getService().isEmpty()){
              context.put("service", route.getService());
          }
         
          RouteRule routeRule= RouteRule.parse(route);
         
          @SuppressWarnings("unchecked")
          Map<String, RouteRule.MatchPair>[] paramArray = new Map[] {
              routeRule.getWhenCondition(), routeRule.getThenCondition()};
          String[][][] namesArray = new String[][][] {when_names, then_names };
         
          for(int i=0; i<paramArray.length; ++i) {
              Map<String, RouteRule.MatchPair> param = paramArray[i];
              String[][] names = namesArray[i];
View Full Code Here


            for(String[] names : then_names) {
                then_name2valueList.put(names[0], (String)context.get(names[1]));
                notThen_name2valueList.put(names[0], (String)context.get(names[2]));
            }

            RouteRule routeRule = RouteRule.createFromNameAndValueListString(
                    when_name2valueList, notWhen_name2valueList,
                    then_name2valueList, notThen_name2valueList);
           
            if (routeRule.getThenCondition().isEmpty()) {
                context.put("message", getMessage("Add route error! then is empty."));
                return false;
            }

            String matchRule = routeRule.getWhenConditionString();
            String filterRule = routeRule.getThenConditionString();
           
            //限制表达式的长度
            if (matchRule.length() > MAX_RULE_LENGTH) {
                context.put("message", getMessage("When rule is too long!"));
                return false;
            }
            if (filterRule.length() > MAX_RULE_LENGTH) {
                context.put("message", getMessage("Then rule is too long!"));
                return false;
            }
           
            Route route = new Route();
            route.setService(service);
            route.setName(name);
            route.setUsername((String)context.get("operator"));
            route.setOperator((String)context.get("operatorAddress"));
            route.setRule(routeRule.toString());
            if (StringUtils.isNotEmpty((String)context.get("priority"))) {
                route.setPriority(Integer.parseInt((String)context.get("priority")));
            }
            routeService.createRoute(route);
           
View Full Code Here

                for(String[] names : then_names) {
                    then_name2valueList.put(names[0], (String)context.get(names[1]));
                    notThen_name2valueList.put(names[0], (String)context.get(names[2]));
                }

                RouteRule routeRule = RouteRule.createFromNameAndValueListString(
                        when_name2valueList, notWhen_name2valueList,
                        then_name2valueList, notThen_name2valueList);
               
                RouteRule result = null;
                if(black){
                    RouteRule.MatchPair matchPair = routeRule.getThenCondition().get("black");
                    Map<String, RouteRule.MatchPair> then = null;
                    if(null == matchPair) {
                        matchPair = new RouteRule.MatchPair();
                        then = new HashMap<String, RouteRule.MatchPair>();
                        then.put("black", matchPair);
                    }else{
                        matchPair.getMatches().clear();
                    }
                    matchPair.getMatches().add(String.valueOf(black));
                    result =  RouteRule.copyWithReplace(routeRule, null, then);
                }
               
                if(result == null){
                    result = routeRule;
                }
               
                if (result.getThenCondition().isEmpty()) {
                    context.put("message", getMessage("Update route error! then is empty."));
                    return false;
                }
               
                String matchRule = result.getWhenConditionString();
                String filterRule = result.getThenConditionString();
               
                //限制表达式的长度
                if (matchRule.length() > MAX_RULE_LENGTH) {
                    context.put("message", getMessage("When rule is too long!"));
                    return false;
                }
                if (filterRule.length() > MAX_RULE_LENGTH) {
                    context.put("message", getMessage("Then rule is too long!"));
                    return false;
                }
               
                int priority = 0;
                if (StringUtils.isNotEmpty((String)context.get("priority"))) {
                    priority = Integer.parseInt((String)context.get("priority"));
                }
               
                Route route = new Route();
                route.setRule(result.toString());
                route.setService(service);
                route.setPriority(priority);
                route.setName((String)context.get("name"));
                route.setUsername((String)context.get("operator"));
                route.setOperator((String)context.get("operatorAddress"));
View Full Code Here

         services.add("service2");
        
         Route route = new Route();
         route.setMatchRule("service=com.alibaba.*,AuthService&service!=com.alibaba.DomainService,com.alibaba.ViewCacheService&consumer.host!=127.0.0.1,15.11.57.6&consumer.version = 2.0.0&consumer.version != 1.0.0");
         route.setFilterRule("provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020");
         RouteRule rr = RouteRule.parse(route);
         Collection<String> changedService = RouteRuleUtils.filterServiceByRule(services, rr);
         assertEquals(3,changedService.size());
    }
View Full Code Here

     services.add("service2");
    
     Route route = new Route();
     route.setMatchRule("service=com.alibaba.PC2Service&service!=com.alibaba.DomainService,com.alibaba.ViewCacheService&consumer.host!=127.0.0.1,15.11.57.6&consumer.version = 2.0.0&consumer.version != 1.0.0");
     route.setFilterRule("provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020");
     RouteRule rr = RouteRule.parse(route);
     Collection<String> changedService = RouteRuleUtils.filterServiceByRule(services, rr);
     assertEquals(2,changedService.size());
   }
View Full Code Here

TOP

Related Classes of com.alibaba.dubbo.registry.common.route.RouteRule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.