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


Java Router.route方法代码示例

本文整理汇总了Java中com.alibaba.dubbo.rpc.cluster.Router.route方法的典型用法代码示例。如果您正苦于以下问题:Java Router.route方法的具体用法?Java Router.route怎么用?Java Router.route使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.dubbo.rpc.cluster.Router的用法示例。


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

示例1: testRoute_PickInvokers

import com.alibaba.dubbo.rpc.cluster.Router; //导入方法依赖的package包/类
@Test
public void testRoute_PickInvokers(){
    String rule = "var result = new java.util.ArrayList(invokers.size());" +
            		"for (i=0;i<invokers.size(); i++){ " +
            		    "if (invokers.get(i).isAvailable()) {" +
            		        "result.add(invokers.get(i)) ;" +
            		    "}" +
            		"} ; " +
            		"return result;";
    String script = "function route(invokers,invocation,context){" + rule + "} route(invokers,invocation,context)";
    Router router = new ScriptRouterFactory().getRouter(getRouteUrl(script));
    
    List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
    Invoker<String> invoker1 = new MockInvoker<String>(false) ;
    Invoker<String> invoker2 = new MockInvoker<String>(true) ;
    Invoker<String> invoker3 = new MockInvoker<String>(true) ;
    invokers.add(invoker1);
    invokers.add(invoker2);
    invokers.add(invoker3);
    List<Invoker<String>> fileredInvokers = router.route(invokers, invokers.get(0).getUrl(), new RpcInvocation());
    Assert.assertEquals(2, fileredInvokers.size());
    Assert.assertEquals(invoker2, fileredInvokers.get(0));
    Assert.assertEquals(invoker3, fileredInvokers.get(1));
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:25,代码来源:ScriptRouterTest.java

示例2: list

import com.alibaba.dubbo.rpc.cluster.Router; //导入方法依赖的package包/类
public List<Invoker<T>> list(Invocation invocation) throws RpcException {
    if (destroyed) {
        throw new RpcException("Directory already destroyed .url: " + getUrl());
    }
    List<Invoker<T>> invokers = doList(invocation);
    List<Router> localRouters = this.routers; // local reference
    if (localRouters != null && localRouters.size() > 0) {
        for (Router router : localRouters) {
            try {
                if (router.getUrl() == null || router.getUrl().getParameter(Constants.RUNTIME_KEY, true)) {
                    invokers = router.route(invokers, getConsumerUrl(), invocation);
                }
            } catch (Throwable t) {
                logger.error("Failed to execute router: " + getUrl() + ", cause: " + t.getMessage(), t);
            }
        }
    }
    return invokers;
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:20,代码来源:AbstractDirectory.java

示例3: testRoute_Placeholder

import com.alibaba.dubbo.rpc.cluster.Router; //导入方法依赖的package包/类
@Test
public void testRoute_Placeholder(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = $host"));
    List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
    Invoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService")) ;
    Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")) ;
    Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")) ;
    invokers.add(invoker1);
    invokers.add(invoker2);
    invokers.add(invoker3);
    List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
    Assert.assertEquals(2, fileredInvokers.size());
    Assert.assertEquals(invoker2, fileredInvokers.get(0));
    Assert.assertEquals(invoker3, fileredInvokers.get(1));
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:16,代码来源:ConditionRouterTest.java

示例4: testRoute_ReturnFalse

import com.alibaba.dubbo.rpc.cluster.Router; //导入方法依赖的package包/类
@Test
public void testRoute_ReturnFalse(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => false"));
    List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
    invokers.add(new MockInvoker<String>());
    invokers.add(new MockInvoker<String>());
    invokers.add(new MockInvoker<String>());
    List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
    Assert.assertEquals(0, fileredInvokers.size());
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:11,代码来源:ConditionRouterTest.java

示例5: testRoute_HostFilter

import com.alibaba.dubbo.rpc.cluster.Router; //导入方法依赖的package包/类
@Test
public void testRoute_HostFilter(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = " + NetUtils.getLocalHost()));
    List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
    Invoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService")) ;
    Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")) ;
    Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")) ;
    invokers.add(invoker1);
    invokers.add(invoker2);
    invokers.add(invoker3);
    List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
    Assert.assertEquals(2, fileredInvokers.size());
    Assert.assertEquals(invoker2, fileredInvokers.get(0));
    Assert.assertEquals(invoker3, fileredInvokers.get(1));
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:16,代码来源:ConditionRouterTest.java

示例6: testRoute_ReturnAll

import com.alibaba.dubbo.rpc.cluster.Router; //导入方法依赖的package包/类
@Test
public void testRoute_ReturnAll(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = " + NetUtils.getLocalHost()));
    List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
    invokers.add(new MockInvoker<String>());
    invokers.add(new MockInvoker<String>());
    invokers.add(new MockInvoker<String>());
    List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
    Assert.assertEquals(invokers, fileredInvokers);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:11,代码来源:ConditionRouterTest.java

示例7: testRoute_Empty_HostFilter

import com.alibaba.dubbo.rpc.cluster.Router; //导入方法依赖的package包/类
@Test
public void testRoute_Empty_HostFilter(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl(" => " + " host = " + NetUtils.getLocalHost()));
    List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
    Invoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService")) ;
    Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")) ;
    Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")) ;
    invokers.add(invoker1);
    invokers.add(invoker2);
    invokers.add(invoker3);
    List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
    Assert.assertEquals(2, fileredInvokers.size());
    Assert.assertEquals(invoker2, fileredInvokers.get(0));
    Assert.assertEquals(invoker3, fileredInvokers.get(1));
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:16,代码来源:ConditionRouterTest.java

示例8: testRoute_ReturnAll

import com.alibaba.dubbo.rpc.cluster.Router; //导入方法依赖的package包/类
@Test
public void testRoute_ReturnAll() {
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = " + NetUtils.getLocalHost()));
    List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
    invokers.add(new MockInvoker<String>());
    invokers.add(new MockInvoker<String>());
    invokers.add(new MockInvoker<String>());
    List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
    Assert.assertEquals(invokers, fileredInvokers);
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:11,代码来源:ConditionRouterTest.java

示例9: testRoute_Force

import com.alibaba.dubbo.rpc.cluster.Router; //导入方法依赖的package包/类
@Test
public void testRoute_Force() {
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = 1.2.3.4").addParameter(Constants.FORCE_KEY, String.valueOf(true)));
    List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
    Invoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService"));
    Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService"));
    Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService"));
    invokers.add(invoker1);
    invokers.add(invoker2);
    invokers.add(invoker3);
    List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
    Assert.assertEquals(0, fileredInvokers.size());
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:14,代码来源:ConditionRouterTest.java

示例10: testRoute_ReturnAll

import com.alibaba.dubbo.rpc.cluster.Router; //导入方法依赖的package包/类
@Test
public void testRoute_ReturnAll(){
    Router router = new ScriptRouterFactory().getRouter(getRouteUrl("function route(op1,op2){return op1} route(invokers)"));
    List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
    invokers.add(new MockInvoker<String>());
    invokers.add(new MockInvoker<String>());
    invokers.add(new MockInvoker<String>());
    List<Invoker<String>> fileredInvokers = router.route(invokers, invokers.get(0).getUrl(), new RpcInvocation());
    Assert.assertEquals(invokers, fileredInvokers);
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:11,代码来源:ScriptRouterTest.java

示例11: route

import com.alibaba.dubbo.rpc.cluster.Router; //导入方法依赖的package包/类
private List<Invoker<T>> route(List<Invoker<T>> invokers, String method) {
    Invocation invocation = new RpcInvocation(method, new Class<?>[0], new Object[0]);
    List<Router> routers = getRouters(); 
    if (routers != null) {
        for (Router router : routers) {
            if (router.getUrl() != null && ! router.getUrl().getParameter(Constants.RUNTIME_KEY, true)) {
                invokers = router.route(invokers, getConsumerUrl(), invocation);
            }
        }
    }
    return invokers;
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:13,代码来源:RegistryDirectory.java

示例12: testRoute_False_HostFilter

import com.alibaba.dubbo.rpc.cluster.Router; //导入方法依赖的package包/类
@Test
public void testRoute_False_HostFilter(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("true => " + " host = " + NetUtils.getLocalHost()));
    List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
    Invoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService")) ;
    Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")) ;
    Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")) ;
    invokers.add(invoker1);
    invokers.add(invoker2);
    invokers.add(invoker3);
    List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
    Assert.assertEquals(2, fileredInvokers.size());
    Assert.assertEquals(invoker2, fileredInvokers.get(0));
    Assert.assertEquals(invoker3, fileredInvokers.get(1));
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:16,代码来源:ConditionRouterTest.java


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