当前位置: 首页>>代码示例>>Java>>正文


Java RouteRule类代码示例

本文整理汇总了Java中com.alibaba.dubbo.registry.common.route.RouteRule的典型用法代码示例。如果您正苦于以下问题:Java RouteRule类的具体用法?Java RouteRule怎么用?Java RouteRule使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RouteRule类属于com.alibaba.dubbo.registry.common.route包,在下文中一共展示了RouteRule类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_filterServiceByRule

import com.alibaba.dubbo.registry.common.route.RouteRule; //导入依赖的package包/类
@Test
public void test_filterServiceByRule()throws Exception {
     List<String> services = new ArrayList<String>();
     services.add("com.alibaba.MemberService");
     services.add("com.alibaba.ViewCacheService");
     services.add("com.alibaba.PC2Service");
     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());
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:16,代码来源:RouteRuleUtilsTest.java

示例2: test_filterServiceByRule2

import com.alibaba.dubbo.registry.common.route.RouteRule; //导入依赖的package包/类
@Test
 public void test_filterServiceByRule2()throws Exception {
  List<String> services = new ArrayList<String>();
  services.add("com.alibaba.MemberService");
  services.add("com.alibaba.ViewCacheService");
  services.add("com.alibaba.PC2Service");
  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());
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:16,代码来源:RouteRuleUtilsTest.java

示例3: show

import com.alibaba.dubbo.registry.common.route.RouteRule; //导入依赖的package包/类
/**
   * 显示路由详细信息
   * @param context
   */
  public void show(Map<String, Object> context) {
  	try {
       Route route = routeService.findRoute(Long.parseLong((String)context.get("id")));
       
       if (route == null) {
           throw new IllegalArgumentException("The route is not existed.");
       }
       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];
           for(String[] name : names) {
               RouteRule.MatchPair matchPair = param.get(name[0]);
               if(matchPair == null) {
                   continue;
               }
               
               if(!matchPair.getMatches().isEmpty()) {
                   String m = RouteRule.join(matchPair.getMatches());
                   context.put(name[1], m);
               }
               if(!matchPair.getUnmatches().isEmpty()) {
                   String u = RouteRule.join(matchPair.getUnmatches());
                   context.put(name[2], u);
               }
           }
       }
       context.put("route", route);
       context.put("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(route.getService()))));
  	} catch (ParseException e) {
	e.printStackTrace();
}
  }
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:48,代码来源:Routes.java

示例4: test_isMatchCondition

import com.alibaba.dubbo.registry.common.route.RouteRule; //导入依赖的package包/类
@Test
public void test_isMatchCondition()throws Exception {
    Map<String, RouteRule.MatchPair> condition = new HashMap<String, RouteRule.MatchPair>();
    Map<String, String> valueParams = new HashMap<String, String>();
    Map<String, String> kv = new HashMap<String, String>();
    
    boolean output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertTrue(output);
    
    {
        // key1
        Set<String> matches   = new HashSet<String>();
        matches.add("value1_1");
        matches.add("value1_2");
        matches.add("value1_3");
        Set<String> unmatches = new HashSet<String>();
        unmatches.add("v1_1");
        unmatches.add("v1_2");
        unmatches.add("v1_3");
        
        RouteRule.MatchPair p = new RouteRule.MatchPair(matches, unmatches);
        condition.put("key1", p);
        
        // key2 
        matches   = new HashSet<String>();
        matches.add("value2_1");
        matches.add("value2_2");
        matches.add("value2_3");
        unmatches = new HashSet<String>();
        unmatches.add("v2_1");
        unmatches.add("v2_2");
        unmatches.add("v2_3");
        
        p = new RouteRule.MatchPair(matches, unmatches);
        condition.put("key2", p);
    }
    
    kv.put("kkk", "vvv");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key1", "vvvXXX");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key1", "value1_1");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key2", "value2_1");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertTrue(output);
    
    kv.put("key1", "v1_2");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:58,代码来源:RouteRuleUtilsTest.java

示例5: show

import com.alibaba.dubbo.registry.common.route.RouteRule; //导入依赖的package包/类
/**
 * 显示路由详细信息
 *
 * @param context
 */
public void show(Map<String, Object> context) {
    try {
        Route route = routeService.findRoute(Long.parseLong((String) context.get("id")));

        if (route == null) {
            throw new IllegalArgumentException("The route is not existed.");
        }
        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];
            for (String[] name : names) {
                RouteRule.MatchPair matchPair = param.get(name[0]);
                if (matchPair == null) {
                    continue;
                }

                if (!matchPair.getMatches().isEmpty()) {
                    String m = RouteRule.join(matchPair.getMatches());
                    context.put(name[1], m);
                }
                if (!matchPair.getUnmatches().isEmpty()) {
                    String u = RouteRule.join(matchPair.getUnmatches());
                    context.put(name[2], u);
                }
            }
        }
        context.put("route", route);
        context.put("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(route.getService()))));
    } catch (ParseException e) {
        e.printStackTrace();
    }
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:49,代码来源:Routes.java


注:本文中的com.alibaba.dubbo.registry.common.route.RouteRule类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。