本文整理汇总了Java中com.alibaba.dubbo.registry.common.domain.Route类的典型用法代码示例。如果您正苦于以下问题:Java Route类的具体用法?Java Route怎么用?Java Route使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Route类属于com.alibaba.dubbo.registry.common.domain包,在下文中一共展示了Route类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: index
import com.alibaba.dubbo.registry.common.domain.Route; //导入依赖的package包/类
/**
* 路由模块首页
* @param context
*/
public void index(Map<String, Object> context) {
String service = (String) context.get("service");
String address = (String) context.get("address");
address = Tool.getIP(address);
List<Route> routes;
if (service != null && service.length() > 0
&& address != null && address.length() > 0) {
routes = routeService.findByServiceAndAddress(service, address);
} else if (service != null && service.length() > 0) {
routes = routeService.findByService(service);
} else if (address != null && address.length() > 0) {
routes = routeService.findByAddress(address);
} else {
routes = routeService.findAll();
}
context.put("routes", routes);
}
示例2: routeselect
import com.alibaba.dubbo.registry.common.domain.Route; //导入依赖的package包/类
/**
* 选择消费者
* @param context
*/
public void routeselect(Map<String, Object> context){
long rid = Long.valueOf((String)context.get("id"));
context.put("id", rid);
Route route = routeService.findRoute(rid);
if (route == null) {
throw new IllegalStateException("Route(id=" + rid + ") is not existed!");
}
context.put("route", route);
// 获取数据
List<Consumer> consumers = consumerService.findByService(route.getService());
context.put("consumers", consumers);
Map<String, Boolean> matchRoute = new HashMap<String, Boolean>();
for(Consumer c : consumers) {
matchRoute.put(c.getAddress(), RouteUtils.matchRoute(c.getAddress(), null, route, null));
}
context.put("matchRoute", matchRoute);
}
示例3: matchRoute
import com.alibaba.dubbo.registry.common.domain.Route; //导入依赖的package包/类
public static boolean matchRoute(String consumerAddress, String consumerQueryUrl, Route route, Map<String, List<String>> clusters) {
RouteRule rule = RouteRule.parseQuitely(route);
Map<String, RouteRule.MatchPair> when = RouteRuleUtils.expandCondition(
rule.getWhenCondition(), "consumer.cluster", "consumer.host", clusters);
Map<String, String> consumerSample = ParseUtils.parseQuery("consumer.", consumerQueryUrl);
final int index = consumerAddress.lastIndexOf(":");
String consumerHost = null;
if (index != -1) {
consumerHost = consumerAddress.substring(0, index);
} else {
consumerHost = consumerAddress;
}
consumerSample.put("consumer.host", consumerHost);
return RouteRuleUtils.isMatchCondition(when, consumerSample, consumerSample);
}
示例4: url2Route
import com.alibaba.dubbo.registry.common.domain.Route; //导入依赖的package包/类
public static Route url2Route(Pair<Long, URL> pair) {
if (pair == null) {
return null;
}
Long id = pair.getKey();
URL url = pair.getValue();
if (null == url)
return null;
Route r = new Route();
r.setId(id);
r.setName(url.getParameter("name"));
r.setService(url.getServiceKey());
r.setPriority(url.getParameter(Constants.PRIORITY_KEY, 0));
r.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));
r.setForce(url.getParameter(Constants.FORCE_KEY, false));
r.setRule(url.getParameterAndDecoded(Constants.RULE_KEY));
return r;
}
示例5: matchRoute
import com.alibaba.dubbo.registry.common.domain.Route; //导入依赖的package包/类
public static boolean matchRoute(String consumerAddress, String consumerQueryUrl, Route route, Map<String, List<String>> clusters) {
RouteRule rule = RouteRule.parseQuitely(route);
Map<String, RouteRule.MatchPair> when = RouteRuleUtils.expandCondition(
rule.getWhenCondition(), "consumer.cluster", "consumer.host", clusters);
Map<String, String> consumerSample = ParseUtils.parseQuery("consumer.", consumerQueryUrl);
final int index = consumerAddress.lastIndexOf(":");
String consumerHost = null;
if(index != -1){
consumerHost = consumerAddress.substring(0, index);
}
else {
consumerHost = consumerAddress;
}
consumerSample.put("consumer.host", consumerHost);
return RouteRuleUtils.isMatchCondition(when, consumerSample, consumerSample);
}
示例6: getFirstRouteMatchedWhenConditionOfRule
import com.alibaba.dubbo.registry.common.domain.Route; //导入依赖的package包/类
static Route getFirstRouteMatchedWhenConditionOfRule(String serviceName, Map<String, String> consumerSample, List<Route> routes, Map<Long, RouteRule> routeRuleMap) {
if (serviceName == null || serviceName.length() == 0) {
return null;
}
if (routes != null && routes.size() > 0) {
for (Route route : routes) {
if (isSerivceNameMatched(route.getService(), serviceName)) {
RouteRule rule = routeRuleMap.get(route.getId());
// 当满足when条件时
if (rule != null && RouteRuleUtils.isMatchCondition(
rule.getWhenCondition(), consumerSample, consumerSample)) {
return route; // 第一个满足即返回
}
}
}
}
return null;
}
示例7: route2RouteRule
import com.alibaba.dubbo.registry.common.domain.Route; //导入依赖的package包/类
static Map<Long, RouteRule> route2RouteRule(List<Route> routes,
Map<String, List<String>> clusters) {
Map<Long, RouteRule> rules = new HashMap<Long, RouteRule>();
// route -> RouteRule
if (routes != null && routes.size() > 0) {
for(Route route: routes) {
rules.put(route.getId(), RouteRule.parseQuitely(route));
}
}
// expand the cluster parameters into conditions of routerule
if (clusters != null && clusters.size() > 0) {
Map<Long, RouteRule> rrs = new HashMap<Long, RouteRule>();
for (Map.Entry<Long, RouteRule> entry : rules.entrySet()) {
RouteRule rr = entry.getValue();
Map<String, RouteRule.MatchPair> when = RouteRuleUtils.expandCondition(
rr.getWhenCondition(), "consumer.cluster", "consumer.host", clusters);
Map<String, RouteRule.MatchPair> then = RouteRuleUtils.expandCondition(
rr.getThenCondition(), "provider.cluster", "provider.host", clusters);
rrs.put(entry.getKey(), RouteRule.createFromCondition(when, then));
}
rules = rrs;
}
return rules;
}
示例8: route2RouteRule
import com.alibaba.dubbo.registry.common.domain.Route; //导入依赖的package包/类
static Map<Long, RouteRule> route2RouteRule(List<Route> routes,
Map<String, List<String>> clusters) {
Map<Long, RouteRule> rules = new HashMap<Long, RouteRule>();
// route -> RouteRule
if (routes != null && routes.size() > 0) {
for (Route route : routes) {
rules.put(route.getId(), RouteRule.parseQuitely(route));
}
}
// expand the cluster parameters into conditions of routerule
if (clusters != null && clusters.size() > 0) {
Map<Long, RouteRule> rrs = new HashMap<Long, RouteRule>();
for (Map.Entry<Long, RouteRule> entry : rules.entrySet()) {
RouteRule rr = entry.getValue();
Map<String, RouteRule.MatchPair> when = RouteRuleUtils.expandCondition(
rr.getWhenCondition(), "consumer.cluster", "consumer.host", clusters);
Map<String, RouteRule.MatchPair> then = RouteRuleUtils.expandCondition(
rr.getThenCondition(), "provider.cluster", "provider.host", clusters);
rrs.put(entry.getKey(), RouteRule.createFromCondition(when, then));
}
rules = rrs;
}
return rules;
}
示例9: url2Route
import com.alibaba.dubbo.registry.common.domain.Route; //导入依赖的package包/类
public static Route url2Route(Pair<Long, URL> pair) {
if (pair == null) {
return null;
}
Long id = pair.getKey();
URL url = pair.getValue();
if (null == url)
return null;
Route r = new Route();
r.setId(id);
r.setName(url.getParameter("name"));
r.setService(url.getServiceKey());
r.setPriority(url.getParameter(Constants.PRIORITY_KEY, 0));
r.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));
r.setForce(url.getParameter(Constants.FORCE_KEY, false));
r.setRule(url.getParameterAndDecoded(Constants.RULE_KEY));
return r;
}
示例10: updateRoute
import com.alibaba.dubbo.registry.common.domain.Route; //导入依赖的package包/类
public void updateRoute(Route route) {
Long id = route.getId();
if(id == null) {
throw new IllegalStateException("no route id");
}
URL oldRoute = findRouteUrl(id);
if(oldRoute == null) {
throw new IllegalStateException("Route was changed!");
}
registryService.unregister(oldRoute);
registryService.register(route.toUrl());
}
示例11: parse
import com.alibaba.dubbo.registry.common.domain.Route; //导入依赖的package包/类
/**
* 把字符串形式的RouteRule的解析成对象。
*
* @throws ParseException RouteRule字符串格式不对了。以下输入的情况,RouteRule都是非法的。
* <ul> <li> 输入是<code>null</code>。
* <li> 输入是空串,或是空白串。
* <li> 输入的Rule,没有When条件
* <li> 输入的Rule,没有Then条件
* </ul>
*/
public static RouteRule parse(Route route) throws ParseException {
if(route == null)
throw new ParseException("null route!", 0);
if(route.getMatchRule() == null && route.getFilterRule() == null) {
return parse(route.getRule());
}
return parse(route == null ? null : route.getMatchRule(), route == null ? null : route.getFilterRule());
}
示例12: url2RouteList
import com.alibaba.dubbo.registry.common.domain.Route; //导入依赖的package包/类
public static List<Route> url2RouteList(Map<Long, URL> cs) {
List<Route> list = new ArrayList<Route>();
if(cs == null) return list;
for(Map.Entry<Long, URL> entry : cs.entrySet()) {
list.add(url2Route(new Pair<Long, URL>(entry.getKey(), entry.getValue())));
}
return list;
}
示例13: previewRoute
import com.alibaba.dubbo.registry.common.domain.Route; //导入依赖的package包/类
public static Map<String, String> previewRoute(String serviceName, String consumerAddress, String queryUrl, Map<String, String> serviceUrls,
Route route, Map<String, List<String>> clusters, List<Route> routed) {
if(null == route) {
throw new IllegalArgumentException("Route is null.");
}
List<Route> routes = new ArrayList<Route>();
routes.add(route);
return route(serviceName, consumerAddress, queryUrl, serviceUrls, routes, clusters, routed);
}
示例14: parseQuitely
import com.alibaba.dubbo.registry.common.domain.Route; //导入依赖的package包/类
/**
* @see #parse(String)
* @throws RuntimeException 解析出错时,Wrap了{@link #parse(String)}方法的抛出的{@link ParseException}的异常。
*/
public static RouteRule parseQuitely(Route route) {
try {
return parse(route);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
示例15: test_filterServiceByRule
import com.alibaba.dubbo.registry.common.domain.Route; //导入依赖的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());
}