target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void testIsMatch4() { URL consumerUrl = URL.valueOf("dubbo: URL providerUrl = URL.valueOf("http: assertTrue(UrlUtils.isMatch(consumerUrl, providerUrl)); }
|
public static boolean isMatch(URL consumerUrl, URL providerUrl) { String consumerInterface = consumerUrl.getServiceInterface(); String providerInterface = providerUrl.getServiceInterface(); if (!(Constants.ANY_VALUE.equals(consumerInterface) || StringUtils.isEquals(consumerInterface, providerInterface))) return false; if (!isMatchCategory(providerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY), consumerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY))) { return false; } if (!providerUrl.getParameter(Constants.ENABLED_KEY, true) && !Constants.ANY_VALUE.equals(consumerUrl.getParameter(Constants.ENABLED_KEY))) { return false; } String consumerGroup = consumerUrl.getParameter(Constants.GROUP_KEY); String consumerVersion = consumerUrl.getParameter(Constants.VERSION_KEY); String consumerClassifier = consumerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); String providerGroup = providerUrl.getParameter(Constants.GROUP_KEY); String providerVersion = providerUrl.getParameter(Constants.VERSION_KEY); String providerClassifier = providerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); return (Constants.ANY_VALUE.equals(consumerGroup) || StringUtils.isEquals(consumerGroup, providerGroup) || StringUtils.isContains(consumerGroup, providerGroup)) && (Constants.ANY_VALUE.equals(consumerVersion) || StringUtils.isEquals(consumerVersion, providerVersion)) && (consumerClassifier == null || Constants.ANY_VALUE.equals(consumerClassifier) || StringUtils.isEquals(consumerClassifier, providerClassifier)); }
|
UrlUtils { public static boolean isMatch(URL consumerUrl, URL providerUrl) { String consumerInterface = consumerUrl.getServiceInterface(); String providerInterface = providerUrl.getServiceInterface(); if (!(Constants.ANY_VALUE.equals(consumerInterface) || StringUtils.isEquals(consumerInterface, providerInterface))) return false; if (!isMatchCategory(providerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY), consumerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY))) { return false; } if (!providerUrl.getParameter(Constants.ENABLED_KEY, true) && !Constants.ANY_VALUE.equals(consumerUrl.getParameter(Constants.ENABLED_KEY))) { return false; } String consumerGroup = consumerUrl.getParameter(Constants.GROUP_KEY); String consumerVersion = consumerUrl.getParameter(Constants.VERSION_KEY); String consumerClassifier = consumerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); String providerGroup = providerUrl.getParameter(Constants.GROUP_KEY); String providerVersion = providerUrl.getParameter(Constants.VERSION_KEY); String providerClassifier = providerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); return (Constants.ANY_VALUE.equals(consumerGroup) || StringUtils.isEquals(consumerGroup, providerGroup) || StringUtils.isContains(consumerGroup, providerGroup)) && (Constants.ANY_VALUE.equals(consumerVersion) || StringUtils.isEquals(consumerVersion, providerVersion)) && (consumerClassifier == null || Constants.ANY_VALUE.equals(consumerClassifier) || StringUtils.isEquals(consumerClassifier, providerClassifier)); } }
|
UrlUtils { public static boolean isMatch(URL consumerUrl, URL providerUrl) { String consumerInterface = consumerUrl.getServiceInterface(); String providerInterface = providerUrl.getServiceInterface(); if (!(Constants.ANY_VALUE.equals(consumerInterface) || StringUtils.isEquals(consumerInterface, providerInterface))) return false; if (!isMatchCategory(providerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY), consumerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY))) { return false; } if (!providerUrl.getParameter(Constants.ENABLED_KEY, true) && !Constants.ANY_VALUE.equals(consumerUrl.getParameter(Constants.ENABLED_KEY))) { return false; } String consumerGroup = consumerUrl.getParameter(Constants.GROUP_KEY); String consumerVersion = consumerUrl.getParameter(Constants.VERSION_KEY); String consumerClassifier = consumerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); String providerGroup = providerUrl.getParameter(Constants.GROUP_KEY); String providerVersion = providerUrl.getParameter(Constants.VERSION_KEY); String providerClassifier = providerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); return (Constants.ANY_VALUE.equals(consumerGroup) || StringUtils.isEquals(consumerGroup, providerGroup) || StringUtils.isContains(consumerGroup, providerGroup)) && (Constants.ANY_VALUE.equals(consumerVersion) || StringUtils.isEquals(consumerVersion, providerVersion)) && (consumerClassifier == null || Constants.ANY_VALUE.equals(consumerClassifier) || StringUtils.isEquals(consumerClassifier, providerClassifier)); } }
|
UrlUtils { public static boolean isMatch(URL consumerUrl, URL providerUrl) { String consumerInterface = consumerUrl.getServiceInterface(); String providerInterface = providerUrl.getServiceInterface(); if (!(Constants.ANY_VALUE.equals(consumerInterface) || StringUtils.isEquals(consumerInterface, providerInterface))) return false; if (!isMatchCategory(providerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY), consumerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY))) { return false; } if (!providerUrl.getParameter(Constants.ENABLED_KEY, true) && !Constants.ANY_VALUE.equals(consumerUrl.getParameter(Constants.ENABLED_KEY))) { return false; } String consumerGroup = consumerUrl.getParameter(Constants.GROUP_KEY); String consumerVersion = consumerUrl.getParameter(Constants.VERSION_KEY); String consumerClassifier = consumerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); String providerGroup = providerUrl.getParameter(Constants.GROUP_KEY); String providerVersion = providerUrl.getParameter(Constants.VERSION_KEY); String providerClassifier = providerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); return (Constants.ANY_VALUE.equals(consumerGroup) || StringUtils.isEquals(consumerGroup, providerGroup) || StringUtils.isContains(consumerGroup, providerGroup)) && (Constants.ANY_VALUE.equals(consumerVersion) || StringUtils.isEquals(consumerVersion, providerVersion)) && (consumerClassifier == null || Constants.ANY_VALUE.equals(consumerClassifier) || StringUtils.isEquals(consumerClassifier, providerClassifier)); } static URL parseURL(String address, Map<String, String> defaults); static List<URL> parseURLs(String address, Map<String, String> defaults); static Map<String, Map<String, String>> convertRegister(Map<String, Map<String, String>> register); static Map<String, String> convertSubscribe(Map<String, String> subscribe); static Map<String, Map<String, String>> revertRegister(Map<String, Map<String, String>> register); static Map<String, String> revertSubscribe(Map<String, String> subscribe); static Map<String, Map<String, String>> revertNotify(Map<String, Map<String, String>> notify); static List<String> revertForbid(List<String> forbid, Set<URL> subscribed); static URL getEmptyUrl(String service, String category); static boolean isMatchCategory(String category, String categories); static boolean isMatch(URL consumerUrl, URL providerUrl); static boolean isMatchGlobPattern(String pattern, String value, URL param); static boolean isMatchGlobPattern(String pattern, String value); static boolean isServiceKeyMatch(URL pattern, URL value); }
|
UrlUtils { public static boolean isMatch(URL consumerUrl, URL providerUrl) { String consumerInterface = consumerUrl.getServiceInterface(); String providerInterface = providerUrl.getServiceInterface(); if (!(Constants.ANY_VALUE.equals(consumerInterface) || StringUtils.isEquals(consumerInterface, providerInterface))) return false; if (!isMatchCategory(providerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY), consumerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY))) { return false; } if (!providerUrl.getParameter(Constants.ENABLED_KEY, true) && !Constants.ANY_VALUE.equals(consumerUrl.getParameter(Constants.ENABLED_KEY))) { return false; } String consumerGroup = consumerUrl.getParameter(Constants.GROUP_KEY); String consumerVersion = consumerUrl.getParameter(Constants.VERSION_KEY); String consumerClassifier = consumerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); String providerGroup = providerUrl.getParameter(Constants.GROUP_KEY); String providerVersion = providerUrl.getParameter(Constants.VERSION_KEY); String providerClassifier = providerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); return (Constants.ANY_VALUE.equals(consumerGroup) || StringUtils.isEquals(consumerGroup, providerGroup) || StringUtils.isContains(consumerGroup, providerGroup)) && (Constants.ANY_VALUE.equals(consumerVersion) || StringUtils.isEquals(consumerVersion, providerVersion)) && (consumerClassifier == null || Constants.ANY_VALUE.equals(consumerClassifier) || StringUtils.isEquals(consumerClassifier, providerClassifier)); } static URL parseURL(String address, Map<String, String> defaults); static List<URL> parseURLs(String address, Map<String, String> defaults); static Map<String, Map<String, String>> convertRegister(Map<String, Map<String, String>> register); static Map<String, String> convertSubscribe(Map<String, String> subscribe); static Map<String, Map<String, String>> revertRegister(Map<String, Map<String, String>> register); static Map<String, String> revertSubscribe(Map<String, String> subscribe); static Map<String, Map<String, String>> revertNotify(Map<String, Map<String, String>> notify); static List<String> revertForbid(List<String> forbid, Set<URL> subscribed); static URL getEmptyUrl(String service, String category); static boolean isMatchCategory(String category, String categories); static boolean isMatch(URL consumerUrl, URL providerUrl); static boolean isMatchGlobPattern(String pattern, String value, URL param); static boolean isMatchGlobPattern(String pattern, String value); static boolean isServiceKeyMatch(URL pattern, URL value); }
|
@Test public void testIsMatch5() { URL consumerUrl = URL.valueOf("dubbo: URL providerUrl = URL.valueOf("http: assertTrue(UrlUtils.isMatch(consumerUrl, providerUrl)); }
|
public static boolean isMatch(URL consumerUrl, URL providerUrl) { String consumerInterface = consumerUrl.getServiceInterface(); String providerInterface = providerUrl.getServiceInterface(); if (!(Constants.ANY_VALUE.equals(consumerInterface) || StringUtils.isEquals(consumerInterface, providerInterface))) return false; if (!isMatchCategory(providerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY), consumerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY))) { return false; } if (!providerUrl.getParameter(Constants.ENABLED_KEY, true) && !Constants.ANY_VALUE.equals(consumerUrl.getParameter(Constants.ENABLED_KEY))) { return false; } String consumerGroup = consumerUrl.getParameter(Constants.GROUP_KEY); String consumerVersion = consumerUrl.getParameter(Constants.VERSION_KEY); String consumerClassifier = consumerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); String providerGroup = providerUrl.getParameter(Constants.GROUP_KEY); String providerVersion = providerUrl.getParameter(Constants.VERSION_KEY); String providerClassifier = providerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); return (Constants.ANY_VALUE.equals(consumerGroup) || StringUtils.isEquals(consumerGroup, providerGroup) || StringUtils.isContains(consumerGroup, providerGroup)) && (Constants.ANY_VALUE.equals(consumerVersion) || StringUtils.isEquals(consumerVersion, providerVersion)) && (consumerClassifier == null || Constants.ANY_VALUE.equals(consumerClassifier) || StringUtils.isEquals(consumerClassifier, providerClassifier)); }
|
UrlUtils { public static boolean isMatch(URL consumerUrl, URL providerUrl) { String consumerInterface = consumerUrl.getServiceInterface(); String providerInterface = providerUrl.getServiceInterface(); if (!(Constants.ANY_VALUE.equals(consumerInterface) || StringUtils.isEquals(consumerInterface, providerInterface))) return false; if (!isMatchCategory(providerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY), consumerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY))) { return false; } if (!providerUrl.getParameter(Constants.ENABLED_KEY, true) && !Constants.ANY_VALUE.equals(consumerUrl.getParameter(Constants.ENABLED_KEY))) { return false; } String consumerGroup = consumerUrl.getParameter(Constants.GROUP_KEY); String consumerVersion = consumerUrl.getParameter(Constants.VERSION_KEY); String consumerClassifier = consumerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); String providerGroup = providerUrl.getParameter(Constants.GROUP_KEY); String providerVersion = providerUrl.getParameter(Constants.VERSION_KEY); String providerClassifier = providerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); return (Constants.ANY_VALUE.equals(consumerGroup) || StringUtils.isEquals(consumerGroup, providerGroup) || StringUtils.isContains(consumerGroup, providerGroup)) && (Constants.ANY_VALUE.equals(consumerVersion) || StringUtils.isEquals(consumerVersion, providerVersion)) && (consumerClassifier == null || Constants.ANY_VALUE.equals(consumerClassifier) || StringUtils.isEquals(consumerClassifier, providerClassifier)); } }
|
UrlUtils { public static boolean isMatch(URL consumerUrl, URL providerUrl) { String consumerInterface = consumerUrl.getServiceInterface(); String providerInterface = providerUrl.getServiceInterface(); if (!(Constants.ANY_VALUE.equals(consumerInterface) || StringUtils.isEquals(consumerInterface, providerInterface))) return false; if (!isMatchCategory(providerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY), consumerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY))) { return false; } if (!providerUrl.getParameter(Constants.ENABLED_KEY, true) && !Constants.ANY_VALUE.equals(consumerUrl.getParameter(Constants.ENABLED_KEY))) { return false; } String consumerGroup = consumerUrl.getParameter(Constants.GROUP_KEY); String consumerVersion = consumerUrl.getParameter(Constants.VERSION_KEY); String consumerClassifier = consumerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); String providerGroup = providerUrl.getParameter(Constants.GROUP_KEY); String providerVersion = providerUrl.getParameter(Constants.VERSION_KEY); String providerClassifier = providerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); return (Constants.ANY_VALUE.equals(consumerGroup) || StringUtils.isEquals(consumerGroup, providerGroup) || StringUtils.isContains(consumerGroup, providerGroup)) && (Constants.ANY_VALUE.equals(consumerVersion) || StringUtils.isEquals(consumerVersion, providerVersion)) && (consumerClassifier == null || Constants.ANY_VALUE.equals(consumerClassifier) || StringUtils.isEquals(consumerClassifier, providerClassifier)); } }
|
UrlUtils { public static boolean isMatch(URL consumerUrl, URL providerUrl) { String consumerInterface = consumerUrl.getServiceInterface(); String providerInterface = providerUrl.getServiceInterface(); if (!(Constants.ANY_VALUE.equals(consumerInterface) || StringUtils.isEquals(consumerInterface, providerInterface))) return false; if (!isMatchCategory(providerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY), consumerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY))) { return false; } if (!providerUrl.getParameter(Constants.ENABLED_KEY, true) && !Constants.ANY_VALUE.equals(consumerUrl.getParameter(Constants.ENABLED_KEY))) { return false; } String consumerGroup = consumerUrl.getParameter(Constants.GROUP_KEY); String consumerVersion = consumerUrl.getParameter(Constants.VERSION_KEY); String consumerClassifier = consumerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); String providerGroup = providerUrl.getParameter(Constants.GROUP_KEY); String providerVersion = providerUrl.getParameter(Constants.VERSION_KEY); String providerClassifier = providerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); return (Constants.ANY_VALUE.equals(consumerGroup) || StringUtils.isEquals(consumerGroup, providerGroup) || StringUtils.isContains(consumerGroup, providerGroup)) && (Constants.ANY_VALUE.equals(consumerVersion) || StringUtils.isEquals(consumerVersion, providerVersion)) && (consumerClassifier == null || Constants.ANY_VALUE.equals(consumerClassifier) || StringUtils.isEquals(consumerClassifier, providerClassifier)); } static URL parseURL(String address, Map<String, String> defaults); static List<URL> parseURLs(String address, Map<String, String> defaults); static Map<String, Map<String, String>> convertRegister(Map<String, Map<String, String>> register); static Map<String, String> convertSubscribe(Map<String, String> subscribe); static Map<String, Map<String, String>> revertRegister(Map<String, Map<String, String>> register); static Map<String, String> revertSubscribe(Map<String, String> subscribe); static Map<String, Map<String, String>> revertNotify(Map<String, Map<String, String>> notify); static List<String> revertForbid(List<String> forbid, Set<URL> subscribed); static URL getEmptyUrl(String service, String category); static boolean isMatchCategory(String category, String categories); static boolean isMatch(URL consumerUrl, URL providerUrl); static boolean isMatchGlobPattern(String pattern, String value, URL param); static boolean isMatchGlobPattern(String pattern, String value); static boolean isServiceKeyMatch(URL pattern, URL value); }
|
UrlUtils { public static boolean isMatch(URL consumerUrl, URL providerUrl) { String consumerInterface = consumerUrl.getServiceInterface(); String providerInterface = providerUrl.getServiceInterface(); if (!(Constants.ANY_VALUE.equals(consumerInterface) || StringUtils.isEquals(consumerInterface, providerInterface))) return false; if (!isMatchCategory(providerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY), consumerUrl.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY))) { return false; } if (!providerUrl.getParameter(Constants.ENABLED_KEY, true) && !Constants.ANY_VALUE.equals(consumerUrl.getParameter(Constants.ENABLED_KEY))) { return false; } String consumerGroup = consumerUrl.getParameter(Constants.GROUP_KEY); String consumerVersion = consumerUrl.getParameter(Constants.VERSION_KEY); String consumerClassifier = consumerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); String providerGroup = providerUrl.getParameter(Constants.GROUP_KEY); String providerVersion = providerUrl.getParameter(Constants.VERSION_KEY); String providerClassifier = providerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); return (Constants.ANY_VALUE.equals(consumerGroup) || StringUtils.isEquals(consumerGroup, providerGroup) || StringUtils.isContains(consumerGroup, providerGroup)) && (Constants.ANY_VALUE.equals(consumerVersion) || StringUtils.isEquals(consumerVersion, providerVersion)) && (consumerClassifier == null || Constants.ANY_VALUE.equals(consumerClassifier) || StringUtils.isEquals(consumerClassifier, providerClassifier)); } static URL parseURL(String address, Map<String, String> defaults); static List<URL> parseURLs(String address, Map<String, String> defaults); static Map<String, Map<String, String>> convertRegister(Map<String, Map<String, String>> register); static Map<String, String> convertSubscribe(Map<String, String> subscribe); static Map<String, Map<String, String>> revertRegister(Map<String, Map<String, String>> register); static Map<String, String> revertSubscribe(Map<String, String> subscribe); static Map<String, Map<String, String>> revertNotify(Map<String, Map<String, String>> notify); static List<String> revertForbid(List<String> forbid, Set<URL> subscribed); static URL getEmptyUrl(String service, String category); static boolean isMatchCategory(String category, String categories); static boolean isMatch(URL consumerUrl, URL providerUrl); static boolean isMatchGlobPattern(String pattern, String value, URL param); static boolean isMatchGlobPattern(String pattern, String value); static boolean isServiceKeyMatch(URL pattern, URL value); }
|
@Test public void test_sort() throws Exception { List<Integer> list = new ArrayList<Integer>(); list.add(100); list.add(10); list.add(20); List<Integer> expected = new ArrayList<Integer>(); expected.add(10); expected.add(20); expected.add(100); assertEquals(expected, CollectionUtils.sort(list)); }
|
@SuppressWarnings({"unchecked", "rawtypes"}) public static <T> List<T> sort(List<T> list) { if (list != null && list.size() > 0) { Collections.sort((List) list); } return list; }
|
CollectionUtils { @SuppressWarnings({"unchecked", "rawtypes"}) public static <T> List<T> sort(List<T> list) { if (list != null && list.size() > 0) { Collections.sort((List) list); } return list; } }
|
CollectionUtils { @SuppressWarnings({"unchecked", "rawtypes"}) public static <T> List<T> sort(List<T> list) { if (list != null && list.size() > 0) { Collections.sort((List) list); } return list; } private CollectionUtils(); }
|
CollectionUtils { @SuppressWarnings({"unchecked", "rawtypes"}) public static <T> List<T> sort(List<T> list) { if (list != null && list.size() > 0) { Collections.sort((List) list); } return list; } private CollectionUtils(); @SuppressWarnings({"unchecked", "rawtypes"}) static List<T> sort(List<T> list); static List<String> sortSimpleName(List<String> list); static Map<String, Map<String, String>> splitAll(Map<String, List<String>> list, String separator); static Map<String, List<String>> joinAll(Map<String, Map<String, String>> map, String separator); static Map<String, String> split(List<String> list, String separator); static List<String> join(Map<String, String> map, String separator); static String join(List<String> list, String separator); static boolean mapEquals(Map<?, ?> map1, Map<?, ?> map2); static Map<String, String> toStringMap(String... pairs); @SuppressWarnings("unchecked") static Map<K, V> toMap(Object... pairs); static boolean isEmpty(Collection<?> collection); static boolean isNotEmpty(Collection<?> collection); }
|
CollectionUtils { @SuppressWarnings({"unchecked", "rawtypes"}) public static <T> List<T> sort(List<T> list) { if (list != null && list.size() > 0) { Collections.sort((List) list); } return list; } private CollectionUtils(); @SuppressWarnings({"unchecked", "rawtypes"}) static List<T> sort(List<T> list); static List<String> sortSimpleName(List<String> list); static Map<String, Map<String, String>> splitAll(Map<String, List<String>> list, String separator); static Map<String, List<String>> joinAll(Map<String, Map<String, String>> map, String separator); static Map<String, String> split(List<String> list, String separator); static List<String> join(Map<String, String> map, String separator); static String join(List<String> list, String separator); static boolean mapEquals(Map<?, ?> map1, Map<?, ?> map2); static Map<String, String> toStringMap(String... pairs); @SuppressWarnings("unchecked") static Map<K, V> toMap(Object... pairs); static boolean isEmpty(Collection<?> collection); static boolean isNotEmpty(Collection<?> collection); }
|
@Test public void testSelectAgainAndCheckAvailable() { LoadBalance lb = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(RoundRobinLoadBalance.NAME); initlistsize5(); { selectedInvokers.clear(); selectedInvokers.add(invoker1); selectedInvokers.add(invoker2); selectedInvokers.add(invoker3); selectedInvokers.add(invoker5); Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers); Assert.assertTrue(sinvoker == invoker4); } { selectedInvokers.clear(); selectedInvokers.add(invoker2); selectedInvokers.add(invoker3); selectedInvokers.add(invoker4); selectedInvokers.add(invoker5); Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers); Assert.assertTrue(sinvoker == invoker2 || sinvoker == invoker4); } { for (int i = 0; i < 100; i++) { selectedInvokers.clear(); Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers); Assert.assertTrue(sinvoker == invoker2 || sinvoker == invoker4); } } { for (int i = 0; i < 100; i++) { selectedInvokers.clear(); selectedInvokers.add(invoker1); selectedInvokers.add(invoker3); selectedInvokers.add(invoker5); Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers); Assert.assertTrue(sinvoker == invoker2 || sinvoker == invoker4); } } { for (int i = 0; i < 100; i++) { selectedInvokers.clear(); selectedInvokers.add(invoker1); selectedInvokers.add(invoker3); selectedInvokers.add(invoker2); selectedInvokers.add(invoker4); selectedInvokers.add(invoker5); Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers); Assert.assertTrue(sinvoker == invoker2 || sinvoker == invoker4); } } }
|
protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException { if (invokers == null || invokers.size() == 0) return null; String methodName = invocation == null ? "" : invocation.getMethodName(); boolean sticky = invokers.get(0).getUrl().getMethodParameter(methodName, Constants.CLUSTER_STICKY_KEY, Constants.DEFAULT_CLUSTER_STICKY); { if (stickyInvoker != null && !invokers.contains(stickyInvoker)) { stickyInvoker = null; } if (sticky && stickyInvoker != null && (selected == null || !selected.contains(stickyInvoker))) { if (availablecheck && stickyInvoker.isAvailable()) { return stickyInvoker; } } } Invoker<T> invoker = doselect(loadbalance, invocation, invokers, selected); if (sticky) { stickyInvoker = invoker; } return invoker; }
|
AbstractClusterInvoker implements Invoker<T> { protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException { if (invokers == null || invokers.size() == 0) return null; String methodName = invocation == null ? "" : invocation.getMethodName(); boolean sticky = invokers.get(0).getUrl().getMethodParameter(methodName, Constants.CLUSTER_STICKY_KEY, Constants.DEFAULT_CLUSTER_STICKY); { if (stickyInvoker != null && !invokers.contains(stickyInvoker)) { stickyInvoker = null; } if (sticky && stickyInvoker != null && (selected == null || !selected.contains(stickyInvoker))) { if (availablecheck && stickyInvoker.isAvailable()) { return stickyInvoker; } } } Invoker<T> invoker = doselect(loadbalance, invocation, invokers, selected); if (sticky) { stickyInvoker = invoker; } return invoker; } }
|
AbstractClusterInvoker implements Invoker<T> { protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException { if (invokers == null || invokers.size() == 0) return null; String methodName = invocation == null ? "" : invocation.getMethodName(); boolean sticky = invokers.get(0).getUrl().getMethodParameter(methodName, Constants.CLUSTER_STICKY_KEY, Constants.DEFAULT_CLUSTER_STICKY); { if (stickyInvoker != null && !invokers.contains(stickyInvoker)) { stickyInvoker = null; } if (sticky && stickyInvoker != null && (selected == null || !selected.contains(stickyInvoker))) { if (availablecheck && stickyInvoker.isAvailable()) { return stickyInvoker; } } } Invoker<T> invoker = doselect(loadbalance, invocation, invokers, selected); if (sticky) { stickyInvoker = invoker; } return invoker; } AbstractClusterInvoker(Directory<T> directory); AbstractClusterInvoker(Directory<T> directory, URL url); }
|
AbstractClusterInvoker implements Invoker<T> { protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException { if (invokers == null || invokers.size() == 0) return null; String methodName = invocation == null ? "" : invocation.getMethodName(); boolean sticky = invokers.get(0).getUrl().getMethodParameter(methodName, Constants.CLUSTER_STICKY_KEY, Constants.DEFAULT_CLUSTER_STICKY); { if (stickyInvoker != null && !invokers.contains(stickyInvoker)) { stickyInvoker = null; } if (sticky && stickyInvoker != null && (selected == null || !selected.contains(stickyInvoker))) { if (availablecheck && stickyInvoker.isAvailable()) { return stickyInvoker; } } } Invoker<T> invoker = doselect(loadbalance, invocation, invokers, selected); if (sticky) { stickyInvoker = invoker; } return invoker; } AbstractClusterInvoker(Directory<T> directory); AbstractClusterInvoker(Directory<T> directory, URL url); Class<T> getInterface(); URL getUrl(); boolean isAvailable(); void destroy(); Result invoke(final Invocation invocation); @Override String toString(); }
|
AbstractClusterInvoker implements Invoker<T> { protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException { if (invokers == null || invokers.size() == 0) return null; String methodName = invocation == null ? "" : invocation.getMethodName(); boolean sticky = invokers.get(0).getUrl().getMethodParameter(methodName, Constants.CLUSTER_STICKY_KEY, Constants.DEFAULT_CLUSTER_STICKY); { if (stickyInvoker != null && !invokers.contains(stickyInvoker)) { stickyInvoker = null; } if (sticky && stickyInvoker != null && (selected == null || !selected.contains(stickyInvoker))) { if (availablecheck && stickyInvoker.isAvailable()) { return stickyInvoker; } } } Invoker<T> invoker = doselect(loadbalance, invocation, invokers, selected); if (sticky) { stickyInvoker = invoker; } return invoker; } AbstractClusterInvoker(Directory<T> directory); AbstractClusterInvoker(Directory<T> directory, URL url); Class<T> getInterface(); URL getUrl(); boolean isAvailable(); void destroy(); Result invoke(final Invocation invocation); @Override String toString(); }
|
@Test public void test_sortSimpleName() throws Exception { List<String> list = new ArrayList<String>(); list.add("aaa.z"); list.add("b"); list.add(null); list.add("zzz.a"); list.add("c"); list.add(null); List<String> sorted = CollectionUtils.sortSimpleName(list); assertNull(sorted.get(0)); assertNull(sorted.get(1)); }
|
public static List<String> sortSimpleName(List<String> list) { if (list != null && list.size() > 0) { Collections.sort(list, SIMPLE_NAME_COMPARATOR); } return list; }
|
CollectionUtils { public static List<String> sortSimpleName(List<String> list) { if (list != null && list.size() > 0) { Collections.sort(list, SIMPLE_NAME_COMPARATOR); } return list; } }
|
CollectionUtils { public static List<String> sortSimpleName(List<String> list) { if (list != null && list.size() > 0) { Collections.sort(list, SIMPLE_NAME_COMPARATOR); } return list; } private CollectionUtils(); }
|
CollectionUtils { public static List<String> sortSimpleName(List<String> list) { if (list != null && list.size() > 0) { Collections.sort(list, SIMPLE_NAME_COMPARATOR); } return list; } private CollectionUtils(); @SuppressWarnings({"unchecked", "rawtypes"}) static List<T> sort(List<T> list); static List<String> sortSimpleName(List<String> list); static Map<String, Map<String, String>> splitAll(Map<String, List<String>> list, String separator); static Map<String, List<String>> joinAll(Map<String, Map<String, String>> map, String separator); static Map<String, String> split(List<String> list, String separator); static List<String> join(Map<String, String> map, String separator); static String join(List<String> list, String separator); static boolean mapEquals(Map<?, ?> map1, Map<?, ?> map2); static Map<String, String> toStringMap(String... pairs); @SuppressWarnings("unchecked") static Map<K, V> toMap(Object... pairs); static boolean isEmpty(Collection<?> collection); static boolean isNotEmpty(Collection<?> collection); }
|
CollectionUtils { public static List<String> sortSimpleName(List<String> list) { if (list != null && list.size() > 0) { Collections.sort(list, SIMPLE_NAME_COMPARATOR); } return list; } private CollectionUtils(); @SuppressWarnings({"unchecked", "rawtypes"}) static List<T> sort(List<T> list); static List<String> sortSimpleName(List<String> list); static Map<String, Map<String, String>> splitAll(Map<String, List<String>> list, String separator); static Map<String, List<String>> joinAll(Map<String, Map<String, String>> map, String separator); static Map<String, String> split(List<String> list, String separator); static List<String> join(Map<String, String> map, String separator); static String join(List<String> list, String separator); static boolean mapEquals(Map<?, ?> map1, Map<?, ?> map2); static Map<String, String> toStringMap(String... pairs); @SuppressWarnings("unchecked") static Map<K, V> toMap(Object... pairs); static boolean isEmpty(Collection<?> collection); static boolean isNotEmpty(Collection<?> collection); }
|
@Test public void test_joinList() throws Exception { List<String> list = Arrays.asList(); assertEquals("", CollectionUtils.join(list, "/")); list = Arrays.asList("x"); assertEquals("x", CollectionUtils.join(list, "-")); list = Arrays.asList("a", "b"); assertEquals("a/b", CollectionUtils.join(list, "/")); }
|
public static List<String> join(Map<String, String> map, String separator) { if (map == null) { return null; } List<String> list = new ArrayList<String>(); if (map == null || map.size() == 0) { return list; } for (Map.Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (value == null || value.length() == 0) { list.add(key); } else { list.add(key + separator + value); } } return list; }
|
CollectionUtils { public static List<String> join(Map<String, String> map, String separator) { if (map == null) { return null; } List<String> list = new ArrayList<String>(); if (map == null || map.size() == 0) { return list; } for (Map.Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (value == null || value.length() == 0) { list.add(key); } else { list.add(key + separator + value); } } return list; } }
|
CollectionUtils { public static List<String> join(Map<String, String> map, String separator) { if (map == null) { return null; } List<String> list = new ArrayList<String>(); if (map == null || map.size() == 0) { return list; } for (Map.Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (value == null || value.length() == 0) { list.add(key); } else { list.add(key + separator + value); } } return list; } private CollectionUtils(); }
|
CollectionUtils { public static List<String> join(Map<String, String> map, String separator) { if (map == null) { return null; } List<String> list = new ArrayList<String>(); if (map == null || map.size() == 0) { return list; } for (Map.Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (value == null || value.length() == 0) { list.add(key); } else { list.add(key + separator + value); } } return list; } private CollectionUtils(); @SuppressWarnings({"unchecked", "rawtypes"}) static List<T> sort(List<T> list); static List<String> sortSimpleName(List<String> list); static Map<String, Map<String, String>> splitAll(Map<String, List<String>> list, String separator); static Map<String, List<String>> joinAll(Map<String, Map<String, String>> map, String separator); static Map<String, String> split(List<String> list, String separator); static List<String> join(Map<String, String> map, String separator); static String join(List<String> list, String separator); static boolean mapEquals(Map<?, ?> map1, Map<?, ?> map2); static Map<String, String> toStringMap(String... pairs); @SuppressWarnings("unchecked") static Map<K, V> toMap(Object... pairs); static boolean isEmpty(Collection<?> collection); static boolean isNotEmpty(Collection<?> collection); }
|
CollectionUtils { public static List<String> join(Map<String, String> map, String separator) { if (map == null) { return null; } List<String> list = new ArrayList<String>(); if (map == null || map.size() == 0) { return list; } for (Map.Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (value == null || value.length() == 0) { list.add(key); } else { list.add(key + separator + value); } } return list; } private CollectionUtils(); @SuppressWarnings({"unchecked", "rawtypes"}) static List<T> sort(List<T> list); static List<String> sortSimpleName(List<String> list); static Map<String, Map<String, String>> splitAll(Map<String, List<String>> list, String separator); static Map<String, List<String>> joinAll(Map<String, Map<String, String>> map, String separator); static Map<String, String> split(List<String> list, String separator); static List<String> join(Map<String, String> map, String separator); static String join(List<String> list, String separator); static boolean mapEquals(Map<?, ?> map1, Map<?, ?> map2); static Map<String, String> toStringMap(String... pairs); @SuppressWarnings("unchecked") static Map<K, V> toMap(Object... pairs); static boolean isEmpty(Collection<?> collection); static boolean isNotEmpty(Collection<?> collection); }
|
@Test public void test_expandCondition() throws Exception { Map<String, RouteRule.MatchPair> condition = new HashMap<String, RouteRule.MatchPair>(); { 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); 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); matches = new HashSet<String>(); matches.add("value3_1"); matches.add("value3_2"); matches.add("value3_3"); unmatches = new HashSet<String>(); unmatches.add("v3_1"); unmatches.add("v3_2"); unmatches.add("v3_3"); p = new RouteRule.MatchPair(matches, unmatches); condition.put("key3 ", p); } Map<String, Set<String>> expandName2Set = new HashMap<String, Set<String>>(); { expandName2Set.put("value1_1", new HashSet<String>(Arrays.asList("cat1", "dog1"))); expandName2Set.put("value1_2", new HashSet<String>(Arrays.asList("cat2", "dog2"))); expandName2Set.put("value1_3", new HashSet<String>(Arrays.asList("cat3", "dog3"))); expandName2Set.put("v1_1", new HashSet<String>(Arrays.asList("pig1", "rat1"))); expandName2Set.put("v1_2", new HashSet<String>(Arrays.asList("pig2", "rat2"))); } Map<String, RouteRule.MatchPair> output = RouteRuleUtils.expandCondition(condition, "key1", "key2", expandName2Set); Map<String, RouteRule.MatchPair> expected = new HashMap<String, RouteRule.MatchPair>(); { Set<String> matches = new HashSet<String>(); matches.add("value2_1"); matches.add("value2_2"); matches.add("value2_3"); matches.add("cat1"); matches.add("cat2"); matches.add("cat3"); matches.add("dog1"); matches.add("dog2"); matches.add("dog3"); Set<String> unmatches = new HashSet<String>(); unmatches.add("v2_1"); unmatches.add("v2_2"); unmatches.add("v2_3"); unmatches.add("v2_3"); unmatches.add("pig1"); unmatches.add("pig2"); unmatches.add("rat1"); unmatches.add("rat2"); RouteRule.MatchPair p = new RouteRule.MatchPair(matches, unmatches); expected.put("key2", p); matches = new HashSet<String>(); matches.add("value3_1"); matches.add("value3_2"); matches.add("value3_3"); unmatches = new HashSet<String>(); unmatches.add("v3_1"); unmatches.add("v3_2"); unmatches.add("v3_3"); p = new RouteRule.MatchPair(matches, unmatches); expected.put("key3 ", p); } assertEquals(expected, output); output = RouteRuleUtils.expandCondition(condition, "key1", "keyX", expandName2Set); expected = new HashMap<String, RouteRule.MatchPair>(); { Set<String> matches = new HashSet<String>(); matches.add("cat1"); matches.add("cat2"); matches.add("cat3"); matches.add("dog1"); matches.add("dog2"); matches.add("dog3"); Set<String> unmatches = new HashSet<String>(); unmatches.add("pig1"); unmatches.add("pig2"); unmatches.add("rat1"); unmatches.add("rat2"); RouteRule.MatchPair p = new RouteRule.MatchPair(matches, unmatches); expected.put("keyX", p); 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); expected.put("key2", p); matches = new HashSet<String>(); matches.add("value3_1"); matches.add("value3_2"); matches.add("value3_3"); unmatches = new HashSet<String>(); unmatches.add("v3_1"); unmatches.add("v3_2"); unmatches.add("v3_3"); p = new RouteRule.MatchPair(matches, unmatches); expected.put("key3 ", p); } output = RouteRuleUtils.expandCondition(condition, "keyNotExsited", "key3", expandName2Set); assertSame(condition, output); }
|
public static <T extends Collection<String>> Map<String, RouteRule.MatchPair> expandCondition( Map<String, RouteRule.MatchPair> condition, String srcKeyName, String destKeyName, Map<String, T> expandName2Set) { if (null == condition || StringUtils.isEmpty(srcKeyName) || StringUtils.isEmpty(destKeyName)) { return condition; } RouteRule.MatchPair matchPair = condition.get(srcKeyName); if (matchPair == null) { return condition; } Map<String, RouteRule.MatchPair> ret = new HashMap<String, RouteRule.MatchPair>(); Iterator<Entry<String, RouteRule.MatchPair>> iterator = condition.entrySet().iterator(); for (; iterator.hasNext(); ) { Entry<String, RouteRule.MatchPair> entry = iterator.next(); String condName = entry.getKey(); if (!condName.equals(srcKeyName) && !condName.equals(destKeyName)) { RouteRule.MatchPair p = entry.getValue(); if (p != null) ret.put(condName, p); } else if (condName.equals(srcKeyName)) { RouteRule.MatchPair from = condition.get(srcKeyName); RouteRule.MatchPair to = condition.get(destKeyName); if (from == null || from.getMatches().isEmpty() && from.getUnmatches().isEmpty()) { if (to != null) ret.put(destKeyName, to); continue; } Set<String> matches = new HashSet<String>(); Set<String> unmatches = new HashSet<String>(); for (String s : from.getMatches()) { if (expandName2Set == null || !expandName2Set.containsKey(s)) continue; matches.addAll(expandName2Set.get(s)); } for (String s : from.getUnmatches()) { if (expandName2Set == null || !expandName2Set.containsKey(s)) continue; unmatches.addAll(expandName2Set.get(s)); } if (to != null) { matches.addAll(to.getMatches()); unmatches.addAll(to.getUnmatches()); } ret.put(destKeyName, new RouteRule.MatchPair(matches, unmatches)); } } return ret; }
|
RouteRuleUtils { public static <T extends Collection<String>> Map<String, RouteRule.MatchPair> expandCondition( Map<String, RouteRule.MatchPair> condition, String srcKeyName, String destKeyName, Map<String, T> expandName2Set) { if (null == condition || StringUtils.isEmpty(srcKeyName) || StringUtils.isEmpty(destKeyName)) { return condition; } RouteRule.MatchPair matchPair = condition.get(srcKeyName); if (matchPair == null) { return condition; } Map<String, RouteRule.MatchPair> ret = new HashMap<String, RouteRule.MatchPair>(); Iterator<Entry<String, RouteRule.MatchPair>> iterator = condition.entrySet().iterator(); for (; iterator.hasNext(); ) { Entry<String, RouteRule.MatchPair> entry = iterator.next(); String condName = entry.getKey(); if (!condName.equals(srcKeyName) && !condName.equals(destKeyName)) { RouteRule.MatchPair p = entry.getValue(); if (p != null) ret.put(condName, p); } else if (condName.equals(srcKeyName)) { RouteRule.MatchPair from = condition.get(srcKeyName); RouteRule.MatchPair to = condition.get(destKeyName); if (from == null || from.getMatches().isEmpty() && from.getUnmatches().isEmpty()) { if (to != null) ret.put(destKeyName, to); continue; } Set<String> matches = new HashSet<String>(); Set<String> unmatches = new HashSet<String>(); for (String s : from.getMatches()) { if (expandName2Set == null || !expandName2Set.containsKey(s)) continue; matches.addAll(expandName2Set.get(s)); } for (String s : from.getUnmatches()) { if (expandName2Set == null || !expandName2Set.containsKey(s)) continue; unmatches.addAll(expandName2Set.get(s)); } if (to != null) { matches.addAll(to.getMatches()); unmatches.addAll(to.getUnmatches()); } ret.put(destKeyName, new RouteRule.MatchPair(matches, unmatches)); } } return ret; } }
|
RouteRuleUtils { public static <T extends Collection<String>> Map<String, RouteRule.MatchPair> expandCondition( Map<String, RouteRule.MatchPair> condition, String srcKeyName, String destKeyName, Map<String, T> expandName2Set) { if (null == condition || StringUtils.isEmpty(srcKeyName) || StringUtils.isEmpty(destKeyName)) { return condition; } RouteRule.MatchPair matchPair = condition.get(srcKeyName); if (matchPair == null) { return condition; } Map<String, RouteRule.MatchPair> ret = new HashMap<String, RouteRule.MatchPair>(); Iterator<Entry<String, RouteRule.MatchPair>> iterator = condition.entrySet().iterator(); for (; iterator.hasNext(); ) { Entry<String, RouteRule.MatchPair> entry = iterator.next(); String condName = entry.getKey(); if (!condName.equals(srcKeyName) && !condName.equals(destKeyName)) { RouteRule.MatchPair p = entry.getValue(); if (p != null) ret.put(condName, p); } else if (condName.equals(srcKeyName)) { RouteRule.MatchPair from = condition.get(srcKeyName); RouteRule.MatchPair to = condition.get(destKeyName); if (from == null || from.getMatches().isEmpty() && from.getUnmatches().isEmpty()) { if (to != null) ret.put(destKeyName, to); continue; } Set<String> matches = new HashSet<String>(); Set<String> unmatches = new HashSet<String>(); for (String s : from.getMatches()) { if (expandName2Set == null || !expandName2Set.containsKey(s)) continue; matches.addAll(expandName2Set.get(s)); } for (String s : from.getUnmatches()) { if (expandName2Set == null || !expandName2Set.containsKey(s)) continue; unmatches.addAll(expandName2Set.get(s)); } if (to != null) { matches.addAll(to.getMatches()); unmatches.addAll(to.getUnmatches()); } ret.put(destKeyName, new RouteRule.MatchPair(matches, unmatches)); } } return ret; } private RouteRuleUtils(); }
|
RouteRuleUtils { public static <T extends Collection<String>> Map<String, RouteRule.MatchPair> expandCondition( Map<String, RouteRule.MatchPair> condition, String srcKeyName, String destKeyName, Map<String, T> expandName2Set) { if (null == condition || StringUtils.isEmpty(srcKeyName) || StringUtils.isEmpty(destKeyName)) { return condition; } RouteRule.MatchPair matchPair = condition.get(srcKeyName); if (matchPair == null) { return condition; } Map<String, RouteRule.MatchPair> ret = new HashMap<String, RouteRule.MatchPair>(); Iterator<Entry<String, RouteRule.MatchPair>> iterator = condition.entrySet().iterator(); for (; iterator.hasNext(); ) { Entry<String, RouteRule.MatchPair> entry = iterator.next(); String condName = entry.getKey(); if (!condName.equals(srcKeyName) && !condName.equals(destKeyName)) { RouteRule.MatchPair p = entry.getValue(); if (p != null) ret.put(condName, p); } else if (condName.equals(srcKeyName)) { RouteRule.MatchPair from = condition.get(srcKeyName); RouteRule.MatchPair to = condition.get(destKeyName); if (from == null || from.getMatches().isEmpty() && from.getUnmatches().isEmpty()) { if (to != null) ret.put(destKeyName, to); continue; } Set<String> matches = new HashSet<String>(); Set<String> unmatches = new HashSet<String>(); for (String s : from.getMatches()) { if (expandName2Set == null || !expandName2Set.containsKey(s)) continue; matches.addAll(expandName2Set.get(s)); } for (String s : from.getUnmatches()) { if (expandName2Set == null || !expandName2Set.containsKey(s)) continue; unmatches.addAll(expandName2Set.get(s)); } if (to != null) { matches.addAll(to.getMatches()); unmatches.addAll(to.getUnmatches()); } ret.put(destKeyName, new RouteRule.MatchPair(matches, unmatches)); } } return ret; } private RouteRuleUtils(); static Map<String, RouteRule.MatchPair> expandCondition(
Map<String, RouteRule.MatchPair> condition, String srcKeyName, String destKeyName,
Map<String, T> expandName2Set); static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition,
Map<String, String> valueParams, Map<String, String> kv); static Set<String> filterServiceByRule(List<String> services, RouteRule rule); }
|
RouteRuleUtils { public static <T extends Collection<String>> Map<String, RouteRule.MatchPair> expandCondition( Map<String, RouteRule.MatchPair> condition, String srcKeyName, String destKeyName, Map<String, T> expandName2Set) { if (null == condition || StringUtils.isEmpty(srcKeyName) || StringUtils.isEmpty(destKeyName)) { return condition; } RouteRule.MatchPair matchPair = condition.get(srcKeyName); if (matchPair == null) { return condition; } Map<String, RouteRule.MatchPair> ret = new HashMap<String, RouteRule.MatchPair>(); Iterator<Entry<String, RouteRule.MatchPair>> iterator = condition.entrySet().iterator(); for (; iterator.hasNext(); ) { Entry<String, RouteRule.MatchPair> entry = iterator.next(); String condName = entry.getKey(); if (!condName.equals(srcKeyName) && !condName.equals(destKeyName)) { RouteRule.MatchPair p = entry.getValue(); if (p != null) ret.put(condName, p); } else if (condName.equals(srcKeyName)) { RouteRule.MatchPair from = condition.get(srcKeyName); RouteRule.MatchPair to = condition.get(destKeyName); if (from == null || from.getMatches().isEmpty() && from.getUnmatches().isEmpty()) { if (to != null) ret.put(destKeyName, to); continue; } Set<String> matches = new HashSet<String>(); Set<String> unmatches = new HashSet<String>(); for (String s : from.getMatches()) { if (expandName2Set == null || !expandName2Set.containsKey(s)) continue; matches.addAll(expandName2Set.get(s)); } for (String s : from.getUnmatches()) { if (expandName2Set == null || !expandName2Set.containsKey(s)) continue; unmatches.addAll(expandName2Set.get(s)); } if (to != null) { matches.addAll(to.getMatches()); unmatches.addAll(to.getUnmatches()); } ret.put(destKeyName, new RouteRule.MatchPair(matches, unmatches)); } } return ret; } private RouteRuleUtils(); static Map<String, RouteRule.MatchPair> expandCondition(
Map<String, RouteRule.MatchPair> condition, String srcKeyName, String destKeyName,
Map<String, T> expandName2Set); static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition,
Map<String, String> valueParams, Map<String, String> kv); static Set<String> filterServiceByRule(List<String> services, RouteRule rule); }
|
@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()); }
|
public static Set<String> filterServiceByRule(List<String> services, RouteRule rule) { if (null == services || services.isEmpty() || rule == null) { return new HashSet<String>(); } RouteRule.MatchPair p = rule.getWhenCondition().get("service"); if (p == null) { return new HashSet<String>(); } Set<String> filter = ParseUtils.filterByGlobPattern(p.getMatches(), services); Set<String> set = ParseUtils.filterByGlobPattern(p.getUnmatches(), services); filter.addAll(set); return filter; }
|
RouteRuleUtils { public static Set<String> filterServiceByRule(List<String> services, RouteRule rule) { if (null == services || services.isEmpty() || rule == null) { return new HashSet<String>(); } RouteRule.MatchPair p = rule.getWhenCondition().get("service"); if (p == null) { return new HashSet<String>(); } Set<String> filter = ParseUtils.filterByGlobPattern(p.getMatches(), services); Set<String> set = ParseUtils.filterByGlobPattern(p.getUnmatches(), services); filter.addAll(set); return filter; } }
|
RouteRuleUtils { public static Set<String> filterServiceByRule(List<String> services, RouteRule rule) { if (null == services || services.isEmpty() || rule == null) { return new HashSet<String>(); } RouteRule.MatchPair p = rule.getWhenCondition().get("service"); if (p == null) { return new HashSet<String>(); } Set<String> filter = ParseUtils.filterByGlobPattern(p.getMatches(), services); Set<String> set = ParseUtils.filterByGlobPattern(p.getUnmatches(), services); filter.addAll(set); return filter; } private RouteRuleUtils(); }
|
RouteRuleUtils { public static Set<String> filterServiceByRule(List<String> services, RouteRule rule) { if (null == services || services.isEmpty() || rule == null) { return new HashSet<String>(); } RouteRule.MatchPair p = rule.getWhenCondition().get("service"); if (p == null) { return new HashSet<String>(); } Set<String> filter = ParseUtils.filterByGlobPattern(p.getMatches(), services); Set<String> set = ParseUtils.filterByGlobPattern(p.getUnmatches(), services); filter.addAll(set); return filter; } private RouteRuleUtils(); static Map<String, RouteRule.MatchPair> expandCondition(
Map<String, RouteRule.MatchPair> condition, String srcKeyName, String destKeyName,
Map<String, T> expandName2Set); static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition,
Map<String, String> valueParams, Map<String, String> kv); static Set<String> filterServiceByRule(List<String> services, RouteRule rule); }
|
RouteRuleUtils { public static Set<String> filterServiceByRule(List<String> services, RouteRule rule) { if (null == services || services.isEmpty() || rule == null) { return new HashSet<String>(); } RouteRule.MatchPair p = rule.getWhenCondition().get("service"); if (p == null) { return new HashSet<String>(); } Set<String> filter = ParseUtils.filterByGlobPattern(p.getMatches(), services); Set<String> set = ParseUtils.filterByGlobPattern(p.getUnmatches(), services); filter.addAll(set); return filter; } private RouteRuleUtils(); static Map<String, RouteRule.MatchPair> expandCondition(
Map<String, RouteRule.MatchPair> condition, String srcKeyName, String destKeyName,
Map<String, T> expandName2Set); static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition,
Map<String, String> valueParams, Map<String, String> kv); static Set<String> filterServiceByRule(List<String> services, RouteRule rule); }
|
@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); { 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); 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); }
|
public static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition, Map<String, String> valueParams, Map<String, String> kv) { if (condition != null && condition.size() > 0) { for (Map.Entry<String, RouteRule.MatchPair> entry : condition.entrySet()) { String condName = entry.getKey(); RouteRule.MatchPair p = entry.getValue(); String value = kv.get(condName); Set<String> matches = p.getMatches(); if (matches != null && matches.size() > 0 && !ParseUtils.isMatchGlobPatternsNeedInterpolate(matches, valueParams, value)) { return false; } Set<String> unmatches = p.getUnmatches(); if (unmatches != null && unmatches.size() > 0 && ParseUtils.isMatchGlobPatternsNeedInterpolate(unmatches, valueParams, value)) { return false; } } } return true; }
|
RouteRuleUtils { public static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition, Map<String, String> valueParams, Map<String, String> kv) { if (condition != null && condition.size() > 0) { for (Map.Entry<String, RouteRule.MatchPair> entry : condition.entrySet()) { String condName = entry.getKey(); RouteRule.MatchPair p = entry.getValue(); String value = kv.get(condName); Set<String> matches = p.getMatches(); if (matches != null && matches.size() > 0 && !ParseUtils.isMatchGlobPatternsNeedInterpolate(matches, valueParams, value)) { return false; } Set<String> unmatches = p.getUnmatches(); if (unmatches != null && unmatches.size() > 0 && ParseUtils.isMatchGlobPatternsNeedInterpolate(unmatches, valueParams, value)) { return false; } } } return true; } }
|
RouteRuleUtils { public static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition, Map<String, String> valueParams, Map<String, String> kv) { if (condition != null && condition.size() > 0) { for (Map.Entry<String, RouteRule.MatchPair> entry : condition.entrySet()) { String condName = entry.getKey(); RouteRule.MatchPair p = entry.getValue(); String value = kv.get(condName); Set<String> matches = p.getMatches(); if (matches != null && matches.size() > 0 && !ParseUtils.isMatchGlobPatternsNeedInterpolate(matches, valueParams, value)) { return false; } Set<String> unmatches = p.getUnmatches(); if (unmatches != null && unmatches.size() > 0 && ParseUtils.isMatchGlobPatternsNeedInterpolate(unmatches, valueParams, value)) { return false; } } } return true; } private RouteRuleUtils(); }
|
RouteRuleUtils { public static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition, Map<String, String> valueParams, Map<String, String> kv) { if (condition != null && condition.size() > 0) { for (Map.Entry<String, RouteRule.MatchPair> entry : condition.entrySet()) { String condName = entry.getKey(); RouteRule.MatchPair p = entry.getValue(); String value = kv.get(condName); Set<String> matches = p.getMatches(); if (matches != null && matches.size() > 0 && !ParseUtils.isMatchGlobPatternsNeedInterpolate(matches, valueParams, value)) { return false; } Set<String> unmatches = p.getUnmatches(); if (unmatches != null && unmatches.size() > 0 && ParseUtils.isMatchGlobPatternsNeedInterpolate(unmatches, valueParams, value)) { return false; } } } return true; } private RouteRuleUtils(); static Map<String, RouteRule.MatchPair> expandCondition(
Map<String, RouteRule.MatchPair> condition, String srcKeyName, String destKeyName,
Map<String, T> expandName2Set); static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition,
Map<String, String> valueParams, Map<String, String> kv); static Set<String> filterServiceByRule(List<String> services, RouteRule rule); }
|
RouteRuleUtils { public static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition, Map<String, String> valueParams, Map<String, String> kv) { if (condition != null && condition.size() > 0) { for (Map.Entry<String, RouteRule.MatchPair> entry : condition.entrySet()) { String condName = entry.getKey(); RouteRule.MatchPair p = entry.getValue(); String value = kv.get(condName); Set<String> matches = p.getMatches(); if (matches != null && matches.size() > 0 && !ParseUtils.isMatchGlobPatternsNeedInterpolate(matches, valueParams, value)) { return false; } Set<String> unmatches = p.getUnmatches(); if (unmatches != null && unmatches.size() > 0 && ParseUtils.isMatchGlobPatternsNeedInterpolate(unmatches, valueParams, value)) { return false; } } } return true; } private RouteRuleUtils(); static Map<String, RouteRule.MatchPair> expandCondition(
Map<String, RouteRule.MatchPair> condition, String srcKeyName, String destKeyName,
Map<String, T> expandName2Set); static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition,
Map<String, String> valueParams, Map<String, String> kv); static Set<String> filterServiceByRule(List<String> services, RouteRule rule); }
|
@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()); }
|
public static Set<String> filterServiceByRule(List<String> services, RouteRule rule) { if (null == services || services.isEmpty() || rule == null) { return new HashSet<String>(); } RouteRule.MatchPair p = rule.getWhenCondition().get("service"); if (p == null) { return new HashSet<String>(); } Set<String> filter = ParseUtils.filterByGlobPattern(p.getMatches(), services); Set<String> set = ParseUtils.filterByGlobPattern(p.getUnmatches(), services); filter.addAll(set); return filter; }
|
RouteRuleUtils { public static Set<String> filterServiceByRule(List<String> services, RouteRule rule) { if (null == services || services.isEmpty() || rule == null) { return new HashSet<String>(); } RouteRule.MatchPair p = rule.getWhenCondition().get("service"); if (p == null) { return new HashSet<String>(); } Set<String> filter = ParseUtils.filterByGlobPattern(p.getMatches(), services); Set<String> set = ParseUtils.filterByGlobPattern(p.getUnmatches(), services); filter.addAll(set); return filter; } }
|
RouteRuleUtils { public static Set<String> filterServiceByRule(List<String> services, RouteRule rule) { if (null == services || services.isEmpty() || rule == null) { return new HashSet<String>(); } RouteRule.MatchPair p = rule.getWhenCondition().get("service"); if (p == null) { return new HashSet<String>(); } Set<String> filter = ParseUtils.filterByGlobPattern(p.getMatches(), services); Set<String> set = ParseUtils.filterByGlobPattern(p.getUnmatches(), services); filter.addAll(set); return filter; } private RouteRuleUtils(); }
|
RouteRuleUtils { public static Set<String> filterServiceByRule(List<String> services, RouteRule rule) { if (null == services || services.isEmpty() || rule == null) { return new HashSet<String>(); } RouteRule.MatchPair p = rule.getWhenCondition().get("service"); if (p == null) { return new HashSet<String>(); } Set<String> filter = ParseUtils.filterByGlobPattern(p.getMatches(), services); Set<String> set = ParseUtils.filterByGlobPattern(p.getUnmatches(), services); filter.addAll(set); return filter; } private RouteRuleUtils(); static Map<String, RouteRule.MatchPair> expandCondition(
Map<String, RouteRule.MatchPair> condition, String srcKeyName, String destKeyName,
Map<String, T> expandName2Set); static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition,
Map<String, String> valueParams, Map<String, String> kv); static Set<String> filterServiceByRule(List<String> services, RouteRule rule); }
|
RouteRuleUtils { public static Set<String> filterServiceByRule(List<String> services, RouteRule rule) { if (null == services || services.isEmpty() || rule == null) { return new HashSet<String>(); } RouteRule.MatchPair p = rule.getWhenCondition().get("service"); if (p == null) { return new HashSet<String>(); } Set<String> filter = ParseUtils.filterByGlobPattern(p.getMatches(), services); Set<String> set = ParseUtils.filterByGlobPattern(p.getUnmatches(), services); filter.addAll(set); return filter; } private RouteRuleUtils(); static Map<String, RouteRule.MatchPair> expandCondition(
Map<String, RouteRule.MatchPair> condition, String srcKeyName, String destKeyName,
Map<String, T> expandName2Set); static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition,
Map<String, String> valueParams, Map<String, String> kv); static Set<String> filterServiceByRule(List<String> services, RouteRule rule); }
|
@Test public void testInterpolateDot() throws Exception { String regexp = ParseUtils.interpolate("com.alibaba.morgan.MemberService", new HashMap<String, String>()); assertEquals("com.alibaba.morgan.MemberService", regexp); }
|
public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); static String METHOD_SPLIT; }
|
@Test public void testInterpolateWildcard() throws Exception { String regexp = ParseUtils.interpolate("com.alibaba.morgan.*", new HashMap<String, String>()); assertEquals("com.alibaba.morgan.*", regexp); }
|
public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); static String METHOD_SPLIT; }
|
@Test() public void testTimeoutExceptionCode() { List<Invoker<DemoService>> invokers = new ArrayList<Invoker<DemoService>>(); invokers.add(new Invoker<DemoService>() { public Class<DemoService> getInterface() { return DemoService.class; } public URL getUrl() { return URL.valueOf("dubbo: } public boolean isAvailable() { return false; } public Result invoke(Invocation invocation) throws RpcException { throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "test timeout"); } public void destroy() { } }); Directory<DemoService> directory = new StaticDirectory<DemoService>(invokers); FailoverClusterInvoker<DemoService> failoverClusterInvoker = new FailoverClusterInvoker<DemoService>(directory); try { failoverClusterInvoker.invoke(new RpcInvocation("sayHello", new Class<?>[0], new Object[0])); Assert.fail(); } catch (RpcException e) { Assert.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode()); } ForkingClusterInvoker<DemoService> forkingClusterInvoker = new ForkingClusterInvoker<DemoService>(directory); try { forkingClusterInvoker.invoke(new RpcInvocation("sayHello", new Class<?>[0], new Object[0])); Assert.fail(); } catch (RpcException e) { Assert.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode()); } FailfastClusterInvoker<DemoService> failfastClusterInvoker = new FailfastClusterInvoker<DemoService>(directory); try { failfastClusterInvoker.invoke(new RpcInvocation("sayHello", new Class<?>[0], new Object[0])); Assert.fail(); } catch (RpcException e) { Assert.assertEquals(RpcException.TIMEOUT_EXCEPTION, e.getCode()); } }
|
public Result invoke(final Invocation invocation) throws RpcException { checkWheatherDestoried(); LoadBalance loadbalance; List<Invoker<T>> invokers = list(invocation); if (invokers != null && invokers.size() > 0) { loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl() .getMethodParameter(invocation.getMethodName(), Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE)); } else { loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE); } RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation); return doInvoke(invocation, invokers, loadbalance); }
|
AbstractClusterInvoker implements Invoker<T> { public Result invoke(final Invocation invocation) throws RpcException { checkWheatherDestoried(); LoadBalance loadbalance; List<Invoker<T>> invokers = list(invocation); if (invokers != null && invokers.size() > 0) { loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl() .getMethodParameter(invocation.getMethodName(), Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE)); } else { loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE); } RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation); return doInvoke(invocation, invokers, loadbalance); } }
|
AbstractClusterInvoker implements Invoker<T> { public Result invoke(final Invocation invocation) throws RpcException { checkWheatherDestoried(); LoadBalance loadbalance; List<Invoker<T>> invokers = list(invocation); if (invokers != null && invokers.size() > 0) { loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl() .getMethodParameter(invocation.getMethodName(), Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE)); } else { loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE); } RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation); return doInvoke(invocation, invokers, loadbalance); } AbstractClusterInvoker(Directory<T> directory); AbstractClusterInvoker(Directory<T> directory, URL url); }
|
AbstractClusterInvoker implements Invoker<T> { public Result invoke(final Invocation invocation) throws RpcException { checkWheatherDestoried(); LoadBalance loadbalance; List<Invoker<T>> invokers = list(invocation); if (invokers != null && invokers.size() > 0) { loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl() .getMethodParameter(invocation.getMethodName(), Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE)); } else { loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE); } RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation); return doInvoke(invocation, invokers, loadbalance); } AbstractClusterInvoker(Directory<T> directory); AbstractClusterInvoker(Directory<T> directory, URL url); Class<T> getInterface(); URL getUrl(); boolean isAvailable(); void destroy(); Result invoke(final Invocation invocation); @Override String toString(); }
|
AbstractClusterInvoker implements Invoker<T> { public Result invoke(final Invocation invocation) throws RpcException { checkWheatherDestoried(); LoadBalance loadbalance; List<Invoker<T>> invokers = list(invocation); if (invokers != null && invokers.size() > 0) { loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl() .getMethodParameter(invocation.getMethodName(), Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE)); } else { loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE); } RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation); return doInvoke(invocation, invokers, loadbalance); } AbstractClusterInvoker(Directory<T> directory); AbstractClusterInvoker(Directory<T> directory, URL url); Class<T> getInterface(); URL getUrl(); boolean isAvailable(); void destroy(); Result invoke(final Invocation invocation); @Override String toString(); }
|
@Test public void testInterpolateSequence() throws Exception { String regexp = ParseUtils.interpolate("1.0.[0-9]", new HashMap<String, String>()); assertEquals("1.0.[0-9]", regexp.toString()); }
|
public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); static String METHOD_SPLIT; }
|
@Test public void testInterpolateVariable() throws Exception { Map<String, String> params = new HashMap<String, String>(); params.put("consumer.address", "10.20.130.230"); String regexp = ParseUtils.interpolate("xx$consumer.address", params); assertEquals("xx10.20.130.230", regexp); }
|
public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); static String METHOD_SPLIT; }
|
@Test public void testInterpolateVariableWithParentheses() throws Exception { Map<String, String> params = new HashMap<String, String>(); params.put("consumer.address", "10.20.130.230"); String regexp = ParseUtils.interpolate("xx${consumer.address}yy", params); assertEquals("xx10.20.130.230yy", regexp); }
|
public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); static String METHOD_SPLIT; }
|
@Test public void testInterpolateCollMap_NormalCase() throws Exception { List<String> expressions = new ArrayList<String>(); expressions.add("xx$var1"); expressions.add("yy${var2}zz"); Map<String, String> params = new HashMap<String, String>(); params.put("var1", "CAT"); params.put("var2", "DOG"); List<String> interpolate = ParseUtils.interpolate(expressions, params); List<String> expected = new ArrayList<String>(); expected.add("xxCAT"); expected.add("yyDOGzz"); assertEquals(expected, interpolate); }
|
public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); }
|
ParseUtils { public static String interpolate(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0) { throw new IllegalArgumentException("glob pattern is empty!"); } if (expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = params == null ? null : params.get(key); if (value == null) { value = ""; } matcher.appendReplacement(sb, value); } matcher.appendTail(sb); return sb.toString(); } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); static String METHOD_SPLIT; }
|
@Test public void testIsMatchGlobPattern() throws Exception { assertTrue(ParseUtils.isMatchGlobPattern(null, null)); assertFalse(ParseUtils.isMatchGlobPattern("abc", null)); assertFalse(ParseUtils.isMatchGlobPattern(null, "xxx")); assertTrue(ParseUtils.isMatchGlobPattern("", "")); assertFalse(ParseUtils.isMatchGlobPattern("", "xxx")); assertFalse(ParseUtils.isMatchGlobPattern("abc", "")); assertFalse(ParseUtils.isMatchGlobPattern("a*bc", "")); assertFalse(ParseUtils.isMatchGlobPattern("*abc", "")); assertFalse(ParseUtils.isMatchGlobPattern("abc*", "")); assertTrue(ParseUtils.isMatchGlobPattern("*", "")); assertTrue(ParseUtils.isMatchGlobPattern("*", "xxx")); assertTrue(ParseUtils.isMatchGlobPattern("abc*123", "abc123")); assertTrue(ParseUtils.isMatchGlobPattern("abc*123", "abcXXX123")); assertFalse(ParseUtils.isMatchGlobPattern("abc*123", "abcXXX333")); assertTrue(ParseUtils.isMatchGlobPattern("*abc123", "abc123")); assertTrue(ParseUtils.isMatchGlobPattern("*abc123", "XXXabc123")); assertTrue(ParseUtils.isMatchGlobPattern("*abc123", "abc123abc123")); assertFalse(ParseUtils.isMatchGlobPattern("*abc123", "abc123abc333")); assertTrue(ParseUtils.isMatchGlobPattern("abc123*", "abc123")); assertTrue(ParseUtils.isMatchGlobPattern("abc123*", "abc123YYY")); assertTrue(ParseUtils.isMatchGlobPattern("abc123*", "abc123abc123")); assertFalse(ParseUtils.isMatchGlobPattern("abc123*", "abc333abc123")); assertFalse(ParseUtils.isMatchGlobPattern("*abc123*", "abc123abc123")); assertTrue(ParseUtils.isMatchGlobPattern("*abc123*", "*abc123abc123")); assertTrue(ParseUtils.isMatchGlobPattern("*abc123*", "*abc123XXX")); }
|
public static boolean isMatchGlobPattern(String pattern, String value) { if ("*".equals(pattern)) return true; if ((pattern == null || pattern.length() == 0) && (value == null || value.length() == 0)) return true; if ((pattern == null || pattern.length() == 0) || (value == null || value.length() == 0)) return false; int i = pattern.lastIndexOf('*'); if (i == -1) { return value.equals(pattern); } else if (i == pattern.length() - 1) { return value.startsWith(pattern.substring(0, i)); } else if (i == 0) { return value.endsWith(pattern.substring(i + 1)); } else { String prefix = pattern.substring(0, i); String suffix = pattern.substring(i + 1); return value.startsWith(prefix) && value.endsWith(suffix); } }
|
ParseUtils { public static boolean isMatchGlobPattern(String pattern, String value) { if ("*".equals(pattern)) return true; if ((pattern == null || pattern.length() == 0) && (value == null || value.length() == 0)) return true; if ((pattern == null || pattern.length() == 0) || (value == null || value.length() == 0)) return false; int i = pattern.lastIndexOf('*'); if (i == -1) { return value.equals(pattern); } else if (i == pattern.length() - 1) { return value.startsWith(pattern.substring(0, i)); } else if (i == 0) { return value.endsWith(pattern.substring(i + 1)); } else { String prefix = pattern.substring(0, i); String suffix = pattern.substring(i + 1); return value.startsWith(prefix) && value.endsWith(suffix); } } }
|
ParseUtils { public static boolean isMatchGlobPattern(String pattern, String value) { if ("*".equals(pattern)) return true; if ((pattern == null || pattern.length() == 0) && (value == null || value.length() == 0)) return true; if ((pattern == null || pattern.length() == 0) || (value == null || value.length() == 0)) return false; int i = pattern.lastIndexOf('*'); if (i == -1) { return value.equals(pattern); } else if (i == pattern.length() - 1) { return value.startsWith(pattern.substring(0, i)); } else if (i == 0) { return value.endsWith(pattern.substring(i + 1)); } else { String prefix = pattern.substring(0, i); String suffix = pattern.substring(i + 1); return value.startsWith(prefix) && value.endsWith(suffix); } } private ParseUtils(); }
|
ParseUtils { public static boolean isMatchGlobPattern(String pattern, String value) { if ("*".equals(pattern)) return true; if ((pattern == null || pattern.length() == 0) && (value == null || value.length() == 0)) return true; if ((pattern == null || pattern.length() == 0) || (value == null || value.length() == 0)) return false; int i = pattern.lastIndexOf('*'); if (i == -1) { return value.equals(pattern); } else if (i == pattern.length() - 1) { return value.startsWith(pattern.substring(0, i)); } else if (i == 0) { return value.endsWith(pattern.substring(i + 1)); } else { String prefix = pattern.substring(0, i); String suffix = pattern.substring(i + 1); return value.startsWith(prefix) && value.endsWith(suffix); } } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); }
|
ParseUtils { public static boolean isMatchGlobPattern(String pattern, String value) { if ("*".equals(pattern)) return true; if ((pattern == null || pattern.length() == 0) && (value == null || value.length() == 0)) return true; if ((pattern == null || pattern.length() == 0) || (value == null || value.length() == 0)) return false; int i = pattern.lastIndexOf('*'); if (i == -1) { return value.equals(pattern); } else if (i == pattern.length() - 1) { return value.startsWith(pattern.substring(0, i)); } else if (i == 0) { return value.endsWith(pattern.substring(i + 1)); } else { String prefix = pattern.substring(0, i); String suffix = pattern.substring(i + 1); return value.startsWith(prefix) && value.endsWith(suffix); } } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); static String METHOD_SPLIT; }
|
@Test public void testIsMatchGlobPatternsNeedInterpolate() throws Exception { Collection<String> patternsNeedInterpolate = new HashSet<String>(); Map<String, String> interpolateParams = new HashMap<String, String>(); boolean match = ParseUtils.isMatchGlobPatternsNeedInterpolate(patternsNeedInterpolate, interpolateParams, "abc"); assertFalse(match); patternsNeedInterpolate.add("abc*$var1"); patternsNeedInterpolate.add("123${var2}*"); interpolateParams.put("var1", "CAT"); interpolateParams.put("var2", "DOG"); match = ParseUtils.isMatchGlobPatternsNeedInterpolate(patternsNeedInterpolate, interpolateParams, "abc"); assertFalse(match); match = ParseUtils.isMatchGlobPatternsNeedInterpolate(patternsNeedInterpolate, interpolateParams, "abcXXXCAT"); assertTrue(match); match = ParseUtils.isMatchGlobPatternsNeedInterpolate(patternsNeedInterpolate, interpolateParams, "123DOGYYY"); assertTrue(match); }
|
public static boolean isMatchGlobPatternsNeedInterpolate( Collection<String> patternsNeedInterpolate, Map<String, String> interpolateParams, String value) { if (patternsNeedInterpolate != null && !patternsNeedInterpolate.isEmpty()) { for (String patternNeedItp : patternsNeedInterpolate) { if (StringUtils.isEmpty(patternNeedItp)) { continue; } String pattern = interpolate(patternNeedItp, interpolateParams); if (isMatchGlobPattern(pattern, value)) { return true; } } } return false; }
|
ParseUtils { public static boolean isMatchGlobPatternsNeedInterpolate( Collection<String> patternsNeedInterpolate, Map<String, String> interpolateParams, String value) { if (patternsNeedInterpolate != null && !patternsNeedInterpolate.isEmpty()) { for (String patternNeedItp : patternsNeedInterpolate) { if (StringUtils.isEmpty(patternNeedItp)) { continue; } String pattern = interpolate(patternNeedItp, interpolateParams); if (isMatchGlobPattern(pattern, value)) { return true; } } } return false; } }
|
ParseUtils { public static boolean isMatchGlobPatternsNeedInterpolate( Collection<String> patternsNeedInterpolate, Map<String, String> interpolateParams, String value) { if (patternsNeedInterpolate != null && !patternsNeedInterpolate.isEmpty()) { for (String patternNeedItp : patternsNeedInterpolate) { if (StringUtils.isEmpty(patternNeedItp)) { continue; } String pattern = interpolate(patternNeedItp, interpolateParams); if (isMatchGlobPattern(pattern, value)) { return true; } } } return false; } private ParseUtils(); }
|
ParseUtils { public static boolean isMatchGlobPatternsNeedInterpolate( Collection<String> patternsNeedInterpolate, Map<String, String> interpolateParams, String value) { if (patternsNeedInterpolate != null && !patternsNeedInterpolate.isEmpty()) { for (String patternNeedItp : patternsNeedInterpolate) { if (StringUtils.isEmpty(patternNeedItp)) { continue; } String pattern = interpolate(patternNeedItp, interpolateParams); if (isMatchGlobPattern(pattern, value)) { return true; } } } return false; } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); }
|
ParseUtils { public static boolean isMatchGlobPatternsNeedInterpolate( Collection<String> patternsNeedInterpolate, Map<String, String> interpolateParams, String value) { if (patternsNeedInterpolate != null && !patternsNeedInterpolate.isEmpty()) { for (String patternNeedItp : patternsNeedInterpolate) { if (StringUtils.isEmpty(patternNeedItp)) { continue; } String pattern = interpolate(patternNeedItp, interpolateParams); if (isMatchGlobPattern(pattern, value)) { return true; } } } return false; } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); static String METHOD_SPLIT; }
|
@Test public void test_hasIntersection() throws Exception { assertFalse(ParseUtils.hasIntersection(null, null)); assertFalse(ParseUtils.hasIntersection("dog", null)); assertFalse(ParseUtils.hasIntersection(null, "god")); assertTrue(ParseUtils.hasIntersection("hello", "hello*")); assertTrue(ParseUtils.hasIntersection("helloxxx", "hello*")); assertTrue(ParseUtils.hasIntersection("world", "*world")); assertTrue(ParseUtils.hasIntersection("xxxworld", "*world")); assertTrue(ParseUtils.hasIntersection("helloworld", "hello*world")); assertTrue(ParseUtils.hasIntersection("helloxxxworld", "hello*world")); assertFalse(ParseUtils.hasIntersection("Yhelloxxxworld", "hello*world")); assertTrue(ParseUtils.hasIntersection("hello*", "hello")); assertTrue(ParseUtils.hasIntersection("hello*", "helloxxx")); assertTrue(ParseUtils.hasIntersection("*world", "world")); assertTrue(ParseUtils.hasIntersection("*world", "xxxworld")); assertTrue(ParseUtils.hasIntersection("hello*world", "helloworld")); assertTrue(ParseUtils.hasIntersection("hello*world", "helloxxxworld")); assertFalse(ParseUtils.hasIntersection("hello*world", "Yhelloxxxworld")); assertTrue(ParseUtils.hasIntersection("*world", "hello*world")); assertTrue(ParseUtils.hasIntersection("*world", "hello*Zworld")); assertTrue(ParseUtils.hasIntersection("helloZ*", "hello*world")); assertFalse(ParseUtils.hasIntersection("Zhello*", "hello*world")); assertFalse(ParseUtils.hasIntersection("hello*world", "hello*worldZ")); assertTrue(ParseUtils.hasIntersection("hello*world", "hello*world")); assertTrue(ParseUtils.hasIntersection("hello*world", "hello*Zworld")); assertTrue(ParseUtils.hasIntersection("helloZ*world", "hello*world")); assertFalse(ParseUtils.hasIntersection("Zhello*world", "hello*world")); assertFalse(ParseUtils.hasIntersection("hello*world", "hello*worldZ")); }
|
public static boolean hasIntersection(String glob1, String glob2) { if (null == glob1 || null == glob2) { return false; } if (glob1.contains("*") && glob2.contains("*")) { int index1 = glob1.indexOf("*"); int index2 = glob2.indexOf("*"); String s11 = glob1.substring(0, index1); String s12 = glob1.substring(index1 + 1, glob1.length()); String s21 = glob2.substring(0, index2); String s22 = glob2.substring(index2 + 1, glob2.length()); if (!s11.startsWith(s21) && !s21.startsWith(s11)) return false; if (!s12.endsWith(s22) && !s22.endsWith(s12)) return false; return true; } else if (glob1.contains("*")) { return isMatchGlobPattern(glob1, glob2); } else if (glob2.contains("*")) { return isMatchGlobPattern(glob2, glob1); } else { return glob1.equals(glob2); } }
|
ParseUtils { public static boolean hasIntersection(String glob1, String glob2) { if (null == glob1 || null == glob2) { return false; } if (glob1.contains("*") && glob2.contains("*")) { int index1 = glob1.indexOf("*"); int index2 = glob2.indexOf("*"); String s11 = glob1.substring(0, index1); String s12 = glob1.substring(index1 + 1, glob1.length()); String s21 = glob2.substring(0, index2); String s22 = glob2.substring(index2 + 1, glob2.length()); if (!s11.startsWith(s21) && !s21.startsWith(s11)) return false; if (!s12.endsWith(s22) && !s22.endsWith(s12)) return false; return true; } else if (glob1.contains("*")) { return isMatchGlobPattern(glob1, glob2); } else if (glob2.contains("*")) { return isMatchGlobPattern(glob2, glob1); } else { return glob1.equals(glob2); } } }
|
ParseUtils { public static boolean hasIntersection(String glob1, String glob2) { if (null == glob1 || null == glob2) { return false; } if (glob1.contains("*") && glob2.contains("*")) { int index1 = glob1.indexOf("*"); int index2 = glob2.indexOf("*"); String s11 = glob1.substring(0, index1); String s12 = glob1.substring(index1 + 1, glob1.length()); String s21 = glob2.substring(0, index2); String s22 = glob2.substring(index2 + 1, glob2.length()); if (!s11.startsWith(s21) && !s21.startsWith(s11)) return false; if (!s12.endsWith(s22) && !s22.endsWith(s12)) return false; return true; } else if (glob1.contains("*")) { return isMatchGlobPattern(glob1, glob2); } else if (glob2.contains("*")) { return isMatchGlobPattern(glob2, glob1); } else { return glob1.equals(glob2); } } private ParseUtils(); }
|
ParseUtils { public static boolean hasIntersection(String glob1, String glob2) { if (null == glob1 || null == glob2) { return false; } if (glob1.contains("*") && glob2.contains("*")) { int index1 = glob1.indexOf("*"); int index2 = glob2.indexOf("*"); String s11 = glob1.substring(0, index1); String s12 = glob1.substring(index1 + 1, glob1.length()); String s21 = glob2.substring(0, index2); String s22 = glob2.substring(index2 + 1, glob2.length()); if (!s11.startsWith(s21) && !s21.startsWith(s11)) return false; if (!s12.endsWith(s22) && !s22.endsWith(s12)) return false; return true; } else if (glob1.contains("*")) { return isMatchGlobPattern(glob1, glob2); } else if (glob2.contains("*")) { return isMatchGlobPattern(glob2, glob1); } else { return glob1.equals(glob2); } } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); }
|
ParseUtils { public static boolean hasIntersection(String glob1, String glob2) { if (null == glob1 || null == glob2) { return false; } if (glob1.contains("*") && glob2.contains("*")) { int index1 = glob1.indexOf("*"); int index2 = glob2.indexOf("*"); String s11 = glob1.substring(0, index1); String s12 = glob1.substring(index1 + 1, glob1.length()); String s21 = glob2.substring(0, index2); String s22 = glob2.substring(index2 + 1, glob2.length()); if (!s11.startsWith(s21) && !s21.startsWith(s11)) return false; if (!s12.endsWith(s22) && !s22.endsWith(s12)) return false; return true; } else if (glob1.contains("*")) { return isMatchGlobPattern(glob1, glob2); } else if (glob2.contains("*")) { return isMatchGlobPattern(glob2, glob1); } else { return glob1.equals(glob2); } } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); static String METHOD_SPLIT; }
|
@Test public void testFilterByGlobPattern() throws Exception { Collection<String> values = new ArrayList<String>(); values.add("abc123"); values.add("JQKxyz"); values.add("abc123"); values.add("abcLLL"); Set<String> filter = ParseUtils.filterByGlobPattern("abc*", values); Set<String> expected = new HashSet<String>(); expected.add("abc123"); expected.add("abcLLL"); assertEquals(expected, filter); filter = ParseUtils.filterByGlobPattern((Collection<String>) null, values); assertTrue(filter.isEmpty()); Collection<String> patterns = new ArrayList<String>(); patterns.add("000000000"); patterns.add("abc*"); patterns.add("*xyz"); filter = ParseUtils.filterByGlobPattern(patterns, values); expected.add("JQKxyz"); assertEquals(expected, filter); }
|
public static Set<String> filterByGlobPattern(String pattern, Collection<String> values) { Set<String> ret = new HashSet<String>(); if (pattern == null || values == null) { return ret; } for (String v : values) { if (isMatchGlobPattern(pattern, v)) { ret.add(v); } } return ret; }
|
ParseUtils { public static Set<String> filterByGlobPattern(String pattern, Collection<String> values) { Set<String> ret = new HashSet<String>(); if (pattern == null || values == null) { return ret; } for (String v : values) { if (isMatchGlobPattern(pattern, v)) { ret.add(v); } } return ret; } }
|
ParseUtils { public static Set<String> filterByGlobPattern(String pattern, Collection<String> values) { Set<String> ret = new HashSet<String>(); if (pattern == null || values == null) { return ret; } for (String v : values) { if (isMatchGlobPattern(pattern, v)) { ret.add(v); } } return ret; } private ParseUtils(); }
|
ParseUtils { public static Set<String> filterByGlobPattern(String pattern, Collection<String> values) { Set<String> ret = new HashSet<String>(); if (pattern == null || values == null) { return ret; } for (String v : values) { if (isMatchGlobPattern(pattern, v)) { ret.add(v); } } return ret; } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); }
|
ParseUtils { public static Set<String> filterByGlobPattern(String pattern, Collection<String> values) { Set<String> ret = new HashSet<String>(); if (pattern == null || values == null) { return ret; } for (String v : values) { if (isMatchGlobPattern(pattern, v)) { ret.add(v); } } return ret; } private ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); static String METHOD_SPLIT; }
|
@Test public void test_matchRoute() throws Exception { Route route = new Route(); route.setId(1L); route.setPriority(3); route.setMatchRule("consumer.host = 1.1.2.2"); route.setFilterRule("xxx = yyy"); routes.add(route); { assertTrue(RouteUtils.matchRoute("1.1.2.2:20880", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters)); assertFalse(RouteUtils.matchRoute("9.9.9.9", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters)); route.setMatchRule("consumer.host = 1.1.2.2 & consumer.application = kylin"); assertTrue(RouteUtils.matchRoute("1.1.2.2", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters)); route.setMatchRule("consumer.host = 1.1.2.2 & consumer.application = notExstied"); assertFalse(RouteUtils.matchRoute("1.1.2.2", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say&application=kylin", route, clusters)); } { route.setMatchRule("consumer.cluster = cluster1"); assertTrue(RouteUtils.matchRoute("7.7.7.7:20880", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters)); assertFalse(RouteUtils.matchRoute("9.9.9.9", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters)); route.setMatchRule("consumer.cluster = cluster1 & consumer.application = kylin"); assertTrue(RouteUtils.matchRoute("7.7.7.7", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters)); route.setMatchRule("consumer.cluster = cluster1 & consumer.application = notExstied"); assertFalse(RouteUtils.matchRoute("7.7.7.7", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say&application=kylin", route, clusters)); } }
|
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); }
|
RouteUtils { 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); } }
|
RouteUtils { 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); } }
|
RouteUtils { 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); } static boolean matchRoute(String consumerAddress, String consumerQueryUrl, Route route, Map<String, List<String>> clusters); 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); static List<Route> findUsedRoute(String serviceName, String consumerAddress, String consumerQueryUrl,
List<Route> routes, Map<String, List<String>> clusters); static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers,
List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); static Map<String, String> route(String serviceName, String consumerAddress, String consumerQueryUrl, Map<String, String> serviceUrls,
List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); }
|
RouteUtils { 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); } static boolean matchRoute(String consumerAddress, String consumerQueryUrl, Route route, Map<String, List<String>> clusters); 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); static List<Route> findUsedRoute(String serviceName, String consumerAddress, String consumerQueryUrl,
List<Route> routes, Map<String, List<String>> clusters); static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers,
List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); static Map<String, String> route(String serviceName, String consumerAddress, String consumerQueryUrl, Map<String, String> serviceUrls,
List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); }
|
@Test public void test_previewRoute() throws Exception { Route route = new Route(); route.setId(1L); route.setService("hello.HelloService"); route.setMatchRule("consumer.host=1.1.2.2,2.2.2.3"); route.setFilterRule("provider.host=3.3.4.4&provider.application=morgan"); { Map<String, String> preview = RouteUtils.previewRoute("hello.HelloService", "1.1.2.2:20880", "application=morgan", serviceUrls, route, clusters, null); Map<String, String> expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, preview); preview = RouteUtils.previewRoute("hello.HelloService", "1.1.2.2", "application=morgan&methods=getPort,say", serviceUrls, route, clusters, null); expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, preview); preview = RouteUtils.previewRoute("hello.HelloService", "1.1.2.2", "application=morgan&methods=getPort,say,ghostMethod", serviceUrls, route, clusters, null); expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, preview); preview = RouteUtils.previewRoute("hello.HelloService", "1.2.3.4", "application=morgan", serviceUrls, route, clusters, null); assertEquals(serviceUrls_starMethods, preview); preview = RouteUtils.previewRoute("hello.HelloService", "1.2.3.4", "application=morgan&methods=getPort,say", serviceUrls, route, clusters, null); assertEquals(serviceUrls, preview); preview = RouteUtils.previewRoute("hello.HelloService", "1.2.3.4", "application=morgan&methods=getPort,say,ghostMethod", serviceUrls, route, clusters, null); assertEquals(serviceUrls_ghostMethods, preview); } { route.setMatchRule("consumer.cluster = cluster1"); Map<String, String> preview = RouteUtils.previewRoute("hello.HelloService", "7.7.7.7:20880", "application=morgan", serviceUrls, route, clusters, null); Map<String, String> expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, preview); preview = RouteUtils.previewRoute("hello.HelloService", "7.7.7.7", "application=morgan&methods=getPort,say", serviceUrls, route, clusters, null); expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, preview); preview = RouteUtils.previewRoute("hello.HelloService", "7.7.7.7", "application=morgan&methods=getPort,say,ghostMethod", serviceUrls, route, clusters, null); expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, preview); preview = RouteUtils.previewRoute("hello.HelloService", "1.2.3.4", "application=morgan", serviceUrls, route, clusters, null); assertEquals(serviceUrls_starMethods, preview); preview = RouteUtils.previewRoute("hello.HelloService", "1.2.3.4", "application=morgan&methods=getPort,say", serviceUrls, route, clusters, null); assertEquals(serviceUrls, preview); preview = RouteUtils.previewRoute("hello.HelloService", "1.2.3.4", "application=morgan&methods=getPort,say,ghostMethod", serviceUrls, route, clusters, null); assertEquals(serviceUrls_ghostMethods, preview); } }
|
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); }
|
RouteUtils { 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); } }
|
RouteUtils { 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); } }
|
RouteUtils { 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); } static boolean matchRoute(String consumerAddress, String consumerQueryUrl, Route route, Map<String, List<String>> clusters); 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); static List<Route> findUsedRoute(String serviceName, String consumerAddress, String consumerQueryUrl,
List<Route> routes, Map<String, List<String>> clusters); static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers,
List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); static Map<String, String> route(String serviceName, String consumerAddress, String consumerQueryUrl, Map<String, String> serviceUrls,
List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); }
|
RouteUtils { 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); } static boolean matchRoute(String consumerAddress, String consumerQueryUrl, Route route, Map<String, List<String>> clusters); 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); static List<Route> findUsedRoute(String serviceName, String consumerAddress, String consumerQueryUrl,
List<Route> routes, Map<String, List<String>> clusters); static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers,
List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); static Map<String, String> route(String serviceName, String consumerAddress, String consumerQueryUrl, Map<String, String> serviceUrls,
List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); }
|
@Test public void testRoute() throws Exception { { Map<String, String> result = RouteUtils.route("hello.HelloService:1.0.0", "1.1.2.2:20880", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", serviceUrls, routes, clusters, null); Map<String, String> expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, result); result = RouteUtils.route("cn/hello.HelloService", "1.1.2.2", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say&application=kylin", serviceUrls, routes, clusters, null); expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, result); result = RouteUtils.route("cn/hello.HelloService:2.0.0", "1.1.2.2", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say,ghostMethod&application=kylin", serviceUrls, routes, clusters, null); expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, result); result = RouteUtils.route("hello.HelloService", "1.2.3.4", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", serviceUrls, routes, clusters, null); assertEquals(serviceUrls_starMethods, result); result = RouteUtils.route("hello.HelloService", "1.2.3.4", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say&application=kylin", serviceUrls, routes, clusters, null); assertEquals(serviceUrls, result); result = RouteUtils.route("hello.HelloService", "1.2.3.4", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say,ghostMethod&application=kylin", serviceUrls, routes, clusters, null); assertEquals(serviceUrls_ghostMethods, result); } { routes.get(0).setMatchRule("consumer.cluster = cluster1"); Map<String, String> result = RouteUtils.route("hello.HelloService", "7.7.7.7:20880", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", serviceUrls, routes, clusters, null); Map<String, String> expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, result); result = RouteUtils.route("hello.HelloService", "7.7.7.7", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say&application=kylin", serviceUrls, routes, clusters, null); expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, result); result = RouteUtils.route("hello.HelloService", "7.7.7.7", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say,ghostMethod&application=kylin", serviceUrls, routes, clusters, null); expected = new HashMap<String, String>(); expected.put("dubbo: assertEquals(expected, result); result = RouteUtils.route("hello.HelloService", "1.2.3.4", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", serviceUrls, routes, clusters, null); assertEquals(serviceUrls_starMethods, result); result = RouteUtils.route("hello.HelloService", "1.2.3.4", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say&application=kylin", serviceUrls, routes, clusters, null); assertEquals(serviceUrls, result); result = RouteUtils.route("hello.HelloService", "1.2.3.4", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say,ghostMethod&application=kylin", serviceUrls, routes, clusters, null); assertEquals(serviceUrls_ghostMethods, result); } }
|
public static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers, List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed) { if (providers == null) { return null; } Map<String, String> urls = new HashMap<String, String>(); urls.put("consumer: for (Provider provider : providers) { if (com.alibaba.dubbo.governance.web.common.pulltool.Tool.isProviderEnabled(provider, overrides)) { urls.put(provider.getUrl(), provider.getParameters()); } } urls = RouteUtils.route(serviceName, consumerAddress, consumerQueryUrl, urls, routes, clusters, routed); List<Provider> result = new ArrayList<Provider>(); for (Provider provider : providers) { if (urls.containsKey(provider.getUrl())) { result.add(provider); } } return result; }
|
RouteUtils { public static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers, List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed) { if (providers == null) { return null; } Map<String, String> urls = new HashMap<String, String>(); urls.put("consumer: for (Provider provider : providers) { if (com.alibaba.dubbo.governance.web.common.pulltool.Tool.isProviderEnabled(provider, overrides)) { urls.put(provider.getUrl(), provider.getParameters()); } } urls = RouteUtils.route(serviceName, consumerAddress, consumerQueryUrl, urls, routes, clusters, routed); List<Provider> result = new ArrayList<Provider>(); for (Provider provider : providers) { if (urls.containsKey(provider.getUrl())) { result.add(provider); } } return result; } }
|
RouteUtils { public static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers, List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed) { if (providers == null) { return null; } Map<String, String> urls = new HashMap<String, String>(); urls.put("consumer: for (Provider provider : providers) { if (com.alibaba.dubbo.governance.web.common.pulltool.Tool.isProviderEnabled(provider, overrides)) { urls.put(provider.getUrl(), provider.getParameters()); } } urls = RouteUtils.route(serviceName, consumerAddress, consumerQueryUrl, urls, routes, clusters, routed); List<Provider> result = new ArrayList<Provider>(); for (Provider provider : providers) { if (urls.containsKey(provider.getUrl())) { result.add(provider); } } return result; } }
|
RouteUtils { public static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers, List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed) { if (providers == null) { return null; } Map<String, String> urls = new HashMap<String, String>(); urls.put("consumer: for (Provider provider : providers) { if (com.alibaba.dubbo.governance.web.common.pulltool.Tool.isProviderEnabled(provider, overrides)) { urls.put(provider.getUrl(), provider.getParameters()); } } urls = RouteUtils.route(serviceName, consumerAddress, consumerQueryUrl, urls, routes, clusters, routed); List<Provider> result = new ArrayList<Provider>(); for (Provider provider : providers) { if (urls.containsKey(provider.getUrl())) { result.add(provider); } } return result; } static boolean matchRoute(String consumerAddress, String consumerQueryUrl, Route route, Map<String, List<String>> clusters); 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); static List<Route> findUsedRoute(String serviceName, String consumerAddress, String consumerQueryUrl,
List<Route> routes, Map<String, List<String>> clusters); static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers,
List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); static Map<String, String> route(String serviceName, String consumerAddress, String consumerQueryUrl, Map<String, String> serviceUrls,
List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); }
|
RouteUtils { public static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers, List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed) { if (providers == null) { return null; } Map<String, String> urls = new HashMap<String, String>(); urls.put("consumer: for (Provider provider : providers) { if (com.alibaba.dubbo.governance.web.common.pulltool.Tool.isProviderEnabled(provider, overrides)) { urls.put(provider.getUrl(), provider.getParameters()); } } urls = RouteUtils.route(serviceName, consumerAddress, consumerQueryUrl, urls, routes, clusters, routed); List<Provider> result = new ArrayList<Provider>(); for (Provider provider : providers) { if (urls.containsKey(provider.getUrl())) { result.add(provider); } } return result; } static boolean matchRoute(String consumerAddress, String consumerQueryUrl, Route route, Map<String, List<String>> clusters); 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); static List<Route> findUsedRoute(String serviceName, String consumerAddress, String consumerQueryUrl,
List<Route> routes, Map<String, List<String>> clusters); static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers,
List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); static Map<String, String> route(String serviceName, String consumerAddress, String consumerQueryUrl, Map<String, String> serviceUrls,
List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); }
|
@Test public void testMockInvokerInvoke_normal() { URL url = URL.valueOf("remote: url = url.addParameter(Constants.MOCK_KEY, "fail"); Invoker<IHelloService> cluster = getClusterInvoker(url); URL mockUrl = URL.valueOf("mock: + "?getSomething.mock=return aa"); Protocol protocol = new MockProtocol(); Invoker<IHelloService> mInvoker1 = protocol.refer(IHelloService.class, mockUrl); invokers.add(mInvoker1); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getSomething"); Result ret = cluster.invoke(invocation); Assert.assertEquals("something", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("sayHello"); ret = cluster.invoke(invocation); Assert.assertEquals(null, ret.getValue()); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void test_isSerivceNameMatched() throws Exception { assertTrue(RouteUtils.isSerivceNameMatched("com.alibaba.morgan.MemberService", "com.alibaba.morgan.MemberService:1.0.0")); assertTrue(RouteUtils.isSerivceNameMatched("com.alibaba.morgan.MemberService", "cn/com.alibaba.morgan.MemberService:1.0.0")); assertTrue(RouteUtils.isSerivceNameMatched("com.alibaba.morgan.MemberService", "cn/com.alibaba.morgan.MemberService")); assertTrue(RouteUtils.isSerivceNameMatched("com.alibaba.morgan.MemberService", "com.alibaba.morgan.MemberService")); assertTrue(RouteUtils.isSerivceNameMatched("com.alibaba.morgan.Member*", "com.alibaba.morgan.MemberService:1.0.0")); assertTrue(RouteUtils.isSerivceNameMatched("com.alibaba.morgan.Member*", "cn/com.alibaba.morgan.MemberService:1.0.0")); assertTrue(RouteUtils.isSerivceNameMatched("com.alibaba.morgan.Member*", "cn/com.alibaba.morgan.MemberService")); assertTrue(RouteUtils.isSerivceNameMatched("com.alibaba.morgan.Member*", "com.alibaba.morgan.MemberService")); assertFalse(RouteUtils.isSerivceNameMatched("cn/com.alibaba.morgan.Member*", "com.alibaba.morgan.MemberService:1.0.0")); assertTrue(RouteUtils.isSerivceNameMatched("cn/com.alibaba.morgan.MemberService", "cn/com.alibaba.morgan.MemberService:1.0.0")); assertTrue(RouteUtils.isSerivceNameMatched("cn/com.alibaba.morgan.Member*", "cn/com.alibaba.morgan.MemberService")); assertFalse(RouteUtils.isSerivceNameMatched("cn/com.alibaba.morgan.Member*", "intl/com.alibaba.morgan.MemberService")); assertFalse(RouteUtils.isSerivceNameMatched("cn/com.alibaba.morgan.Member*", "com.alibaba.morgan.MemberService")); assertTrue(RouteUtils.isSerivceNameMatched("com.alibaba.morgan.Member*:1.0.0", "com.alibaba.morgan.MemberService:1.0.0")); assertTrue(RouteUtils.isSerivceNameMatched("com.alibaba.morgan.MemberService:1.0.0", "cn/com.alibaba.morgan.MemberService:1.0.0")); assertFalse(RouteUtils.isSerivceNameMatched("com.alibaba.morgan.MemberService:1.0.0", "cn/com.alibaba.morgan.MemberService:2.0.0")); assertFalse(RouteUtils.isSerivceNameMatched("com.alibaba.morgan.Member*:1.0.0", "cn/com.alibaba.morgan.MemberService")); assertFalse(RouteUtils.isSerivceNameMatched("com.alibaba.morgan.Member*:1.0.0", "com.alibaba.morgan.MemberService")); }
|
static boolean isSerivceNameMatched(String servicePattern, String serviceName) { final int pip = servicePattern.indexOf('/'); final int pi = serviceName.indexOf('/'); if (pip != -1) { if (pi == -1) return false; String gp = servicePattern.substring(0, pip); servicePattern = servicePattern.substring(pip + 1); String g = serviceName.substring(0, pi); if (!gp.equals(g)) return false; } if (pi != -1) serviceName = serviceName.substring(pi + 1); final int vip = servicePattern.lastIndexOf(':'); final int vi = serviceName.lastIndexOf(':'); if (vip != -1) { if (vi == -1) return false; String vp = servicePattern.substring(vip + 1); servicePattern = servicePattern.substring(0, vip); String v = serviceName.substring(vi + 1); if (!vp.equals(v)) return false; } if (vi != -1) serviceName = serviceName.substring(0, vi); return ParseUtils.isMatchGlobPattern(servicePattern, serviceName); }
|
RouteUtils { static boolean isSerivceNameMatched(String servicePattern, String serviceName) { final int pip = servicePattern.indexOf('/'); final int pi = serviceName.indexOf('/'); if (pip != -1) { if (pi == -1) return false; String gp = servicePattern.substring(0, pip); servicePattern = servicePattern.substring(pip + 1); String g = serviceName.substring(0, pi); if (!gp.equals(g)) return false; } if (pi != -1) serviceName = serviceName.substring(pi + 1); final int vip = servicePattern.lastIndexOf(':'); final int vi = serviceName.lastIndexOf(':'); if (vip != -1) { if (vi == -1) return false; String vp = servicePattern.substring(vip + 1); servicePattern = servicePattern.substring(0, vip); String v = serviceName.substring(vi + 1); if (!vp.equals(v)) return false; } if (vi != -1) serviceName = serviceName.substring(0, vi); return ParseUtils.isMatchGlobPattern(servicePattern, serviceName); } }
|
RouteUtils { static boolean isSerivceNameMatched(String servicePattern, String serviceName) { final int pip = servicePattern.indexOf('/'); final int pi = serviceName.indexOf('/'); if (pip != -1) { if (pi == -1) return false; String gp = servicePattern.substring(0, pip); servicePattern = servicePattern.substring(pip + 1); String g = serviceName.substring(0, pi); if (!gp.equals(g)) return false; } if (pi != -1) serviceName = serviceName.substring(pi + 1); final int vip = servicePattern.lastIndexOf(':'); final int vi = serviceName.lastIndexOf(':'); if (vip != -1) { if (vi == -1) return false; String vp = servicePattern.substring(vip + 1); servicePattern = servicePattern.substring(0, vip); String v = serviceName.substring(vi + 1); if (!vp.equals(v)) return false; } if (vi != -1) serviceName = serviceName.substring(0, vi); return ParseUtils.isMatchGlobPattern(servicePattern, serviceName); } }
|
RouteUtils { static boolean isSerivceNameMatched(String servicePattern, String serviceName) { final int pip = servicePattern.indexOf('/'); final int pi = serviceName.indexOf('/'); if (pip != -1) { if (pi == -1) return false; String gp = servicePattern.substring(0, pip); servicePattern = servicePattern.substring(pip + 1); String g = serviceName.substring(0, pi); if (!gp.equals(g)) return false; } if (pi != -1) serviceName = serviceName.substring(pi + 1); final int vip = servicePattern.lastIndexOf(':'); final int vi = serviceName.lastIndexOf(':'); if (vip != -1) { if (vi == -1) return false; String vp = servicePattern.substring(vip + 1); servicePattern = servicePattern.substring(0, vip); String v = serviceName.substring(vi + 1); if (!vp.equals(v)) return false; } if (vi != -1) serviceName = serviceName.substring(0, vi); return ParseUtils.isMatchGlobPattern(servicePattern, serviceName); } static boolean matchRoute(String consumerAddress, String consumerQueryUrl, Route route, Map<String, List<String>> clusters); 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); static List<Route> findUsedRoute(String serviceName, String consumerAddress, String consumerQueryUrl,
List<Route> routes, Map<String, List<String>> clusters); static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers,
List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); static Map<String, String> route(String serviceName, String consumerAddress, String consumerQueryUrl, Map<String, String> serviceUrls,
List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); }
|
RouteUtils { static boolean isSerivceNameMatched(String servicePattern, String serviceName) { final int pip = servicePattern.indexOf('/'); final int pi = serviceName.indexOf('/'); if (pip != -1) { if (pi == -1) return false; String gp = servicePattern.substring(0, pip); servicePattern = servicePattern.substring(pip + 1); String g = serviceName.substring(0, pi); if (!gp.equals(g)) return false; } if (pi != -1) serviceName = serviceName.substring(pi + 1); final int vip = servicePattern.lastIndexOf(':'); final int vi = serviceName.lastIndexOf(':'); if (vip != -1) { if (vi == -1) return false; String vp = servicePattern.substring(vip + 1); servicePattern = servicePattern.substring(0, vip); String v = serviceName.substring(vi + 1); if (!vp.equals(v)) return false; } if (vi != -1) serviceName = serviceName.substring(0, vi); return ParseUtils.isMatchGlobPattern(servicePattern, serviceName); } static boolean matchRoute(String consumerAddress, String consumerQueryUrl, Route route, Map<String, List<String>> clusters); 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); static List<Route> findUsedRoute(String serviceName, String consumerAddress, String consumerQueryUrl,
List<Route> routes, Map<String, List<String>> clusters); static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers,
List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); static Map<String, String> route(String serviceName, String consumerAddress, String consumerQueryUrl, Map<String, String> serviceUrls,
List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); }
|
@Test public void testGetPageCount() { PageList<Object> pl = new PageList<Object>(0, 100, 52, null); Assert.assertEquals(1, pl.getPageCount()); pl = new PageList<Object>(0, -100, -3, null); Assert.assertEquals(1, pl.getPageCount()); pl = new PageList<Object>(0, 30, 100, null); Assert.assertEquals(4, pl.getPageCount()); }
|
public int getPageCount() { int lim = limit; if (limit < 1) { lim = 1; } int page = total / lim; if (page < 1) { return 1; } int remain = total % lim; if (remain > 0) { page += 1; } return page; }
|
PageList implements Serializable { public int getPageCount() { int lim = limit; if (limit < 1) { lim = 1; } int page = total / lim; if (page < 1) { return 1; } int remain = total % lim; if (remain > 0) { page += 1; } return page; } }
|
PageList implements Serializable { public int getPageCount() { int lim = limit; if (limit < 1) { lim = 1; } int page = total / lim; if (page < 1) { return 1; } int remain = total % lim; if (remain > 0) { page += 1; } return page; } PageList(); PageList(int start, int limit, int total, List<T> list); }
|
PageList implements Serializable { public int getPageCount() { int lim = limit; if (limit < 1) { lim = 1; } int page = total / lim; if (page < 1) { return 1; } int remain = total % lim; if (remain > 0) { page += 1; } return page; } PageList(); PageList(int start, int limit, int total, List<T> list); int getStart(); void setStart(int start); int getLimit(); void setLimit(int limit); int getTotal(); void setTotal(int total); List<T> getList(); void setList(List<T> list); int getPageCount(); }
|
PageList implements Serializable { public int getPageCount() { int lim = limit; if (limit < 1) { lim = 1; } int page = total / lim; if (page < 1) { return 1; } int remain = total % lim; if (remain > 0) { page += 1; } return page; } PageList(); PageList(int start, int limit, int total, List<T> list); int getStart(); void setStart(int start); int getLimit(); void setLimit(int limit); int getTotal(); void setTotal(int total); List<T> getList(); void setList(List<T> list); int getPageCount(); }
|
@Test public void testHeartBeat() throws Exception { url = url.addParameter(Constants.DUBBO_VERSION_KEY, "2.1.1"); channel.setAttribute( HeaderExchangeHandler.KEY_READ_TIMESTAMP, System.currentTimeMillis()); channel.setAttribute( HeaderExchangeHandler.KEY_WRITE_TIMESTAMP, System.currentTimeMillis()); Thread.sleep(2000L); task.run(); List<Object> objects = channel.getSentObjects(); Assert.assertTrue(objects.size() > 0); Object obj = objects.get(0); Assert.assertTrue(obj instanceof Request); Request request = (Request) obj; Assert.assertTrue(request.isHeartbeat()); }
|
public void run() { try { long now = System.currentTimeMillis(); for (Channel channel : channelProvider.getChannels()) { if (channel.isClosed()) { continue; } try { Long lastRead = (Long) channel.getAttribute( HeaderExchangeHandler.KEY_READ_TIMESTAMP); Long lastWrite = (Long) channel.getAttribute( HeaderExchangeHandler.KEY_WRITE_TIMESTAMP); if ((lastRead != null && now - lastRead > heartbeat) || (lastWrite != null && now - lastWrite > heartbeat)) { Request req = new Request(); req.setVersion("2.0.0"); req.setTwoWay(true); req.setEvent(Request.HEARTBEAT_EVENT); channel.send(req); if (logger.isDebugEnabled()) { logger.debug("Send heartbeat to remote channel " + channel.getRemoteAddress() + ", cause: The channel has no data-transmission exceeds a heartbeat period: " + heartbeat + "ms"); } } if (lastRead != null && now - lastRead > heartbeatTimeout) { logger.warn("Close channel " + channel + ", because heartbeat read idle time out: " + heartbeatTimeout + "ms"); if (channel instanceof Client) { try { ((Client) channel).reconnect(); } catch (Exception e) { } } else { channel.close(); } } } catch (Throwable t) { logger.warn("Exception when heartbeat to remote channel " + channel.getRemoteAddress(), t); } } } catch (Throwable t) { logger.warn("Unhandled exception when heartbeat, cause: " + t.getMessage(), t); } }
|
HeartBeatTask implements Runnable { public void run() { try { long now = System.currentTimeMillis(); for (Channel channel : channelProvider.getChannels()) { if (channel.isClosed()) { continue; } try { Long lastRead = (Long) channel.getAttribute( HeaderExchangeHandler.KEY_READ_TIMESTAMP); Long lastWrite = (Long) channel.getAttribute( HeaderExchangeHandler.KEY_WRITE_TIMESTAMP); if ((lastRead != null && now - lastRead > heartbeat) || (lastWrite != null && now - lastWrite > heartbeat)) { Request req = new Request(); req.setVersion("2.0.0"); req.setTwoWay(true); req.setEvent(Request.HEARTBEAT_EVENT); channel.send(req); if (logger.isDebugEnabled()) { logger.debug("Send heartbeat to remote channel " + channel.getRemoteAddress() + ", cause: The channel has no data-transmission exceeds a heartbeat period: " + heartbeat + "ms"); } } if (lastRead != null && now - lastRead > heartbeatTimeout) { logger.warn("Close channel " + channel + ", because heartbeat read idle time out: " + heartbeatTimeout + "ms"); if (channel instanceof Client) { try { ((Client) channel).reconnect(); } catch (Exception e) { } } else { channel.close(); } } } catch (Throwable t) { logger.warn("Exception when heartbeat to remote channel " + channel.getRemoteAddress(), t); } } } catch (Throwable t) { logger.warn("Unhandled exception when heartbeat, cause: " + t.getMessage(), t); } } }
|
HeartBeatTask implements Runnable { public void run() { try { long now = System.currentTimeMillis(); for (Channel channel : channelProvider.getChannels()) { if (channel.isClosed()) { continue; } try { Long lastRead = (Long) channel.getAttribute( HeaderExchangeHandler.KEY_READ_TIMESTAMP); Long lastWrite = (Long) channel.getAttribute( HeaderExchangeHandler.KEY_WRITE_TIMESTAMP); if ((lastRead != null && now - lastRead > heartbeat) || (lastWrite != null && now - lastWrite > heartbeat)) { Request req = new Request(); req.setVersion("2.0.0"); req.setTwoWay(true); req.setEvent(Request.HEARTBEAT_EVENT); channel.send(req); if (logger.isDebugEnabled()) { logger.debug("Send heartbeat to remote channel " + channel.getRemoteAddress() + ", cause: The channel has no data-transmission exceeds a heartbeat period: " + heartbeat + "ms"); } } if (lastRead != null && now - lastRead > heartbeatTimeout) { logger.warn("Close channel " + channel + ", because heartbeat read idle time out: " + heartbeatTimeout + "ms"); if (channel instanceof Client) { try { ((Client) channel).reconnect(); } catch (Exception e) { } } else { channel.close(); } } } catch (Throwable t) { logger.warn("Exception when heartbeat to remote channel " + channel.getRemoteAddress(), t); } } } catch (Throwable t) { logger.warn("Unhandled exception when heartbeat, cause: " + t.getMessage(), t); } } HeartBeatTask(ChannelProvider provider, int heartbeat, int heartbeatTimeout); }
|
HeartBeatTask implements Runnable { public void run() { try { long now = System.currentTimeMillis(); for (Channel channel : channelProvider.getChannels()) { if (channel.isClosed()) { continue; } try { Long lastRead = (Long) channel.getAttribute( HeaderExchangeHandler.KEY_READ_TIMESTAMP); Long lastWrite = (Long) channel.getAttribute( HeaderExchangeHandler.KEY_WRITE_TIMESTAMP); if ((lastRead != null && now - lastRead > heartbeat) || (lastWrite != null && now - lastWrite > heartbeat)) { Request req = new Request(); req.setVersion("2.0.0"); req.setTwoWay(true); req.setEvent(Request.HEARTBEAT_EVENT); channel.send(req); if (logger.isDebugEnabled()) { logger.debug("Send heartbeat to remote channel " + channel.getRemoteAddress() + ", cause: The channel has no data-transmission exceeds a heartbeat period: " + heartbeat + "ms"); } } if (lastRead != null && now - lastRead > heartbeatTimeout) { logger.warn("Close channel " + channel + ", because heartbeat read idle time out: " + heartbeatTimeout + "ms"); if (channel instanceof Client) { try { ((Client) channel).reconnect(); } catch (Exception e) { } } else { channel.close(); } } } catch (Throwable t) { logger.warn("Exception when heartbeat to remote channel " + channel.getRemoteAddress(), t); } } } catch (Throwable t) { logger.warn("Unhandled exception when heartbeat, cause: " + t.getMessage(), t); } } HeartBeatTask(ChannelProvider provider, int heartbeat, int heartbeatTimeout); void run(); }
|
HeartBeatTask implements Runnable { public void run() { try { long now = System.currentTimeMillis(); for (Channel channel : channelProvider.getChannels()) { if (channel.isClosed()) { continue; } try { Long lastRead = (Long) channel.getAttribute( HeaderExchangeHandler.KEY_READ_TIMESTAMP); Long lastWrite = (Long) channel.getAttribute( HeaderExchangeHandler.KEY_WRITE_TIMESTAMP); if ((lastRead != null && now - lastRead > heartbeat) || (lastWrite != null && now - lastWrite > heartbeat)) { Request req = new Request(); req.setVersion("2.0.0"); req.setTwoWay(true); req.setEvent(Request.HEARTBEAT_EVENT); channel.send(req); if (logger.isDebugEnabled()) { logger.debug("Send heartbeat to remote channel " + channel.getRemoteAddress() + ", cause: The channel has no data-transmission exceeds a heartbeat period: " + heartbeat + "ms"); } } if (lastRead != null && now - lastRead > heartbeatTimeout) { logger.warn("Close channel " + channel + ", because heartbeat read idle time out: " + heartbeatTimeout + "ms"); if (channel instanceof Client) { try { ((Client) channel).reconnect(); } catch (Exception e) { } } else { channel.close(); } } } catch (Throwable t) { logger.warn("Exception when heartbeat to remote channel " + channel.getRemoteAddress(), t); } } } catch (Throwable t) { logger.warn("Unhandled exception when heartbeat, cause: " + t.getMessage(), t); } } HeartBeatTask(ChannelProvider provider, int heartbeat, int heartbeatTimeout); void run(); }
|
@Test(expected = IndexOutOfBoundsException.class) public void writerIndexBoundaryCheck1() { buffer.writerIndex(-1); }
|
public int writerIndex() { return writerIndex; }
|
AbstractChannelBuffer implements ChannelBuffer { public int writerIndex() { return writerIndex; } }
|
AbstractChannelBuffer implements ChannelBuffer { public int writerIndex() { return writerIndex; } }
|
AbstractChannelBuffer implements ChannelBuffer { public int writerIndex() { return writerIndex; } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
AbstractChannelBuffer implements ChannelBuffer { public int writerIndex() { return writerIndex; } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
@Test(expected = IndexOutOfBoundsException.class) public void getByteArrayBoundaryCheck1() { buffer.getBytes(-1, new byte[0]); }
|
public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); }
|
AbstractChannelBuffer implements ChannelBuffer { public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); } }
|
AbstractChannelBuffer implements ChannelBuffer { public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); } }
|
AbstractChannelBuffer implements ChannelBuffer { public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
AbstractChannelBuffer implements ChannelBuffer { public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
@Test(expected = IndexOutOfBoundsException.class) public void getByteArrayBoundaryCheck2() { buffer.getBytes(-1, new byte[0], 0, 0); }
|
public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); }
|
AbstractChannelBuffer implements ChannelBuffer { public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); } }
|
AbstractChannelBuffer implements ChannelBuffer { public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); } }
|
AbstractChannelBuffer implements ChannelBuffer { public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
AbstractChannelBuffer implements ChannelBuffer { public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
@Test(expected = IndexOutOfBoundsException.class) public void getByteBufferBoundaryCheck() { buffer.getBytes(-1, ByteBuffer.allocate(0)); }
|
public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); }
|
AbstractChannelBuffer implements ChannelBuffer { public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); } }
|
AbstractChannelBuffer implements ChannelBuffer { public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); } }
|
AbstractChannelBuffer implements ChannelBuffer { public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
AbstractChannelBuffer implements ChannelBuffer { public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
@Test(expected = IndexOutOfBoundsException.class) public void copyBoundaryCheck1() { buffer.copy(-1, 0); }
|
public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
@Test(expected = IndexOutOfBoundsException.class) public void copyBoundaryCheck2() { buffer.copy(0, buffer.capacity() + 1); }
|
public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
@Test public void testMockInvokerInvoke_failmock() { URL url = URL.valueOf("remote: .addParameter(Constants.MOCK_KEY, "fail:return null") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); URL mockUrl = URL.valueOf("mock: + "?getSomething.mock=return aa").addParameters(url.getParameters()); Protocol protocol = new MockProtocol(); Invoker<IHelloService> mInvoker1 = protocol.refer(IHelloService.class, mockUrl); invokers.add(mInvoker1); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getSomething"); Result ret = cluster.invoke(invocation); Assert.assertEquals("aa", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("getSomething2"); ret = cluster.invoke(invocation); Assert.assertEquals(null, ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("sayHello"); ret = cluster.invoke(invocation); Assert.assertEquals(null, ret.getValue()); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testRoute_ReturnEmpty() { Router router = new ConditionRouterFactory().getRouter(getRouteUrl("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: Assert.assertEquals(0, fileredInvokers.size()); }
|
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); URL getUrl(); int compareTo(Router o); boolean matchWhen(URL url); boolean matchThen(URL url, URL param); }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); URL getUrl(); int compareTo(Router o); boolean matchWhen(URL url); boolean matchThen(URL url, URL param); }
|
@Test(expected = IndexOutOfBoundsException.class) public void copyBoundaryCheck3() { buffer.copy(buffer.capacity() + 1, 0); }
|
public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
@Test(expected = IndexOutOfBoundsException.class) public void copyBoundaryCheck4() { buffer.copy(buffer.capacity(), 1); }
|
public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
@Test(expected = IndexOutOfBoundsException.class) public void setIndexBoundaryCheck1() { buffer.setIndex(-1, CAPACITY); }
|
public void setIndex(int readerIndex, int writerIndex) { if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity()) { throw new IndexOutOfBoundsException(); } this.readerIndex = readerIndex; this.writerIndex = writerIndex; }
|
AbstractChannelBuffer implements ChannelBuffer { public void setIndex(int readerIndex, int writerIndex) { if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity()) { throw new IndexOutOfBoundsException(); } this.readerIndex = readerIndex; this.writerIndex = writerIndex; } }
|
AbstractChannelBuffer implements ChannelBuffer { public void setIndex(int readerIndex, int writerIndex) { if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity()) { throw new IndexOutOfBoundsException(); } this.readerIndex = readerIndex; this.writerIndex = writerIndex; } }
|
AbstractChannelBuffer implements ChannelBuffer { public void setIndex(int readerIndex, int writerIndex) { if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity()) { throw new IndexOutOfBoundsException(); } this.readerIndex = readerIndex; this.writerIndex = writerIndex; } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
AbstractChannelBuffer implements ChannelBuffer { public void setIndex(int readerIndex, int writerIndex) { if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity()) { throw new IndexOutOfBoundsException(); } this.readerIndex = readerIndex; this.writerIndex = writerIndex; } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
@Test(expected = IndexOutOfBoundsException.class) public void setIndexBoundaryCheck2() { buffer.setIndex(CAPACITY / 2, CAPACITY / 4); }
|
public void setIndex(int readerIndex, int writerIndex) { if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity()) { throw new IndexOutOfBoundsException(); } this.readerIndex = readerIndex; this.writerIndex = writerIndex; }
|
AbstractChannelBuffer implements ChannelBuffer { public void setIndex(int readerIndex, int writerIndex) { if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity()) { throw new IndexOutOfBoundsException(); } this.readerIndex = readerIndex; this.writerIndex = writerIndex; } }
|
AbstractChannelBuffer implements ChannelBuffer { public void setIndex(int readerIndex, int writerIndex) { if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity()) { throw new IndexOutOfBoundsException(); } this.readerIndex = readerIndex; this.writerIndex = writerIndex; } }
|
AbstractChannelBuffer implements ChannelBuffer { public void setIndex(int readerIndex, int writerIndex) { if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity()) { throw new IndexOutOfBoundsException(); } this.readerIndex = readerIndex; this.writerIndex = writerIndex; } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
AbstractChannelBuffer implements ChannelBuffer { public void setIndex(int readerIndex, int writerIndex) { if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity()) { throw new IndexOutOfBoundsException(); } this.readerIndex = readerIndex; this.writerIndex = writerIndex; } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
@Test(expected = IndexOutOfBoundsException.class) public void setIndexBoundaryCheck3() { buffer.setIndex(0, CAPACITY + 1); }
|
public void setIndex(int readerIndex, int writerIndex) { if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity()) { throw new IndexOutOfBoundsException(); } this.readerIndex = readerIndex; this.writerIndex = writerIndex; }
|
AbstractChannelBuffer implements ChannelBuffer { public void setIndex(int readerIndex, int writerIndex) { if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity()) { throw new IndexOutOfBoundsException(); } this.readerIndex = readerIndex; this.writerIndex = writerIndex; } }
|
AbstractChannelBuffer implements ChannelBuffer { public void setIndex(int readerIndex, int writerIndex) { if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity()) { throw new IndexOutOfBoundsException(); } this.readerIndex = readerIndex; this.writerIndex = writerIndex; } }
|
AbstractChannelBuffer implements ChannelBuffer { public void setIndex(int readerIndex, int writerIndex) { if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity()) { throw new IndexOutOfBoundsException(); } this.readerIndex = readerIndex; this.writerIndex = writerIndex; } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
AbstractChannelBuffer implements ChannelBuffer { public void setIndex(int readerIndex, int writerIndex) { if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity()) { throw new IndexOutOfBoundsException(); } this.readerIndex = readerIndex; this.writerIndex = writerIndex; } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
@Test(expected = IndexOutOfBoundsException.class) public void getDirectByteBufferBoundaryCheck() { buffer.getBytes(-1, ByteBuffer.allocateDirect(0)); }
|
public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); }
|
AbstractChannelBuffer implements ChannelBuffer { public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); } }
|
AbstractChannelBuffer implements ChannelBuffer { public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); } }
|
AbstractChannelBuffer implements ChannelBuffer { public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
AbstractChannelBuffer implements ChannelBuffer { public void getBytes(int index, byte[] dst) { getBytes(index, dst, 0, dst.length); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
@Test public void testCopy() { for (int i = 0; i < buffer.capacity(); i++) { byte value = (byte) random.nextInt(); buffer.setByte(i, value); } final int readerIndex = CAPACITY / 3; final int writerIndex = CAPACITY * 2 / 3; buffer.setIndex(readerIndex, writerIndex); ChannelBuffer copy = buffer.copy(); assertEquals(0, copy.readerIndex()); assertEquals(buffer.readableBytes(), copy.writerIndex()); assertEquals(buffer.readableBytes(), copy.capacity()); for (int i = 0; i < copy.capacity(); i++) { assertEquals(buffer.getByte(i + readerIndex), copy.getByte(i)); } buffer.setByte(readerIndex, (byte) (buffer.getByte(readerIndex) + 1)); assertTrue(buffer.getByte(readerIndex) != copy.getByte(0)); copy.setByte(1, (byte) (copy.getByte(1) + 1)); assertTrue(buffer.getByte(readerIndex + 1) != copy.getByte(1)); }
|
public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
AbstractChannelBuffer implements ChannelBuffer { public ChannelBuffer copy() { return copy(readerIndex, readableBytes()); } int readerIndex(); void readerIndex(int readerIndex); int writerIndex(); void writerIndex(int writerIndex); void setIndex(int readerIndex, int writerIndex); void clear(); boolean readable(); boolean writable(); int readableBytes(); int writableBytes(); void markReaderIndex(); void resetReaderIndex(); void markWriterIndex(); void resetWriterIndex(); void discardReadBytes(); void ensureWritableBytes(int writableBytes); void getBytes(int index, byte[] dst); void getBytes(int index, ChannelBuffer dst); void getBytes(int index, ChannelBuffer dst, int length); void setBytes(int index, byte[] src); void setBytes(int index, ChannelBuffer src); void setBytes(int index, ChannelBuffer src, int length); byte readByte(); ChannelBuffer readBytes(int length); void readBytes(byte[] dst, int dstIndex, int length); void readBytes(byte[] dst); void readBytes(ChannelBuffer dst); void readBytes(ChannelBuffer dst, int length); void readBytes(ChannelBuffer dst, int dstIndex, int length); void readBytes(ByteBuffer dst); void readBytes(OutputStream out, int length); void skipBytes(int length); void writeByte(int value); void writeBytes(byte[] src, int srcIndex, int length); void writeBytes(byte[] src); void writeBytes(ChannelBuffer src); void writeBytes(ChannelBuffer src, int length); void writeBytes(ChannelBuffer src, int srcIndex, int length); void writeBytes(ByteBuffer src); int writeBytes(InputStream in, int length); ChannelBuffer copy(); ByteBuffer toByteBuffer(); @Override boolean equals(Object o); int compareTo(ChannelBuffer that); @Override String toString(); }
|
@Test public void testDestroyAll() throws Exception { ReferenceConfigCache cache = ReferenceConfigCache.getCache(); MockReferenceConfig config = new MockReferenceConfig(); config.setInterface("FooService"); config.setGroup("group1"); config.setVersion("1.0.0"); cache.get(config); MockReferenceConfig configCopy = new MockReferenceConfig(); configCopy.setInterface("XxxService"); configCopy.setGroup("group1"); configCopy.setVersion("1.0.0"); cache.get(configCopy); assertEquals(2, cache.cache.size()); cache.destroyAll(); assertTrue(config.isDestroyMethodRun()); assertTrue(configCopy.isDestroyMethodRun()); assertEquals(0, cache.cache.size()); }
|
public void destroyAll() { Set<String> set = new HashSet<String>(cache.keySet()); for (String key : set) { destroyKey(key); } }
|
ReferenceConfigCache { public void destroyAll() { Set<String> set = new HashSet<String>(cache.keySet()); for (String key : set) { destroyKey(key); } } }
|
ReferenceConfigCache { public void destroyAll() { Set<String> set = new HashSet<String>(cache.keySet()); for (String key : set) { destroyKey(key); } } private ReferenceConfigCache(String name, KeyGenerator generator); }
|
ReferenceConfigCache { public void destroyAll() { Set<String> set = new HashSet<String>(cache.keySet()); for (String key : set) { destroyKey(key); } } private ReferenceConfigCache(String name, KeyGenerator generator); static ReferenceConfigCache getCache(); static ReferenceConfigCache getCache(String name); static ReferenceConfigCache getCache(String name, KeyGenerator keyGenerator); @SuppressWarnings("unchecked") T get(ReferenceConfig<T> referenceConfig); void destroy(ReferenceConfig<T> referenceConfig); void destroyAll(); @Override String toString(); }
|
ReferenceConfigCache { public void destroyAll() { Set<String> set = new HashSet<String>(cache.keySet()); for (String key : set) { destroyKey(key); } } private ReferenceConfigCache(String name, KeyGenerator generator); static ReferenceConfigCache getCache(); static ReferenceConfigCache getCache(String name); static ReferenceConfigCache getCache(String name, KeyGenerator keyGenerator); @SuppressWarnings("unchecked") T get(ReferenceConfig<T> referenceConfig); void destroy(ReferenceConfig<T> referenceConfig); void destroyAll(); @Override String toString(); static final String DEFAULT_NAME; static final KeyGenerator DEFAULT_KEY_GENERATOR; }
|
@Test public void testMockInvokerInvoke_forcemock() { URL url = URL.valueOf("remote: url = url.addParameter(Constants.MOCK_KEY, "force:return null"); Invoker<IHelloService> cluster = getClusterInvoker(url); URL mockUrl = URL.valueOf("mock: + "?getSomething.mock=return aa&getSomething3xx.mock=return xx") .addParameters(url.getParameters()); Protocol protocol = new MockProtocol(); Invoker<IHelloService> mInvoker1 = protocol.refer(IHelloService.class, mockUrl); invokers.add(mInvoker1); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getSomething"); Result ret = cluster.invoke(invocation); Assert.assertEquals("aa", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("getSomething2"); ret = cluster.invoke(invocation); Assert.assertEquals(null, ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("sayHello"); ret = cluster.invoke(invocation); Assert.assertEquals(null, ret.getValue()); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testMockInvokerInvoke_forcemock_defaultreturn() { URL url = URL.valueOf("remote: url = url.addParameter(Constants.MOCK_KEY, "force"); Invoker<IHelloService> cluster = getClusterInvoker(url); URL mockUrl = URL.valueOf("mock: + "?getSomething.mock=return aa&getSomething3xx.mock=return xx&sayHello.mock=return ") .addParameters(url.getParameters()); Protocol protocol = new MockProtocol(); Invoker<IHelloService> mInvoker1 = protocol.refer(IHelloService.class, mockUrl); invokers.add(mInvoker1); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("sayHello"); Result ret = cluster.invoke(invocation); Assert.assertEquals(null, ret.getValue()); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testMockInvokerFromOverride_Invoke_Fock_someMethods() { URL url = URL.valueOf("remote: .addParameter("getSomething.mock", "fail:return x") .addParameter("getSomething2.mock", "force:return y"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getSomething"); Result ret = cluster.invoke(invocation); Assert.assertEquals("something", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("getSomething2"); ret = cluster.invoke(invocation); Assert.assertEquals("y", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("getSomething3"); ret = cluster.invoke(invocation); Assert.assertEquals("something3", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("sayHello"); ret = cluster.invoke(invocation); Assert.assertEquals(null, ret.getValue()); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testMockInvokerFromOverride_Invoke_Fock_WithOutDefault() { URL url = URL.valueOf("remote: .addParameter("getSomething.mock", "fail:return x") .addParameter("getSomething2.mock", "force:return y") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getSomething"); Result ret = cluster.invoke(invocation); Assert.assertEquals("x", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("getSomething2"); ret = cluster.invoke(invocation); Assert.assertEquals("y", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("getSomething3"); try { ret = cluster.invoke(invocation); Assert.fail(); } catch (RpcException e) { } }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testMockInvokerFromOverride_Invoke_Fock_WithDefault() { URL url = URL.valueOf("remote: .addParameter("mock", "fail:return null") .addParameter("getSomething.mock", "fail:return x") .addParameter("getSomething2.mock", "force:return y") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getSomething"); Result ret = cluster.invoke(invocation); Assert.assertEquals("x", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("getSomething2"); ret = cluster.invoke(invocation); Assert.assertEquals("y", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("getSomething3"); ret = cluster.invoke(invocation); Assert.assertEquals(null, ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("sayHello"); ret = cluster.invoke(invocation); Assert.assertEquals(null, ret.getValue()); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testMockInvokerFromOverride_Invoke_Fock_WithFailDefault() { URL url = URL.valueOf("remote: .addParameter("mock", "fail:return z") .addParameter("getSomething.mock", "fail:return x") .addParameter("getSomething2.mock", "force:return y") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getSomething"); Result ret = cluster.invoke(invocation); Assert.assertEquals("x", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("getSomething2"); ret = cluster.invoke(invocation); Assert.assertEquals("y", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("getSomething3"); ret = cluster.invoke(invocation); Assert.assertEquals("z", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("sayHello"); ret = cluster.invoke(invocation); Assert.assertEquals("z", ret.getValue()); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testMockInvokerFromOverride_Invoke_Fock_WithForceDefault() { URL url = URL.valueOf("remote: .addParameter("mock", "force:return z") .addParameter("getSomething.mock", "fail:return x") .addParameter("getSomething2.mock", "force:return y") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getSomething"); Result ret = cluster.invoke(invocation); Assert.assertEquals("x", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("getSomething2"); ret = cluster.invoke(invocation); Assert.assertEquals("y", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("getSomething3"); ret = cluster.invoke(invocation); Assert.assertEquals("z", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("sayHello"); ret = cluster.invoke(invocation); Assert.assertEquals("z", ret.getValue()); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testMockInvokerFromOverride_Invoke_Fock_Default() { URL url = URL.valueOf("remote: .addParameter("mock", "fail:return x") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getSomething"); Result ret = cluster.invoke(invocation); Assert.assertEquals("x", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("getSomething2"); ret = cluster.invoke(invocation); Assert.assertEquals("x", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("sayHello"); ret = cluster.invoke(invocation); Assert.assertEquals("x", ret.getValue()); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testMockInvokerFromOverride_Invoke_checkCompatible_return() { URL url = URL.valueOf("remote: .addParameter("getSomething.mock", "return x") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getSomething"); Result ret = cluster.invoke(invocation); Assert.assertEquals("x", ret.getValue()); invocation = new RpcInvocation(); invocation.setMethodName("getSomething3"); try { ret = cluster.invoke(invocation); Assert.fail("fail invoke"); } catch (RpcException e) { } }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock() { URL url = URL.valueOf("remote: .addParameter("mock", "true") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getSomething"); Result ret = cluster.invoke(invocation); Assert.assertEquals("somethingmock", ret.getValue()); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@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: Assert.assertEquals(invokers, fileredInvokers); }
|
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); URL getUrl(); int compareTo(Router o); boolean matchWhen(URL url); boolean matchThen(URL url, URL param); }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); URL getUrl(); int compareTo(Router o); boolean matchWhen(URL url); boolean matchThen(URL url, URL param); }
|
@Test public void testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock2() { URL url = URL.valueOf("remote: .addParameter("mock", "fail") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getSomething"); Result ret = cluster.invoke(invocation); Assert.assertEquals("somethingmock", ret.getValue()); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock3() { URL url = URL.valueOf("remote: .addParameter("mock", "force"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getSomething"); Result ret = cluster.invoke(invocation); Assert.assertEquals("somethingmock", ret.getValue()); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testMockInvokerFromOverride_Invoke_check_String() { URL url = URL.valueOf("remote: .addParameter("getSomething.mock", "force:return 1688") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getSomething"); Result ret = cluster.invoke(invocation); Assert.assertTrue("result type must be String but was : " + ret.getValue().getClass(), ret.getValue() instanceof String); Assert.assertEquals("1688", (String) ret.getValue()); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testMockInvokerFromOverride_Invoke_check_int() { URL url = URL.valueOf("remote: .addParameter("getInt1.mock", "force:return 1688") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getInt1"); Result ret = cluster.invoke(invocation); Assert.assertTrue("result type must be integer but was : " + ret.getValue().getClass(), ret.getValue() instanceof Integer); Assert.assertEquals(new Integer(1688), (Integer) ret.getValue()); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@SuppressWarnings("unchecked") @Test public void testMockInvokerFromOverride_Invoke_check_ListString_empty() { URL url = URL.valueOf("remote: .addParameter("getListString.mock", "force:return empty") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getListString"); Result ret = cluster.invoke(invocation); Assert.assertEquals(0, ((List<String>) ret.getValue()).size()); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@SuppressWarnings("unchecked") @Test public void testMockInvokerFromOverride_Invoke_check_ListString() { URL url = URL.valueOf("remote: .addParameter("getListString.mock", "force:return [\"hi\",\"hi2\"]") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getListString"); Result ret = cluster.invoke(invocation); List<String> rl = (List<String>) ret.getValue(); Assert.assertEquals(2, rl.size()); Assert.assertEquals("hi", rl.get(0)); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@SuppressWarnings("unchecked") @Test public void testMockInvokerFromOverride_Invoke_check_ListPojo_empty() { URL url = URL.valueOf("remote: .addParameter("getUsers.mock", "force:return empty") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getUsers"); Result ret = cluster.invoke(invocation); Assert.assertEquals(0, ((List<User>) ret.getValue()).size()); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@SuppressWarnings("unchecked") @Test public void testMockInvokerFromOverride_Invoke_check_ListPojo() { URL url = URL.valueOf("remote: .addParameter("getUsers.mock", "force:return [{id:1, name:\"hi1\"}, {id:2, name:\"hi2\"}]") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getUsers"); Result ret = cluster.invoke(invocation); List<User> rl = (List<User>) ret.getValue(); System.out.println(rl); Assert.assertEquals(2, rl.size()); Assert.assertEquals("hi1", ((User) rl.get(0)).getName()); }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testMockInvokerFromOverride_Invoke_check_ListPojo_error() { URL url = URL.valueOf("remote: .addParameter("getUsers.mock", "force:return [{id:x, name:\"hi1\"}]") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getUsers"); try { cluster.invoke(invocation); } catch (RpcException e) { } }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testMockInvokerFromOverride_Invoke_force_throw() { URL url = URL.valueOf("remote: .addParameter("getBoolean2.mock", "force:throw ") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getBoolean2"); try { cluster.invoke(invocation); Assert.fail(); } catch (RpcException e) { Assert.assertFalse("not custem exception", e.isBiz()); } }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@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: Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo: Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo: invokers.add(invoker1); invokers.add(invoker2); invokers.add(invoker3); List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer: Assert.assertEquals(2, fileredInvokers.size()); Assert.assertEquals(invoker2, fileredInvokers.get(0)); Assert.assertEquals(invoker3, fileredInvokers.get(1)); }
|
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); URL getUrl(); int compareTo(Router o); boolean matchWhen(URL url); boolean matchThen(URL url, URL param); }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); URL getUrl(); int compareTo(Router o); boolean matchWhen(URL url); boolean matchThen(URL url, URL param); }
|
@Test public void testMockInvokerFromOverride_Invoke_force_throwCustemException() throws Throwable { URL url = URL.valueOf("remote: .addParameter("getBoolean2.mock", "force:throw com.alibaba.dubbo.rpc.cluster.support.wrapper.MyMockException") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getBoolean2"); try { cluster.invoke(invocation).recreate(); Assert.fail(); } catch (MyMockException e) { } }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testMockInvokerFromOverride_Invoke_force_throwCustemExceptionNotFound() { URL url = URL.valueOf("remote: .addParameter("getBoolean2.mock", "force:throw java.lang.RuntimeException2") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getBoolean2"); try { cluster.invoke(invocation); Assert.fail(); } catch (Exception e) { Assert.assertTrue(e.getCause() instanceof IllegalStateException); } }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testMockInvokerFromOverride_Invoke_mock_false() { URL url = URL.valueOf("remote: .addParameter("mock", "false") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getBoolean2"); try { cluster.invoke(invocation); Assert.fail(); } catch (RpcException e) { Assert.assertTrue(e.isTimeout()); } }
|
public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
MockClusterInvoker implements Invoker<T> { public Result invoke(Invocation invocation) throws RpcException { Result result = null; String value = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim(); if (value.length() == 0 || value.equalsIgnoreCase("false")) { result = this.invoker.invoke(invocation); } else if (value.startsWith("force")) { if (logger.isWarnEnabled()) { logger.info("force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + directory.getUrl()); } result = doMockInvoke(invocation, null); } else { try { String SF = "no"; String errorrate = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.ERRORRATE_KEY, Boolean.FALSE.toString()).trim(); String supervene = directory .getUrl() .getMethodParameter(invocation.getMethodName(), Constants.SUPERVENE_KEY, Boolean.FALSE.toString()).trim(); if (Float.parseFloat(errorrate) != 0 || Integer.parseInt(supervene) != 0) { SF = fuseCount(errorrate, supervene, "before",(long)-1,invocation.getMethodName()); } if (SF.equals("fail")) { result = doMockInvoke(invocation, null); return result; } if (SF.equals("no")) { result = this.invoker.invoke(invocation); } if (SF.equals("success")) { long timeBefore = System.currentTimeMillis(); result = this.invoker.invoke(invocation); long time = System.currentTimeMillis()-timeBefore; fuseCount(errorrate, supervene, "after",time,invocation.getMethodName()); } } catch (RpcException e) { if (e.isBiz()) { throw e; } else { if (logger.isWarnEnabled()) { logger.info( "fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + directory.getUrl(), e); } result = doMockInvoke(invocation, e); } } } return result; } MockClusterInvoker(Directory<T> directory, Invoker<T> invoker); URL getUrl(); boolean isAvailable(); void destroy(); Class<T> getInterface(); Result invoke(Invocation invocation); @Override String toString(); String fuseCount(String errorrate, String supervene, String status,Long time,String methodName); }
|
@Test public void testTimeOut() { HessianServiceImpl server = new HessianServiceImpl(); ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension(); URL url = URL.valueOf("hessian: Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url)); Invoker<HessianService> invoker = protocol.refer(HessianService.class, url); HessianService client = proxyFactory.getProxy(invoker); try { client.timeOut(6000); fail(); } catch (RpcException expected) { Assert.assertEquals(true, expected.isTimeout()); } finally { invoker.destroy(); exporter.unexport(); } }
|
public void destroy() { super.destroy(); for (String key : new ArrayList<String>(serverMap.keySet())) { HttpServer server = serverMap.remove(key); if (server != null) { try { if (logger.isInfoEnabled()) { logger.info("Close hessian server " + server.getUrl()); } server.close(); } catch (Throwable t) { logger.warn(t.getMessage(), t); } } } }
|
HessianProtocol extends AbstractProxyProtocol { public void destroy() { super.destroy(); for (String key : new ArrayList<String>(serverMap.keySet())) { HttpServer server = serverMap.remove(key); if (server != null) { try { if (logger.isInfoEnabled()) { logger.info("Close hessian server " + server.getUrl()); } server.close(); } catch (Throwable t) { logger.warn(t.getMessage(), t); } } } } }
|
HessianProtocol extends AbstractProxyProtocol { public void destroy() { super.destroy(); for (String key : new ArrayList<String>(serverMap.keySet())) { HttpServer server = serverMap.remove(key); if (server != null) { try { if (logger.isInfoEnabled()) { logger.info("Close hessian server " + server.getUrl()); } server.close(); } catch (Throwable t) { logger.warn(t.getMessage(), t); } } } } HessianProtocol(); }
|
HessianProtocol extends AbstractProxyProtocol { public void destroy() { super.destroy(); for (String key : new ArrayList<String>(serverMap.keySet())) { HttpServer server = serverMap.remove(key); if (server != null) { try { if (logger.isInfoEnabled()) { logger.info("Close hessian server " + server.getUrl()); } server.close(); } catch (Throwable t) { logger.warn(t.getMessage(), t); } } } } HessianProtocol(); void setHttpBinder(HttpBinder httpBinder); int getDefaultPort(); void destroy(); }
|
HessianProtocol extends AbstractProxyProtocol { public void destroy() { super.destroy(); for (String key : new ArrayList<String>(serverMap.keySet())) { HttpServer server = serverMap.remove(key); if (server != null) { try { if (logger.isInfoEnabled()) { logger.info("Close hessian server " + server.getUrl()); } server.close(); } catch (Throwable t) { logger.warn(t.getMessage(), t); } } } } HessianProtocol(); void setHttpBinder(HttpBinder httpBinder); int getDefaultPort(); void destroy(); }
|
@Test public void test_share_connect() { init(0); Assert.assertEquals(demoClient.getLocalAddress(), helloClient.getLocalAddress()); Assert.assertEquals(demoClient, helloClient); destoy(); }
|
public InetSocketAddress getLocalAddress() { return client.getLocalAddress(); }
|
ReferenceCountExchangeClient implements ExchangeClient { public InetSocketAddress getLocalAddress() { return client.getLocalAddress(); } }
|
ReferenceCountExchangeClient implements ExchangeClient { public InetSocketAddress getLocalAddress() { return client.getLocalAddress(); } ReferenceCountExchangeClient(ExchangeClient client, ConcurrentMap<String, LazyConnectExchangeClient> ghostClientMap); }
|
ReferenceCountExchangeClient implements ExchangeClient { public InetSocketAddress getLocalAddress() { return client.getLocalAddress(); } ReferenceCountExchangeClient(ExchangeClient client, ConcurrentMap<String, LazyConnectExchangeClient> ghostClientMap); void reset(URL url); ResponseFuture request(Object request); URL getUrl(); InetSocketAddress getRemoteAddress(); ChannelHandler getChannelHandler(); ResponseFuture request(Object request, int timeout); boolean isConnected(); void reconnect(); InetSocketAddress getLocalAddress(); boolean hasAttribute(String key); void reset(Parameters parameters); void send(Object message); ExchangeHandler getExchangeHandler(); Object getAttribute(String key); void send(Object message, boolean sent); void setAttribute(String key, Object value); void removeAttribute(String key); void close(); void close(int timeout); boolean isClosed(); void incrementAndGetCount(); }
|
ReferenceCountExchangeClient implements ExchangeClient { public InetSocketAddress getLocalAddress() { return client.getLocalAddress(); } ReferenceCountExchangeClient(ExchangeClient client, ConcurrentMap<String, LazyConnectExchangeClient> ghostClientMap); void reset(URL url); ResponseFuture request(Object request); URL getUrl(); InetSocketAddress getRemoteAddress(); ChannelHandler getChannelHandler(); ResponseFuture request(Object request, int timeout); boolean isConnected(); void reconnect(); InetSocketAddress getLocalAddress(); boolean hasAttribute(String key); void reset(Parameters parameters); void send(Object message); ExchangeHandler getExchangeHandler(); Object getAttribute(String key); void send(Object message, boolean sent); void setAttribute(String key, Object value); void removeAttribute(String key); void close(); void close(int timeout); boolean isClosed(); void incrementAndGetCount(); }
|
@Test public void test_not_share_connect() { init(1); Assert.assertNotSame(demoClient.getLocalAddress(), helloClient.getLocalAddress()); Assert.assertNotSame(demoClient, helloClient); destoy(); }
|
public InetSocketAddress getLocalAddress() { return client.getLocalAddress(); }
|
ReferenceCountExchangeClient implements ExchangeClient { public InetSocketAddress getLocalAddress() { return client.getLocalAddress(); } }
|
ReferenceCountExchangeClient implements ExchangeClient { public InetSocketAddress getLocalAddress() { return client.getLocalAddress(); } ReferenceCountExchangeClient(ExchangeClient client, ConcurrentMap<String, LazyConnectExchangeClient> ghostClientMap); }
|
ReferenceCountExchangeClient implements ExchangeClient { public InetSocketAddress getLocalAddress() { return client.getLocalAddress(); } ReferenceCountExchangeClient(ExchangeClient client, ConcurrentMap<String, LazyConnectExchangeClient> ghostClientMap); void reset(URL url); ResponseFuture request(Object request); URL getUrl(); InetSocketAddress getRemoteAddress(); ChannelHandler getChannelHandler(); ResponseFuture request(Object request, int timeout); boolean isConnected(); void reconnect(); InetSocketAddress getLocalAddress(); boolean hasAttribute(String key); void reset(Parameters parameters); void send(Object message); ExchangeHandler getExchangeHandler(); Object getAttribute(String key); void send(Object message, boolean sent); void setAttribute(String key, Object value); void removeAttribute(String key); void close(); void close(int timeout); boolean isClosed(); void incrementAndGetCount(); }
|
ReferenceCountExchangeClient implements ExchangeClient { public InetSocketAddress getLocalAddress() { return client.getLocalAddress(); } ReferenceCountExchangeClient(ExchangeClient client, ConcurrentMap<String, LazyConnectExchangeClient> ghostClientMap); void reset(URL url); ResponseFuture request(Object request); URL getUrl(); InetSocketAddress getRemoteAddress(); ChannelHandler getChannelHandler(); ResponseFuture request(Object request, int timeout); boolean isConnected(); void reconnect(); InetSocketAddress getLocalAddress(); boolean hasAttribute(String key); void reset(Parameters parameters); void send(Object message); ExchangeHandler getExchangeHandler(); Object getAttribute(String key); void send(Object message, boolean sent); void setAttribute(String key, Object value); void removeAttribute(String key); void close(); void close(int timeout); boolean isClosed(); void incrementAndGetCount(); }
|
@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: Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo: Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo: invokers.add(invoker1); invokers.add(invoker2); invokers.add(invoker3); List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer: Assert.assertEquals(2, fileredInvokers.size()); Assert.assertEquals(invoker2, fileredInvokers.get(0)); Assert.assertEquals(invoker3, fileredInvokers.get(1)); }
|
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); URL getUrl(); int compareTo(Router o); boolean matchWhen(URL url); boolean matchThen(URL url, URL param); }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); URL getUrl(); int compareTo(Router o); boolean matchWhen(URL url); boolean matchThen(URL url, URL param); }
|
@Test public void testChangeLogLevel() throws RemotingException { mockChannel = EasyMock.createMock(Channel.class); EasyMock.replay(mockChannel); String result = log.telnet(mockChannel, "error"); assertTrue(result.contains("\r\nCURRENT LOG LEVEL:ERROR")); String result2 = log.telnet(mockChannel, "warn"); assertTrue(result2.contains("\r\nCURRENT LOG LEVEL:WARN")); EasyMock.reset(mockChannel); }
|
public String telnet(Channel channel, String message) { long size = 0; File file = LoggerFactory.getFile(); StringBuffer buf = new StringBuffer(); if (message == null || message.trim().length() == 0) { buf.append("EXAMPLE: log error / log 100"); } else { String str[] = message.split(" "); if (!StringUtils.isInteger(str[0])) { LoggerFactory.setLevel(Level.valueOf(message.toUpperCase())); } else { int SHOW_LOG_LENGTH = Integer.parseInt(str[0]); if (file != null && file.exists()) { try { FileInputStream fis = new FileInputStream(file); FileChannel filechannel = fis.getChannel(); size = filechannel.size(); ByteBuffer bb; if (size <= SHOW_LOG_LENGTH) { bb = ByteBuffer.allocate((int) size); filechannel.read(bb, 0); } else { int pos = (int) (size - SHOW_LOG_LENGTH); bb = ByteBuffer.allocate(SHOW_LOG_LENGTH); filechannel.read(bb, pos); } bb.flip(); String content = new String(bb.array()).replace("<", "<") .replace(">", ">").replace("\n", "<br/><br/>"); buf.append("\r\ncontent:" + content); buf.append("\r\nmodified:" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .format(new Date(file.lastModified())))); buf.append("\r\nsize:" + size + "\r\n"); } catch (Exception e) { buf.append(e.getMessage()); } } else { size = 0; buf.append("\r\nMESSAGE: log file not exists or log appender is console ."); } } } buf.append("\r\nCURRENT LOG LEVEL:" + LoggerFactory.getLevel()) .append("\r\nCURRENT LOG APPENDER:" + (file == null ? "console" : file.getAbsolutePath())); return buf.toString(); }
|
LogTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { long size = 0; File file = LoggerFactory.getFile(); StringBuffer buf = new StringBuffer(); if (message == null || message.trim().length() == 0) { buf.append("EXAMPLE: log error / log 100"); } else { String str[] = message.split(" "); if (!StringUtils.isInteger(str[0])) { LoggerFactory.setLevel(Level.valueOf(message.toUpperCase())); } else { int SHOW_LOG_LENGTH = Integer.parseInt(str[0]); if (file != null && file.exists()) { try { FileInputStream fis = new FileInputStream(file); FileChannel filechannel = fis.getChannel(); size = filechannel.size(); ByteBuffer bb; if (size <= SHOW_LOG_LENGTH) { bb = ByteBuffer.allocate((int) size); filechannel.read(bb, 0); } else { int pos = (int) (size - SHOW_LOG_LENGTH); bb = ByteBuffer.allocate(SHOW_LOG_LENGTH); filechannel.read(bb, pos); } bb.flip(); String content = new String(bb.array()).replace("<", "<") .replace(">", ">").replace("\n", "<br/><br/>"); buf.append("\r\ncontent:" + content); buf.append("\r\nmodified:" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .format(new Date(file.lastModified())))); buf.append("\r\nsize:" + size + "\r\n"); } catch (Exception e) { buf.append(e.getMessage()); } } else { size = 0; buf.append("\r\nMESSAGE: log file not exists or log appender is console ."); } } } buf.append("\r\nCURRENT LOG LEVEL:" + LoggerFactory.getLevel()) .append("\r\nCURRENT LOG APPENDER:" + (file == null ? "console" : file.getAbsolutePath())); return buf.toString(); } }
|
LogTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { long size = 0; File file = LoggerFactory.getFile(); StringBuffer buf = new StringBuffer(); if (message == null || message.trim().length() == 0) { buf.append("EXAMPLE: log error / log 100"); } else { String str[] = message.split(" "); if (!StringUtils.isInteger(str[0])) { LoggerFactory.setLevel(Level.valueOf(message.toUpperCase())); } else { int SHOW_LOG_LENGTH = Integer.parseInt(str[0]); if (file != null && file.exists()) { try { FileInputStream fis = new FileInputStream(file); FileChannel filechannel = fis.getChannel(); size = filechannel.size(); ByteBuffer bb; if (size <= SHOW_LOG_LENGTH) { bb = ByteBuffer.allocate((int) size); filechannel.read(bb, 0); } else { int pos = (int) (size - SHOW_LOG_LENGTH); bb = ByteBuffer.allocate(SHOW_LOG_LENGTH); filechannel.read(bb, pos); } bb.flip(); String content = new String(bb.array()).replace("<", "<") .replace(">", ">").replace("\n", "<br/><br/>"); buf.append("\r\ncontent:" + content); buf.append("\r\nmodified:" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .format(new Date(file.lastModified())))); buf.append("\r\nsize:" + size + "\r\n"); } catch (Exception e) { buf.append(e.getMessage()); } } else { size = 0; buf.append("\r\nMESSAGE: log file not exists or log appender is console ."); } } } buf.append("\r\nCURRENT LOG LEVEL:" + LoggerFactory.getLevel()) .append("\r\nCURRENT LOG APPENDER:" + (file == null ? "console" : file.getAbsolutePath())); return buf.toString(); } }
|
LogTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { long size = 0; File file = LoggerFactory.getFile(); StringBuffer buf = new StringBuffer(); if (message == null || message.trim().length() == 0) { buf.append("EXAMPLE: log error / log 100"); } else { String str[] = message.split(" "); if (!StringUtils.isInteger(str[0])) { LoggerFactory.setLevel(Level.valueOf(message.toUpperCase())); } else { int SHOW_LOG_LENGTH = Integer.parseInt(str[0]); if (file != null && file.exists()) { try { FileInputStream fis = new FileInputStream(file); FileChannel filechannel = fis.getChannel(); size = filechannel.size(); ByteBuffer bb; if (size <= SHOW_LOG_LENGTH) { bb = ByteBuffer.allocate((int) size); filechannel.read(bb, 0); } else { int pos = (int) (size - SHOW_LOG_LENGTH); bb = ByteBuffer.allocate(SHOW_LOG_LENGTH); filechannel.read(bb, pos); } bb.flip(); String content = new String(bb.array()).replace("<", "<") .replace(">", ">").replace("\n", "<br/><br/>"); buf.append("\r\ncontent:" + content); buf.append("\r\nmodified:" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .format(new Date(file.lastModified())))); buf.append("\r\nsize:" + size + "\r\n"); } catch (Exception e) { buf.append(e.getMessage()); } } else { size = 0; buf.append("\r\nMESSAGE: log file not exists or log appender is console ."); } } } buf.append("\r\nCURRENT LOG LEVEL:" + LoggerFactory.getLevel()) .append("\r\nCURRENT LOG APPENDER:" + (file == null ? "console" : file.getAbsolutePath())); return buf.toString(); } String telnet(Channel channel, String message); }
|
LogTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { long size = 0; File file = LoggerFactory.getFile(); StringBuffer buf = new StringBuffer(); if (message == null || message.trim().length() == 0) { buf.append("EXAMPLE: log error / log 100"); } else { String str[] = message.split(" "); if (!StringUtils.isInteger(str[0])) { LoggerFactory.setLevel(Level.valueOf(message.toUpperCase())); } else { int SHOW_LOG_LENGTH = Integer.parseInt(str[0]); if (file != null && file.exists()) { try { FileInputStream fis = new FileInputStream(file); FileChannel filechannel = fis.getChannel(); size = filechannel.size(); ByteBuffer bb; if (size <= SHOW_LOG_LENGTH) { bb = ByteBuffer.allocate((int) size); filechannel.read(bb, 0); } else { int pos = (int) (size - SHOW_LOG_LENGTH); bb = ByteBuffer.allocate(SHOW_LOG_LENGTH); filechannel.read(bb, pos); } bb.flip(); String content = new String(bb.array()).replace("<", "<") .replace(">", ">").replace("\n", "<br/><br/>"); buf.append("\r\ncontent:" + content); buf.append("\r\nmodified:" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .format(new Date(file.lastModified())))); buf.append("\r\nsize:" + size + "\r\n"); } catch (Exception e) { buf.append(e.getMessage()); } } else { size = 0; buf.append("\r\nMESSAGE: log file not exists or log appender is console ."); } } } buf.append("\r\nCURRENT LOG LEVEL:" + LoggerFactory.getLevel()) .append("\r\nCURRENT LOG APPENDER:" + (file == null ? "console" : file.getAbsolutePath())); return buf.toString(); } String telnet(Channel channel, String message); static final String SERVICE_KEY; }
|
@Test public void testPrintLog() throws RemotingException { mockChannel = EasyMock.createMock(Channel.class); EasyMock.replay(mockChannel); String result = log.telnet(mockChannel, "100"); assertTrue(result.contains("CURRENT LOG APPENDER")); EasyMock.reset(mockChannel); }
|
public String telnet(Channel channel, String message) { long size = 0; File file = LoggerFactory.getFile(); StringBuffer buf = new StringBuffer(); if (message == null || message.trim().length() == 0) { buf.append("EXAMPLE: log error / log 100"); } else { String str[] = message.split(" "); if (!StringUtils.isInteger(str[0])) { LoggerFactory.setLevel(Level.valueOf(message.toUpperCase())); } else { int SHOW_LOG_LENGTH = Integer.parseInt(str[0]); if (file != null && file.exists()) { try { FileInputStream fis = new FileInputStream(file); FileChannel filechannel = fis.getChannel(); size = filechannel.size(); ByteBuffer bb; if (size <= SHOW_LOG_LENGTH) { bb = ByteBuffer.allocate((int) size); filechannel.read(bb, 0); } else { int pos = (int) (size - SHOW_LOG_LENGTH); bb = ByteBuffer.allocate(SHOW_LOG_LENGTH); filechannel.read(bb, pos); } bb.flip(); String content = new String(bb.array()).replace("<", "<") .replace(">", ">").replace("\n", "<br/><br/>"); buf.append("\r\ncontent:" + content); buf.append("\r\nmodified:" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .format(new Date(file.lastModified())))); buf.append("\r\nsize:" + size + "\r\n"); } catch (Exception e) { buf.append(e.getMessage()); } } else { size = 0; buf.append("\r\nMESSAGE: log file not exists or log appender is console ."); } } } buf.append("\r\nCURRENT LOG LEVEL:" + LoggerFactory.getLevel()) .append("\r\nCURRENT LOG APPENDER:" + (file == null ? "console" : file.getAbsolutePath())); return buf.toString(); }
|
LogTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { long size = 0; File file = LoggerFactory.getFile(); StringBuffer buf = new StringBuffer(); if (message == null || message.trim().length() == 0) { buf.append("EXAMPLE: log error / log 100"); } else { String str[] = message.split(" "); if (!StringUtils.isInteger(str[0])) { LoggerFactory.setLevel(Level.valueOf(message.toUpperCase())); } else { int SHOW_LOG_LENGTH = Integer.parseInt(str[0]); if (file != null && file.exists()) { try { FileInputStream fis = new FileInputStream(file); FileChannel filechannel = fis.getChannel(); size = filechannel.size(); ByteBuffer bb; if (size <= SHOW_LOG_LENGTH) { bb = ByteBuffer.allocate((int) size); filechannel.read(bb, 0); } else { int pos = (int) (size - SHOW_LOG_LENGTH); bb = ByteBuffer.allocate(SHOW_LOG_LENGTH); filechannel.read(bb, pos); } bb.flip(); String content = new String(bb.array()).replace("<", "<") .replace(">", ">").replace("\n", "<br/><br/>"); buf.append("\r\ncontent:" + content); buf.append("\r\nmodified:" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .format(new Date(file.lastModified())))); buf.append("\r\nsize:" + size + "\r\n"); } catch (Exception e) { buf.append(e.getMessage()); } } else { size = 0; buf.append("\r\nMESSAGE: log file not exists or log appender is console ."); } } } buf.append("\r\nCURRENT LOG LEVEL:" + LoggerFactory.getLevel()) .append("\r\nCURRENT LOG APPENDER:" + (file == null ? "console" : file.getAbsolutePath())); return buf.toString(); } }
|
LogTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { long size = 0; File file = LoggerFactory.getFile(); StringBuffer buf = new StringBuffer(); if (message == null || message.trim().length() == 0) { buf.append("EXAMPLE: log error / log 100"); } else { String str[] = message.split(" "); if (!StringUtils.isInteger(str[0])) { LoggerFactory.setLevel(Level.valueOf(message.toUpperCase())); } else { int SHOW_LOG_LENGTH = Integer.parseInt(str[0]); if (file != null && file.exists()) { try { FileInputStream fis = new FileInputStream(file); FileChannel filechannel = fis.getChannel(); size = filechannel.size(); ByteBuffer bb; if (size <= SHOW_LOG_LENGTH) { bb = ByteBuffer.allocate((int) size); filechannel.read(bb, 0); } else { int pos = (int) (size - SHOW_LOG_LENGTH); bb = ByteBuffer.allocate(SHOW_LOG_LENGTH); filechannel.read(bb, pos); } bb.flip(); String content = new String(bb.array()).replace("<", "<") .replace(">", ">").replace("\n", "<br/><br/>"); buf.append("\r\ncontent:" + content); buf.append("\r\nmodified:" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .format(new Date(file.lastModified())))); buf.append("\r\nsize:" + size + "\r\n"); } catch (Exception e) { buf.append(e.getMessage()); } } else { size = 0; buf.append("\r\nMESSAGE: log file not exists or log appender is console ."); } } } buf.append("\r\nCURRENT LOG LEVEL:" + LoggerFactory.getLevel()) .append("\r\nCURRENT LOG APPENDER:" + (file == null ? "console" : file.getAbsolutePath())); return buf.toString(); } }
|
LogTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { long size = 0; File file = LoggerFactory.getFile(); StringBuffer buf = new StringBuffer(); if (message == null || message.trim().length() == 0) { buf.append("EXAMPLE: log error / log 100"); } else { String str[] = message.split(" "); if (!StringUtils.isInteger(str[0])) { LoggerFactory.setLevel(Level.valueOf(message.toUpperCase())); } else { int SHOW_LOG_LENGTH = Integer.parseInt(str[0]); if (file != null && file.exists()) { try { FileInputStream fis = new FileInputStream(file); FileChannel filechannel = fis.getChannel(); size = filechannel.size(); ByteBuffer bb; if (size <= SHOW_LOG_LENGTH) { bb = ByteBuffer.allocate((int) size); filechannel.read(bb, 0); } else { int pos = (int) (size - SHOW_LOG_LENGTH); bb = ByteBuffer.allocate(SHOW_LOG_LENGTH); filechannel.read(bb, pos); } bb.flip(); String content = new String(bb.array()).replace("<", "<") .replace(">", ">").replace("\n", "<br/><br/>"); buf.append("\r\ncontent:" + content); buf.append("\r\nmodified:" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .format(new Date(file.lastModified())))); buf.append("\r\nsize:" + size + "\r\n"); } catch (Exception e) { buf.append(e.getMessage()); } } else { size = 0; buf.append("\r\nMESSAGE: log file not exists or log appender is console ."); } } } buf.append("\r\nCURRENT LOG LEVEL:" + LoggerFactory.getLevel()) .append("\r\nCURRENT LOG APPENDER:" + (file == null ? "console" : file.getAbsolutePath())); return buf.toString(); } String telnet(Channel channel, String message); }
|
LogTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { long size = 0; File file = LoggerFactory.getFile(); StringBuffer buf = new StringBuffer(); if (message == null || message.trim().length() == 0) { buf.append("EXAMPLE: log error / log 100"); } else { String str[] = message.split(" "); if (!StringUtils.isInteger(str[0])) { LoggerFactory.setLevel(Level.valueOf(message.toUpperCase())); } else { int SHOW_LOG_LENGTH = Integer.parseInt(str[0]); if (file != null && file.exists()) { try { FileInputStream fis = new FileInputStream(file); FileChannel filechannel = fis.getChannel(); size = filechannel.size(); ByteBuffer bb; if (size <= SHOW_LOG_LENGTH) { bb = ByteBuffer.allocate((int) size); filechannel.read(bb, 0); } else { int pos = (int) (size - SHOW_LOG_LENGTH); bb = ByteBuffer.allocate(SHOW_LOG_LENGTH); filechannel.read(bb, pos); } bb.flip(); String content = new String(bb.array()).replace("<", "<") .replace(">", ">").replace("\n", "<br/><br/>"); buf.append("\r\ncontent:" + content); buf.append("\r\nmodified:" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .format(new Date(file.lastModified())))); buf.append("\r\nsize:" + size + "\r\n"); } catch (Exception e) { buf.append(e.getMessage()); } } else { size = 0; buf.append("\r\nMESSAGE: log file not exists or log appender is console ."); } } } buf.append("\r\nCURRENT LOG LEVEL:" + LoggerFactory.getLevel()) .append("\r\nCURRENT LOG APPENDER:" + (file == null ? "console" : file.getAbsolutePath())); return buf.toString(); } String telnet(Channel channel, String message); static final String SERVICE_KEY; }
|
@Test public void testListClient() throws Exception { ExchangeClient client1 = Exchangers.connect("dubbo: ExchangeClient client2 = Exchangers.connect("dubbo: Thread.sleep(5000); String result = port.telnet(null, "-l 20887"); String client1Addr = client1.getLocalAddress().toString(); String client2Addr = client2.getLocalAddress().toString(); System.out.printf("Result: %s %n", result); System.out.printf("Client 1 Address %s %n", client1Addr); System.out.printf("Client 2 Address %s %n", client2Addr); assertTrue(result.contains(client1Addr)); assertTrue(result.contains(client2Addr)); }
|
public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } String telnet(Channel channel, String message); }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } String telnet(Channel channel, String message); }
|
@Test public void testListDetail() throws RemotingException { String result = port.telnet(null, "-l"); assertEquals("dubbo: }
|
public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } String telnet(Channel channel, String message); }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } String telnet(Channel channel, String message); }
|
@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: Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo: Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo: invokers.add(invoker1); invokers.add(invoker2); invokers.add(invoker3); List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer: Assert.assertEquals(2, fileredInvokers.size()); Assert.assertEquals(invoker2, fileredInvokers.get(0)); Assert.assertEquals(invoker3, fileredInvokers.get(1)); }
|
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); URL getUrl(); int compareTo(Router o); boolean matchWhen(URL url); boolean matchThen(URL url, URL param); }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); URL getUrl(); int compareTo(Router o); boolean matchWhen(URL url); boolean matchThen(URL url, URL param); }
|
@Test public void testListAllPort() throws RemotingException { String result = port.telnet(null, ""); assertEquals("20887", result); }
|
public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } String telnet(Channel channel, String message); }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } String telnet(Channel channel, String message); }
|
@Test public void testErrorMessage() throws RemotingException { String result = port.telnet(null, "a"); assertEquals("Illegal port a, must be integer.", result); }
|
public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } String telnet(Channel channel, String message); }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } String telnet(Channel channel, String message); }
|
@Test public void testNoPort() throws RemotingException { String result = port.telnet(null, "-l 20880"); assertEquals("No such port 20880", result); }
|
public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } String telnet(Channel channel, String message); }
|
PortTelnetHandler implements TelnetHandler { public String telnet(Channel channel, String message) { StringBuilder buf = new StringBuilder(); String port = null; boolean detail = false; if (message.length() > 0) { String[] parts = message.split("\\s+"); for (String part : parts) { if ("-l".equals(part)) { detail = true; } else { if (!StringUtils.isInteger(part)) { return "Illegal port " + part + ", must be integer."; } port = part; } } } if (port == null || port.length() == 0) { for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(server.getUrl().getProtocol() + ": } else { buf.append(server.getUrl().getPort()); } } } else { int p = Integer.parseInt(port); ExchangeServer server = null; for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) { if (p == s.getUrl().getPort()) { server = s; break; } } if (server != null) { Collection<ExchangeChannel> channels = server.getExchangeChannels(); for (ExchangeChannel c : channels) { if (buf.length() > 0) { buf.append("\r\n"); } if (detail) { buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress()); } else { buf.append(c.getRemoteAddress()); } } } else { buf.append("No such port " + port); } } return buf.toString(); } String telnet(Channel channel, String message); }
|
@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: Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo: Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo: invokers.add(invoker1); invokers.add(invoker2); invokers.add(invoker3); List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer: Assert.assertEquals(2, fileredInvokers.size()); Assert.assertEquals(invoker2, fileredInvokers.get(0)); Assert.assertEquals(invoker3, fileredInvokers.get(1)); }
|
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); URL getUrl(); int compareTo(Router o); boolean matchWhen(URL url); boolean matchThen(URL url, URL param); }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); URL getUrl(); int compareTo(Router o); boolean matchWhen(URL url); boolean matchThen(URL url, URL param); }
|
@Test public void testDubboProtocol() throws Exception { DemoService service = new DemoServiceImpl(); protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo: service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo: assertEquals(service.enumlength(new Type[]{}), Type.Lower); assertEquals(service.getSize(null), -1); assertEquals(service.getSize(new String[]{"", "", ""}), 3); Map<String, String> map = new HashMap<String, String>(); map.put("aa", "bb"); Set<String> set = service.keys(map); assertEquals(set.size(), 1); assertEquals(set.iterator().next(), "aa"); service.invoke("dubbo: service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo: StringBuffer buf = new StringBuffer(); for (int i = 0; i < 1024 * 32 + 32; i++) buf.append('A'); System.out.println(service.stringLength(buf.toString())); EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("dubbo: assertEquals(echo.$echo(buf.toString()), buf.toString()); assertEquals(echo.$echo("test"), "test"); assertEquals(echo.$echo("abcdefg"), "abcdefg"); assertEquals(echo.$echo(1234), 1234); }
|
public DubboProtocol() { INSTANCE = this; }
|
DubboProtocol extends AbstractProtocol { public DubboProtocol() { INSTANCE = this; } }
|
DubboProtocol extends AbstractProtocol { public DubboProtocol() { INSTANCE = this; } DubboProtocol(); }
|
DubboProtocol extends AbstractProtocol { public DubboProtocol() { INSTANCE = this; } DubboProtocol(); static DubboProtocol getDubboProtocol(); Collection<ExchangeServer> getServers(); Collection<Exporter<?>> getExporters(); Collection<Invoker<?>> getInvokers(); int getDefaultPort(); Exporter<T> export(Invoker<T> invoker); Invoker<T> refer(Class<T> serviceType, URL url); void destroy(); }
|
DubboProtocol extends AbstractProtocol { public DubboProtocol() { INSTANCE = this; } DubboProtocol(); static DubboProtocol getDubboProtocol(); Collection<ExchangeServer> getServers(); Collection<Exporter<?>> getExporters(); Collection<Invoker<?>> getInvokers(); int getDefaultPort(); Exporter<T> export(Invoker<T> invoker); Invoker<T> refer(Class<T> serviceType, URL url); void destroy(); static final String NAME; static final String COMPATIBLE_CODEC_NAME; static final int DEFAULT_PORT; final ReentrantLock lock; }
|
@Test public void testIsInjvmRefer() throws Exception { DemoService service = new DemoServiceImpl(); URL url = URL.valueOf("injvm: .addParameter(Constants.INTERFACE_KEY, DemoService.class.getName()); Exporter<?> exporter = protocol.export(proxy.getInvoker(service, DemoService.class, url)); exporters.add(exporter); url = url.setProtocol("dubbo"); assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url)); url = url.addParameter(Constants.GROUP_KEY, "*") .addParameter(Constants.VERSION_KEY, "*"); assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url)); }
|
public boolean isInjvmRefer(URL url) { final boolean isJvmRefer; String scope = url.getParameter(Constants.SCOPE_KEY); if (Constants.LOCAL_PROTOCOL.toString().equals(url.getProtocol())) { isJvmRefer = false; } else if (Constants.SCOPE_LOCAL.equals(scope) || (url.getParameter("injvm", false))) { isJvmRefer = true; } else if (Constants.SCOPE_REMOTE.equals(scope)) { isJvmRefer = false; } else if (url.getParameter(Constants.GENERIC_KEY, false)) { isJvmRefer = false; } else if (getExporter(exporterMap, url) != null) { isJvmRefer = true; } else { isJvmRefer = false; } return isJvmRefer; }
|
InjvmProtocol extends AbstractProtocol implements Protocol { public boolean isInjvmRefer(URL url) { final boolean isJvmRefer; String scope = url.getParameter(Constants.SCOPE_KEY); if (Constants.LOCAL_PROTOCOL.toString().equals(url.getProtocol())) { isJvmRefer = false; } else if (Constants.SCOPE_LOCAL.equals(scope) || (url.getParameter("injvm", false))) { isJvmRefer = true; } else if (Constants.SCOPE_REMOTE.equals(scope)) { isJvmRefer = false; } else if (url.getParameter(Constants.GENERIC_KEY, false)) { isJvmRefer = false; } else if (getExporter(exporterMap, url) != null) { isJvmRefer = true; } else { isJvmRefer = false; } return isJvmRefer; } }
|
InjvmProtocol extends AbstractProtocol implements Protocol { public boolean isInjvmRefer(URL url) { final boolean isJvmRefer; String scope = url.getParameter(Constants.SCOPE_KEY); if (Constants.LOCAL_PROTOCOL.toString().equals(url.getProtocol())) { isJvmRefer = false; } else if (Constants.SCOPE_LOCAL.equals(scope) || (url.getParameter("injvm", false))) { isJvmRefer = true; } else if (Constants.SCOPE_REMOTE.equals(scope)) { isJvmRefer = false; } else if (url.getParameter(Constants.GENERIC_KEY, false)) { isJvmRefer = false; } else if (getExporter(exporterMap, url) != null) { isJvmRefer = true; } else { isJvmRefer = false; } return isJvmRefer; } InjvmProtocol(); }
|
InjvmProtocol extends AbstractProtocol implements Protocol { public boolean isInjvmRefer(URL url) { final boolean isJvmRefer; String scope = url.getParameter(Constants.SCOPE_KEY); if (Constants.LOCAL_PROTOCOL.toString().equals(url.getProtocol())) { isJvmRefer = false; } else if (Constants.SCOPE_LOCAL.equals(scope) || (url.getParameter("injvm", false))) { isJvmRefer = true; } else if (Constants.SCOPE_REMOTE.equals(scope)) { isJvmRefer = false; } else if (url.getParameter(Constants.GENERIC_KEY, false)) { isJvmRefer = false; } else if (getExporter(exporterMap, url) != null) { isJvmRefer = true; } else { isJvmRefer = false; } return isJvmRefer; } InjvmProtocol(); int getDefaultPort(); static InjvmProtocol getInjvmProtocol(); Exporter<T> export(Invoker<T> invoker); Invoker<T> refer(Class<T> serviceType, URL url); boolean isInjvmRefer(URL url); }
|
InjvmProtocol extends AbstractProtocol implements Protocol { public boolean isInjvmRefer(URL url) { final boolean isJvmRefer; String scope = url.getParameter(Constants.SCOPE_KEY); if (Constants.LOCAL_PROTOCOL.toString().equals(url.getProtocol())) { isJvmRefer = false; } else if (Constants.SCOPE_LOCAL.equals(scope) || (url.getParameter("injvm", false))) { isJvmRefer = true; } else if (Constants.SCOPE_REMOTE.equals(scope)) { isJvmRefer = false; } else if (url.getParameter(Constants.GENERIC_KEY, false)) { isJvmRefer = false; } else if (getExporter(exporterMap, url) != null) { isJvmRefer = true; } else { isJvmRefer = false; } return isJvmRefer; } InjvmProtocol(); int getDefaultPort(); static InjvmProtocol getInjvmProtocol(); Exporter<T> export(Invoker<T> invoker); Invoker<T> refer(Class<T> serviceType, URL url); boolean isInjvmRefer(URL url); static final String NAME; static final int DEFAULT_PORT; }
|
@Test public void testEncodeRequest() throws Exception { Request request = createRequest(); ChannelBuffer output = ChannelBuffers.dynamicBuffer(1024); codec.encode(channel, output, request); byte[] bytes = new byte[output.readableBytes()]; output.readBytes(bytes); ByteArrayInputStream bis = new ByteArrayInputStream(bytes); TTransport transport = new TIOStreamTransport(bis); TBinaryProtocol protocol = new TBinaryProtocol(transport); byte[] length = new byte[4]; transport.read(length, 0, 4); if (bis.markSupported()) { bis.mark(0); } Assert.assertEquals(ThriftCodec.MAGIC, protocol.readI16()); int messageLength = protocol.readI32(); Assert.assertEquals(messageLength + 4, bytes.length); short headerLength = protocol.readI16(); Assert.assertEquals(ThriftCodec.VERSION, protocol.readByte()); Assert.assertEquals(Demo.Iface.class.getName(), protocol.readString()); Assert.assertEquals(request.getId(), protocol.readI64()); if (bis.markSupported()) { bis.reset(); bis.skip(headerLength); } TMessage message = protocol.readMessageBegin(); Demo.echoString_args args = new Demo.echoString_args(); args.read(protocol); protocol.readMessageEnd(); Assert.assertEquals("echoString", message.name); Assert.assertEquals(TMessageType.CALL, message.type); Assert.assertEquals("Hello, World!", args.getArg()); }
|
private void encodeRequest(Channel channel, ChannelBuffer buffer, Request request) throws IOException { RpcInvocation inv = (RpcInvocation) request.getData(); int seqId = nextSeqId(); String serviceName = inv.getAttachment(Constants.INTERFACE_KEY); if (StringUtils.isEmpty(serviceName)) { throw new IllegalArgumentException( new StringBuilder(32) .append("Could not find service name in attachment with key ") .append(Constants.INTERFACE_KEY) .toString()); } TMessage message = new TMessage( inv.getMethodName(), TMessageType.CALL, seqId); String methodArgs = ExtensionLoader.getExtensionLoader(ClassNameGenerator.class) .getExtension(channel.getUrl().getParameter(ThriftConstants.CLASS_NAME_GENERATOR_KEY, ThriftClassNameGenerator.NAME)) .generateArgsClassName(serviceName, inv.getMethodName()); if (StringUtils.isEmpty(methodArgs)) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, new StringBuilder(32).append( "Could not encode request, the specified interface may be incorrect.").toString()); } Class<?> clazz = cachedClass.get(methodArgs); if (clazz == null) { try { clazz = ClassHelper.forNameWithThreadContextClassLoader(methodArgs); cachedClass.putIfAbsent(methodArgs, clazz); } catch (ClassNotFoundException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } } TBase args; try { args = (TBase) clazz.newInstance(); } catch (InstantiationException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } catch (IllegalAccessException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } for (int i = 0; i < inv.getArguments().length; i++) { Object obj = inv.getArguments()[i]; if (obj == null) { continue; } TFieldIdEnum field = args.fieldForId(i + 1); String setMethodName = ThriftUtils.generateSetMethodName(field.getFieldName()); Method method; try { method = clazz.getMethod(setMethodName, inv.getParameterTypes()[i]); } catch (NoSuchMethodException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } try { method.invoke(args, obj); } catch (IllegalAccessException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } catch (InvocationTargetException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } } RandomAccessByteArrayOutputStream bos = new RandomAccessByteArrayOutputStream(1024); TIOStreamTransport transport = new TIOStreamTransport(bos); TBinaryProtocol protocol = new TBinaryProtocol(transport); int headerLength, messageLength; byte[] bytes = new byte[4]; try { protocol.writeI16(MAGIC); protocol.writeI32(Integer.MAX_VALUE); protocol.writeI16(Short.MAX_VALUE); protocol.writeByte(VERSION); protocol.writeString(serviceName); protocol.writeI64(request.getId()); protocol.getTransport().flush(); headerLength = bos.size(); protocol.writeMessageBegin(message); args.write(protocol); protocol.writeMessageEnd(); protocol.getTransport().flush(); int oldIndex = messageLength = bos.size(); try { TFramedTransport.encodeFrameSize(messageLength, bytes); bos.setWriteIndex(MESSAGE_LENGTH_INDEX); protocol.writeI32(messageLength); bos.setWriteIndex(MESSAGE_HEADER_LENGTH_INDEX); protocol.writeI16((short) (0xffff & headerLength)); } finally { bos.setWriteIndex(oldIndex); } } catch (TException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } buffer.writeBytes(bytes); buffer.writeBytes(bos.toByteArray()); }
|
ThriftCodec implements Codec2 { private void encodeRequest(Channel channel, ChannelBuffer buffer, Request request) throws IOException { RpcInvocation inv = (RpcInvocation) request.getData(); int seqId = nextSeqId(); String serviceName = inv.getAttachment(Constants.INTERFACE_KEY); if (StringUtils.isEmpty(serviceName)) { throw new IllegalArgumentException( new StringBuilder(32) .append("Could not find service name in attachment with key ") .append(Constants.INTERFACE_KEY) .toString()); } TMessage message = new TMessage( inv.getMethodName(), TMessageType.CALL, seqId); String methodArgs = ExtensionLoader.getExtensionLoader(ClassNameGenerator.class) .getExtension(channel.getUrl().getParameter(ThriftConstants.CLASS_NAME_GENERATOR_KEY, ThriftClassNameGenerator.NAME)) .generateArgsClassName(serviceName, inv.getMethodName()); if (StringUtils.isEmpty(methodArgs)) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, new StringBuilder(32).append( "Could not encode request, the specified interface may be incorrect.").toString()); } Class<?> clazz = cachedClass.get(methodArgs); if (clazz == null) { try { clazz = ClassHelper.forNameWithThreadContextClassLoader(methodArgs); cachedClass.putIfAbsent(methodArgs, clazz); } catch (ClassNotFoundException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } } TBase args; try { args = (TBase) clazz.newInstance(); } catch (InstantiationException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } catch (IllegalAccessException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } for (int i = 0; i < inv.getArguments().length; i++) { Object obj = inv.getArguments()[i]; if (obj == null) { continue; } TFieldIdEnum field = args.fieldForId(i + 1); String setMethodName = ThriftUtils.generateSetMethodName(field.getFieldName()); Method method; try { method = clazz.getMethod(setMethodName, inv.getParameterTypes()[i]); } catch (NoSuchMethodException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } try { method.invoke(args, obj); } catch (IllegalAccessException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } catch (InvocationTargetException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } } RandomAccessByteArrayOutputStream bos = new RandomAccessByteArrayOutputStream(1024); TIOStreamTransport transport = new TIOStreamTransport(bos); TBinaryProtocol protocol = new TBinaryProtocol(transport); int headerLength, messageLength; byte[] bytes = new byte[4]; try { protocol.writeI16(MAGIC); protocol.writeI32(Integer.MAX_VALUE); protocol.writeI16(Short.MAX_VALUE); protocol.writeByte(VERSION); protocol.writeString(serviceName); protocol.writeI64(request.getId()); protocol.getTransport().flush(); headerLength = bos.size(); protocol.writeMessageBegin(message); args.write(protocol); protocol.writeMessageEnd(); protocol.getTransport().flush(); int oldIndex = messageLength = bos.size(); try { TFramedTransport.encodeFrameSize(messageLength, bytes); bos.setWriteIndex(MESSAGE_LENGTH_INDEX); protocol.writeI32(messageLength); bos.setWriteIndex(MESSAGE_HEADER_LENGTH_INDEX); protocol.writeI16((short) (0xffff & headerLength)); } finally { bos.setWriteIndex(oldIndex); } } catch (TException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } buffer.writeBytes(bytes); buffer.writeBytes(bos.toByteArray()); } }
|
ThriftCodec implements Codec2 { private void encodeRequest(Channel channel, ChannelBuffer buffer, Request request) throws IOException { RpcInvocation inv = (RpcInvocation) request.getData(); int seqId = nextSeqId(); String serviceName = inv.getAttachment(Constants.INTERFACE_KEY); if (StringUtils.isEmpty(serviceName)) { throw new IllegalArgumentException( new StringBuilder(32) .append("Could not find service name in attachment with key ") .append(Constants.INTERFACE_KEY) .toString()); } TMessage message = new TMessage( inv.getMethodName(), TMessageType.CALL, seqId); String methodArgs = ExtensionLoader.getExtensionLoader(ClassNameGenerator.class) .getExtension(channel.getUrl().getParameter(ThriftConstants.CLASS_NAME_GENERATOR_KEY, ThriftClassNameGenerator.NAME)) .generateArgsClassName(serviceName, inv.getMethodName()); if (StringUtils.isEmpty(methodArgs)) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, new StringBuilder(32).append( "Could not encode request, the specified interface may be incorrect.").toString()); } Class<?> clazz = cachedClass.get(methodArgs); if (clazz == null) { try { clazz = ClassHelper.forNameWithThreadContextClassLoader(methodArgs); cachedClass.putIfAbsent(methodArgs, clazz); } catch (ClassNotFoundException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } } TBase args; try { args = (TBase) clazz.newInstance(); } catch (InstantiationException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } catch (IllegalAccessException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } for (int i = 0; i < inv.getArguments().length; i++) { Object obj = inv.getArguments()[i]; if (obj == null) { continue; } TFieldIdEnum field = args.fieldForId(i + 1); String setMethodName = ThriftUtils.generateSetMethodName(field.getFieldName()); Method method; try { method = clazz.getMethod(setMethodName, inv.getParameterTypes()[i]); } catch (NoSuchMethodException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } try { method.invoke(args, obj); } catch (IllegalAccessException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } catch (InvocationTargetException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } } RandomAccessByteArrayOutputStream bos = new RandomAccessByteArrayOutputStream(1024); TIOStreamTransport transport = new TIOStreamTransport(bos); TBinaryProtocol protocol = new TBinaryProtocol(transport); int headerLength, messageLength; byte[] bytes = new byte[4]; try { protocol.writeI16(MAGIC); protocol.writeI32(Integer.MAX_VALUE); protocol.writeI16(Short.MAX_VALUE); protocol.writeByte(VERSION); protocol.writeString(serviceName); protocol.writeI64(request.getId()); protocol.getTransport().flush(); headerLength = bos.size(); protocol.writeMessageBegin(message); args.write(protocol); protocol.writeMessageEnd(); protocol.getTransport().flush(); int oldIndex = messageLength = bos.size(); try { TFramedTransport.encodeFrameSize(messageLength, bytes); bos.setWriteIndex(MESSAGE_LENGTH_INDEX); protocol.writeI32(messageLength); bos.setWriteIndex(MESSAGE_HEADER_LENGTH_INDEX); protocol.writeI16((short) (0xffff & headerLength)); } finally { bos.setWriteIndex(oldIndex); } } catch (TException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } buffer.writeBytes(bytes); buffer.writeBytes(bos.toByteArray()); } }
|
ThriftCodec implements Codec2 { private void encodeRequest(Channel channel, ChannelBuffer buffer, Request request) throws IOException { RpcInvocation inv = (RpcInvocation) request.getData(); int seqId = nextSeqId(); String serviceName = inv.getAttachment(Constants.INTERFACE_KEY); if (StringUtils.isEmpty(serviceName)) { throw new IllegalArgumentException( new StringBuilder(32) .append("Could not find service name in attachment with key ") .append(Constants.INTERFACE_KEY) .toString()); } TMessage message = new TMessage( inv.getMethodName(), TMessageType.CALL, seqId); String methodArgs = ExtensionLoader.getExtensionLoader(ClassNameGenerator.class) .getExtension(channel.getUrl().getParameter(ThriftConstants.CLASS_NAME_GENERATOR_KEY, ThriftClassNameGenerator.NAME)) .generateArgsClassName(serviceName, inv.getMethodName()); if (StringUtils.isEmpty(methodArgs)) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, new StringBuilder(32).append( "Could not encode request, the specified interface may be incorrect.").toString()); } Class<?> clazz = cachedClass.get(methodArgs); if (clazz == null) { try { clazz = ClassHelper.forNameWithThreadContextClassLoader(methodArgs); cachedClass.putIfAbsent(methodArgs, clazz); } catch (ClassNotFoundException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } } TBase args; try { args = (TBase) clazz.newInstance(); } catch (InstantiationException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } catch (IllegalAccessException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } for (int i = 0; i < inv.getArguments().length; i++) { Object obj = inv.getArguments()[i]; if (obj == null) { continue; } TFieldIdEnum field = args.fieldForId(i + 1); String setMethodName = ThriftUtils.generateSetMethodName(field.getFieldName()); Method method; try { method = clazz.getMethod(setMethodName, inv.getParameterTypes()[i]); } catch (NoSuchMethodException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } try { method.invoke(args, obj); } catch (IllegalAccessException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } catch (InvocationTargetException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } } RandomAccessByteArrayOutputStream bos = new RandomAccessByteArrayOutputStream(1024); TIOStreamTransport transport = new TIOStreamTransport(bos); TBinaryProtocol protocol = new TBinaryProtocol(transport); int headerLength, messageLength; byte[] bytes = new byte[4]; try { protocol.writeI16(MAGIC); protocol.writeI32(Integer.MAX_VALUE); protocol.writeI16(Short.MAX_VALUE); protocol.writeByte(VERSION); protocol.writeString(serviceName); protocol.writeI64(request.getId()); protocol.getTransport().flush(); headerLength = bos.size(); protocol.writeMessageBegin(message); args.write(protocol); protocol.writeMessageEnd(); protocol.getTransport().flush(); int oldIndex = messageLength = bos.size(); try { TFramedTransport.encodeFrameSize(messageLength, bytes); bos.setWriteIndex(MESSAGE_LENGTH_INDEX); protocol.writeI32(messageLength); bos.setWriteIndex(MESSAGE_HEADER_LENGTH_INDEX); protocol.writeI16((short) (0xffff & headerLength)); } finally { bos.setWriteIndex(oldIndex); } } catch (TException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } buffer.writeBytes(bytes); buffer.writeBytes(bos.toByteArray()); } void encode(Channel channel, ChannelBuffer buffer, Object message); Object decode(Channel channel, ChannelBuffer buffer); }
|
ThriftCodec implements Codec2 { private void encodeRequest(Channel channel, ChannelBuffer buffer, Request request) throws IOException { RpcInvocation inv = (RpcInvocation) request.getData(); int seqId = nextSeqId(); String serviceName = inv.getAttachment(Constants.INTERFACE_KEY); if (StringUtils.isEmpty(serviceName)) { throw new IllegalArgumentException( new StringBuilder(32) .append("Could not find service name in attachment with key ") .append(Constants.INTERFACE_KEY) .toString()); } TMessage message = new TMessage( inv.getMethodName(), TMessageType.CALL, seqId); String methodArgs = ExtensionLoader.getExtensionLoader(ClassNameGenerator.class) .getExtension(channel.getUrl().getParameter(ThriftConstants.CLASS_NAME_GENERATOR_KEY, ThriftClassNameGenerator.NAME)) .generateArgsClassName(serviceName, inv.getMethodName()); if (StringUtils.isEmpty(methodArgs)) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, new StringBuilder(32).append( "Could not encode request, the specified interface may be incorrect.").toString()); } Class<?> clazz = cachedClass.get(methodArgs); if (clazz == null) { try { clazz = ClassHelper.forNameWithThreadContextClassLoader(methodArgs); cachedClass.putIfAbsent(methodArgs, clazz); } catch (ClassNotFoundException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } } TBase args; try { args = (TBase) clazz.newInstance(); } catch (InstantiationException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } catch (IllegalAccessException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } for (int i = 0; i < inv.getArguments().length; i++) { Object obj = inv.getArguments()[i]; if (obj == null) { continue; } TFieldIdEnum field = args.fieldForId(i + 1); String setMethodName = ThriftUtils.generateSetMethodName(field.getFieldName()); Method method; try { method = clazz.getMethod(setMethodName, inv.getParameterTypes()[i]); } catch (NoSuchMethodException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } try { method.invoke(args, obj); } catch (IllegalAccessException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } catch (InvocationTargetException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } } RandomAccessByteArrayOutputStream bos = new RandomAccessByteArrayOutputStream(1024); TIOStreamTransport transport = new TIOStreamTransport(bos); TBinaryProtocol protocol = new TBinaryProtocol(transport); int headerLength, messageLength; byte[] bytes = new byte[4]; try { protocol.writeI16(MAGIC); protocol.writeI32(Integer.MAX_VALUE); protocol.writeI16(Short.MAX_VALUE); protocol.writeByte(VERSION); protocol.writeString(serviceName); protocol.writeI64(request.getId()); protocol.getTransport().flush(); headerLength = bos.size(); protocol.writeMessageBegin(message); args.write(protocol); protocol.writeMessageEnd(); protocol.getTransport().flush(); int oldIndex = messageLength = bos.size(); try { TFramedTransport.encodeFrameSize(messageLength, bytes); bos.setWriteIndex(MESSAGE_LENGTH_INDEX); protocol.writeI32(messageLength); bos.setWriteIndex(MESSAGE_HEADER_LENGTH_INDEX); protocol.writeI16((short) (0xffff & headerLength)); } finally { bos.setWriteIndex(oldIndex); } } catch (TException e) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e); } buffer.writeBytes(bytes); buffer.writeBytes(bos.toByteArray()); } void encode(Channel channel, ChannelBuffer buffer, Object message); Object decode(Channel channel, ChannelBuffer buffer); static final int MESSAGE_LENGTH_INDEX; static final int MESSAGE_HEADER_LENGTH_INDEX; static final int MESSAGE_SHORTEST_LENGTH; static final String NAME; static final String PARAMETER_CLASS_NAME_GENERATOR; static final byte VERSION; static final short MAGIC; }
|
@Test public void testRefer() throws Exception { }
|
public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException { ThriftInvoker<T> invoker = new ThriftInvoker<T>(type, url, getClients(url), invokers); invokers.add(invoker); return invoker; }
|
ThriftProtocol extends AbstractProtocol { public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException { ThriftInvoker<T> invoker = new ThriftInvoker<T>(type, url, getClients(url), invokers); invokers.add(invoker); return invoker; } }
|
ThriftProtocol extends AbstractProtocol { public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException { ThriftInvoker<T> invoker = new ThriftInvoker<T>(type, url, getClients(url), invokers); invokers.add(invoker); return invoker; } }
|
ThriftProtocol extends AbstractProtocol { public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException { ThriftInvoker<T> invoker = new ThriftInvoker<T>(type, url, getClients(url), invokers); invokers.add(invoker); return invoker; } int getDefaultPort(); Exporter<T> export(Invoker<T> invoker); void destroy(); Invoker<T> refer(Class<T> type, URL url); }
|
ThriftProtocol extends AbstractProtocol { public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException { ThriftInvoker<T> invoker = new ThriftInvoker<T>(type, url, getClients(url), invokers); invokers.add(invoker); return invoker; } int getDefaultPort(); Exporter<T> export(Invoker<T> invoker); void destroy(); Invoker<T> refer(Class<T> type, URL url); static final int DEFAULT_PORT; static final String NAME; }
|
@Test public void testGenerateMethodArgsClassName() { Assert.assertEquals( $__DemoStub.echoString_args.class.getName(), ThriftUtils.generateMethodArgsClassName( com.alibaba.dubbo.rpc.gen.dubbo.Demo.class.getName(), "echoString")); Assert.assertEquals( $__DemoStub.echoString_args.class.getName(), ExtensionLoader.getExtensionLoader(ClassNameGenerator.class) .getExtension(DubboClassNameGenerator.NAME).generateArgsClassName( com.alibaba.dubbo.rpc.gen.dubbo.Demo.class.getName(), "echoString")); }
|
public static String generateMethodArgsClassName(String serviceName, String methodName) { int index = serviceName.lastIndexOf("."); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append("$__") .append(serviceName.substring(index + 1)) .append("Stub$") .append(methodName) .append("_args") .toString(); } else { return new StringBuffer(32) .append("$__") .append(serviceName) .append("Stub$") .append(methodName) .append("_args") .toString(); } }
|
ThriftUtils { public static String generateMethodArgsClassName(String serviceName, String methodName) { int index = serviceName.lastIndexOf("."); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append("$__") .append(serviceName.substring(index + 1)) .append("Stub$") .append(methodName) .append("_args") .toString(); } else { return new StringBuffer(32) .append("$__") .append(serviceName) .append("Stub$") .append(methodName) .append("_args") .toString(); } } }
|
ThriftUtils { public static String generateMethodArgsClassName(String serviceName, String methodName) { int index = serviceName.lastIndexOf("."); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append("$__") .append(serviceName.substring(index + 1)) .append("Stub$") .append(methodName) .append("_args") .toString(); } else { return new StringBuffer(32) .append("$__") .append(serviceName) .append("Stub$") .append(methodName) .append("_args") .toString(); } } }
|
ThriftUtils { public static String generateMethodArgsClassName(String serviceName, String methodName) { int index = serviceName.lastIndexOf("."); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append("$__") .append(serviceName.substring(index + 1)) .append("Stub$") .append(methodName) .append("_args") .toString(); } else { return new StringBuffer(32) .append("$__") .append(serviceName) .append("Stub$") .append(methodName) .append("_args") .toString(); } } static String generateMethodArgsClassName(String serviceName, String methodName); static String generateMethodResultClassName(String serviceName, String method); static String generateSetMethodName(String fieldName); static String generateGetMethodName(String fieldName); static String generateMethodArgsClassNameThrift(String serviceName, String methodName); static String generateMethodResultClassNameThrift(String serviceName, String methodName); }
|
ThriftUtils { public static String generateMethodArgsClassName(String serviceName, String methodName) { int index = serviceName.lastIndexOf("."); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append("$__") .append(serviceName.substring(index + 1)) .append("Stub$") .append(methodName) .append("_args") .toString(); } else { return new StringBuffer(32) .append("$__") .append(serviceName) .append("Stub$") .append(methodName) .append("_args") .toString(); } } static String generateMethodArgsClassName(String serviceName, String methodName); static String generateMethodResultClassName(String serviceName, String method); static String generateSetMethodName(String fieldName); static String generateGetMethodName(String fieldName); static String generateMethodArgsClassNameThrift(String serviceName, String methodName); static String generateMethodResultClassNameThrift(String serviceName, String methodName); }
|
@Test public void testGenerateMethodResultClassName() { Assert.assertEquals($__DemoStub.echoString_result.class.getName(), ThriftUtils.generateMethodResultClassName( com.alibaba.dubbo.rpc.gen.dubbo.Demo.class.getName(), "echoString")); Assert.assertEquals($__DemoStub.echoString_result.class.getName(), ExtensionLoader.getExtensionLoader(ClassNameGenerator.class) .getExtension(DubboClassNameGenerator.NAME).generateResultClassName( com.alibaba.dubbo.rpc.gen.dubbo.Demo.class.getName(), "echoString")); }
|
public static String generateMethodResultClassName(String serviceName, String method) { int index = serviceName.lastIndexOf("."); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append("$__") .append(serviceName.substring(index + 1)) .append("Stub$") .append(method) .append("_result") .toString(); } else { return new StringBuilder(32) .append("$__") .append(serviceName) .append("Stub$") .append(method) .append("_result") .toString(); } }
|
ThriftUtils { public static String generateMethodResultClassName(String serviceName, String method) { int index = serviceName.lastIndexOf("."); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append("$__") .append(serviceName.substring(index + 1)) .append("Stub$") .append(method) .append("_result") .toString(); } else { return new StringBuilder(32) .append("$__") .append(serviceName) .append("Stub$") .append(method) .append("_result") .toString(); } } }
|
ThriftUtils { public static String generateMethodResultClassName(String serviceName, String method) { int index = serviceName.lastIndexOf("."); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append("$__") .append(serviceName.substring(index + 1)) .append("Stub$") .append(method) .append("_result") .toString(); } else { return new StringBuilder(32) .append("$__") .append(serviceName) .append("Stub$") .append(method) .append("_result") .toString(); } } }
|
ThriftUtils { public static String generateMethodResultClassName(String serviceName, String method) { int index = serviceName.lastIndexOf("."); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append("$__") .append(serviceName.substring(index + 1)) .append("Stub$") .append(method) .append("_result") .toString(); } else { return new StringBuilder(32) .append("$__") .append(serviceName) .append("Stub$") .append(method) .append("_result") .toString(); } } static String generateMethodArgsClassName(String serviceName, String methodName); static String generateMethodResultClassName(String serviceName, String method); static String generateSetMethodName(String fieldName); static String generateGetMethodName(String fieldName); static String generateMethodArgsClassNameThrift(String serviceName, String methodName); static String generateMethodResultClassNameThrift(String serviceName, String methodName); }
|
ThriftUtils { public static String generateMethodResultClassName(String serviceName, String method) { int index = serviceName.lastIndexOf("."); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append("$__") .append(serviceName.substring(index + 1)) .append("Stub$") .append(method) .append("_result") .toString(); } else { return new StringBuilder(32) .append("$__") .append(serviceName) .append("Stub$") .append(method) .append("_result") .toString(); } } static String generateMethodArgsClassName(String serviceName, String methodName); static String generateMethodResultClassName(String serviceName, String method); static String generateSetMethodName(String fieldName); static String generateGetMethodName(String fieldName); static String generateMethodArgsClassNameThrift(String serviceName, String methodName); static String generateMethodResultClassNameThrift(String serviceName, String methodName); }
|
@Test public void testGenerateMethodArgsClassNameThrift() { Assert.assertEquals(com.alibaba.dubbo.rpc.gen.thrift.Demo.echoString_args.class.getName(), ThriftUtils.generateMethodArgsClassNameThrift( com.alibaba.dubbo.rpc.gen.thrift.Demo.Iface.class.getName(), "echoString")); Assert.assertEquals(com.alibaba.dubbo.rpc.gen.thrift.Demo.echoString_args.class.getName(), ExtensionLoader.getExtensionLoader(ClassNameGenerator.class) .getExtension(ThriftClassNameGenerator.NAME).generateArgsClassName( com.alibaba.dubbo.rpc.gen.thrift.Demo.Iface.class.getName(), "echoString")); }
|
public static String generateMethodArgsClassNameThrift(String serviceName, String methodName) { int index = serviceName.indexOf("$"); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append(methodName) .append("_args") .toString(); } return null; }
|
ThriftUtils { public static String generateMethodArgsClassNameThrift(String serviceName, String methodName) { int index = serviceName.indexOf("$"); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append(methodName) .append("_args") .toString(); } return null; } }
|
ThriftUtils { public static String generateMethodArgsClassNameThrift(String serviceName, String methodName) { int index = serviceName.indexOf("$"); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append(methodName) .append("_args") .toString(); } return null; } }
|
ThriftUtils { public static String generateMethodArgsClassNameThrift(String serviceName, String methodName) { int index = serviceName.indexOf("$"); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append(methodName) .append("_args") .toString(); } return null; } static String generateMethodArgsClassName(String serviceName, String methodName); static String generateMethodResultClassName(String serviceName, String method); static String generateSetMethodName(String fieldName); static String generateGetMethodName(String fieldName); static String generateMethodArgsClassNameThrift(String serviceName, String methodName); static String generateMethodResultClassNameThrift(String serviceName, String methodName); }
|
ThriftUtils { public static String generateMethodArgsClassNameThrift(String serviceName, String methodName) { int index = serviceName.indexOf("$"); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append(methodName) .append("_args") .toString(); } return null; } static String generateMethodArgsClassName(String serviceName, String methodName); static String generateMethodResultClassName(String serviceName, String method); static String generateSetMethodName(String fieldName); static String generateGetMethodName(String fieldName); static String generateMethodArgsClassNameThrift(String serviceName, String methodName); static String generateMethodResultClassNameThrift(String serviceName, String methodName); }
|
@Test public void testGenerateMethodResultClassNameThrift() { Assert.assertEquals(com.alibaba.dubbo.rpc.gen.thrift.Demo.echoString_result.class.getName(), ThriftUtils.generateMethodResultClassNameThrift( com.alibaba.dubbo.rpc.gen.thrift.Demo.Iface.class.getName(), "echoString")); Assert.assertEquals(com.alibaba.dubbo.rpc.gen.thrift.Demo.echoString_result.class.getName(), ExtensionLoader.getExtensionLoader(ClassNameGenerator.class) .getExtension(ThriftClassNameGenerator.NAME).generateResultClassName( com.alibaba.dubbo.rpc.gen.thrift.Demo.Iface.class.getName(), "echoString")); }
|
public static String generateMethodResultClassNameThrift(String serviceName, String methodName) { int index = serviceName.indexOf("$"); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append(methodName) .append("_result") .toString(); } return null; }
|
ThriftUtils { public static String generateMethodResultClassNameThrift(String serviceName, String methodName) { int index = serviceName.indexOf("$"); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append(methodName) .append("_result") .toString(); } return null; } }
|
ThriftUtils { public static String generateMethodResultClassNameThrift(String serviceName, String methodName) { int index = serviceName.indexOf("$"); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append(methodName) .append("_result") .toString(); } return null; } }
|
ThriftUtils { public static String generateMethodResultClassNameThrift(String serviceName, String methodName) { int index = serviceName.indexOf("$"); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append(methodName) .append("_result") .toString(); } return null; } static String generateMethodArgsClassName(String serviceName, String methodName); static String generateMethodResultClassName(String serviceName, String method); static String generateSetMethodName(String fieldName); static String generateGetMethodName(String fieldName); static String generateMethodArgsClassNameThrift(String serviceName, String methodName); static String generateMethodResultClassNameThrift(String serviceName, String methodName); }
|
ThriftUtils { public static String generateMethodResultClassNameThrift(String serviceName, String methodName) { int index = serviceName.indexOf("$"); if (index > 0) { return new StringBuilder(32) .append(serviceName.substring(0, index + 1)) .append(methodName) .append("_result") .toString(); } return null; } static String generateMethodArgsClassName(String serviceName, String methodName); static String generateMethodResultClassName(String serviceName, String method); static String generateSetMethodName(String fieldName); static String generateGetMethodName(String fieldName); static String generateMethodArgsClassNameThrift(String serviceName, String methodName); static String generateMethodResultClassNameThrift(String serviceName, String methodName); }
|
@Test public void testRoute_NoForce() { Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = 1.2.3.4")); List<Invoker<String>> invokers = new ArrayList<Invoker<String>>(); Invoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo: Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo: Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo: invokers.add(invoker1); invokers.add(invoker2); invokers.add(invoker3); List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer: Assert.assertEquals(invokers, fileredInvokers); }
|
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); URL getUrl(); int compareTo(Router o); boolean matchWhen(URL url); boolean matchThen(URL url, URL param); }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); URL getUrl(); int compareTo(Router o); boolean matchWhen(URL url); boolean matchThen(URL url, URL param); }
|
@SuppressWarnings("unchecked") @Test public void testRpcException() { Logger logger = EasyMock.createMock(Logger.class); RpcContext.getContext().setRemoteAddress("127.0.0.1", 1234); RpcException exception = new RpcException("TestRpcException"); logger.error(EasyMock.eq("Got unchecked and undeclared exception which called by 127.0.0.1. service: " + DemoService.class.getName() + ", method: sayHello, exception: " + RpcException.class.getName() + ": TestRpcException"), EasyMock.eq(exception)); ExceptionFilter exceptionFilter = new ExceptionFilter(logger); RpcInvocation invocation = new RpcInvocation("sayHello", new Class<?>[]{String.class}, new Object[]{"world"}); Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class); EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class); EasyMock.expect(invoker.invoke(EasyMock.eq(invocation))).andThrow(exception); EasyMock.replay(logger, invoker); try { exceptionFilter.invoke(invoker, invocation); } catch (RpcException e) { assertEquals("TestRpcException", e.getMessage()); } EasyMock.verify(logger, invoker); RpcContext.removeContext(); }
|
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { try { Result result = invoker.invoke(invocation); if (result.hasException() && GenericService.class != invoker.getInterface()) { try { Throwable exception = result.getException(); if (!(exception instanceof RuntimeException) && (exception instanceof Exception)) { return result; } try { Method method = invoker.getInterface().getMethod(invocation.getMethodName(), invocation.getParameterTypes()); Class<?>[] exceptionClassses = method.getExceptionTypes(); for (Class<?> exceptionClass : exceptionClassses) { if (exception.getClass().equals(exceptionClass)) { return result; } } } catch (NoSuchMethodException e) { return result; } logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + exception.getClass().getName() + ": " + exception.getMessage(), exception); String serviceFile = ReflectUtils.getCodeBase(invoker.getInterface()); String exceptionFile = ReflectUtils.getCodeBase(exception.getClass()); if (serviceFile == null || exceptionFile == null || serviceFile.equals(exceptionFile)) { return result; } String className = exception.getClass().getName(); if (className.startsWith("java.") || className.startsWith("javax.")) { return result; } if (exception instanceof RpcException) { return result; } return new RpcResult(new RuntimeException(StringUtils.toString(exception))); } catch (Throwable e) { logger.warn("Fail to ExceptionFilter when called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); return result; } } return result; } catch (RuntimeException e) { logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); throw e; } }
|
ExceptionFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { try { Result result = invoker.invoke(invocation); if (result.hasException() && GenericService.class != invoker.getInterface()) { try { Throwable exception = result.getException(); if (!(exception instanceof RuntimeException) && (exception instanceof Exception)) { return result; } try { Method method = invoker.getInterface().getMethod(invocation.getMethodName(), invocation.getParameterTypes()); Class<?>[] exceptionClassses = method.getExceptionTypes(); for (Class<?> exceptionClass : exceptionClassses) { if (exception.getClass().equals(exceptionClass)) { return result; } } } catch (NoSuchMethodException e) { return result; } logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + exception.getClass().getName() + ": " + exception.getMessage(), exception); String serviceFile = ReflectUtils.getCodeBase(invoker.getInterface()); String exceptionFile = ReflectUtils.getCodeBase(exception.getClass()); if (serviceFile == null || exceptionFile == null || serviceFile.equals(exceptionFile)) { return result; } String className = exception.getClass().getName(); if (className.startsWith("java.") || className.startsWith("javax.")) { return result; } if (exception instanceof RpcException) { return result; } return new RpcResult(new RuntimeException(StringUtils.toString(exception))); } catch (Throwable e) { logger.warn("Fail to ExceptionFilter when called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); return result; } } return result; } catch (RuntimeException e) { logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); throw e; } } }
|
ExceptionFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { try { Result result = invoker.invoke(invocation); if (result.hasException() && GenericService.class != invoker.getInterface()) { try { Throwable exception = result.getException(); if (!(exception instanceof RuntimeException) && (exception instanceof Exception)) { return result; } try { Method method = invoker.getInterface().getMethod(invocation.getMethodName(), invocation.getParameterTypes()); Class<?>[] exceptionClassses = method.getExceptionTypes(); for (Class<?> exceptionClass : exceptionClassses) { if (exception.getClass().equals(exceptionClass)) { return result; } } } catch (NoSuchMethodException e) { return result; } logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + exception.getClass().getName() + ": " + exception.getMessage(), exception); String serviceFile = ReflectUtils.getCodeBase(invoker.getInterface()); String exceptionFile = ReflectUtils.getCodeBase(exception.getClass()); if (serviceFile == null || exceptionFile == null || serviceFile.equals(exceptionFile)) { return result; } String className = exception.getClass().getName(); if (className.startsWith("java.") || className.startsWith("javax.")) { return result; } if (exception instanceof RpcException) { return result; } return new RpcResult(new RuntimeException(StringUtils.toString(exception))); } catch (Throwable e) { logger.warn("Fail to ExceptionFilter when called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); return result; } } return result; } catch (RuntimeException e) { logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); throw e; } } ExceptionFilter(); ExceptionFilter(Logger logger); }
|
ExceptionFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { try { Result result = invoker.invoke(invocation); if (result.hasException() && GenericService.class != invoker.getInterface()) { try { Throwable exception = result.getException(); if (!(exception instanceof RuntimeException) && (exception instanceof Exception)) { return result; } try { Method method = invoker.getInterface().getMethod(invocation.getMethodName(), invocation.getParameterTypes()); Class<?>[] exceptionClassses = method.getExceptionTypes(); for (Class<?> exceptionClass : exceptionClassses) { if (exception.getClass().equals(exceptionClass)) { return result; } } } catch (NoSuchMethodException e) { return result; } logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + exception.getClass().getName() + ": " + exception.getMessage(), exception); String serviceFile = ReflectUtils.getCodeBase(invoker.getInterface()); String exceptionFile = ReflectUtils.getCodeBase(exception.getClass()); if (serviceFile == null || exceptionFile == null || serviceFile.equals(exceptionFile)) { return result; } String className = exception.getClass().getName(); if (className.startsWith("java.") || className.startsWith("javax.")) { return result; } if (exception instanceof RpcException) { return result; } return new RpcResult(new RuntimeException(StringUtils.toString(exception))); } catch (Throwable e) { logger.warn("Fail to ExceptionFilter when called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); return result; } } return result; } catch (RuntimeException e) { logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); throw e; } } ExceptionFilter(); ExceptionFilter(Logger logger); Result invoke(Invoker<?> invoker, Invocation invocation); }
|
ExceptionFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { try { Result result = invoker.invoke(invocation); if (result.hasException() && GenericService.class != invoker.getInterface()) { try { Throwable exception = result.getException(); if (!(exception instanceof RuntimeException) && (exception instanceof Exception)) { return result; } try { Method method = invoker.getInterface().getMethod(invocation.getMethodName(), invocation.getParameterTypes()); Class<?>[] exceptionClassses = method.getExceptionTypes(); for (Class<?> exceptionClass : exceptionClassses) { if (exception.getClass().equals(exceptionClass)) { return result; } } } catch (NoSuchMethodException e) { return result; } logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + exception.getClass().getName() + ": " + exception.getMessage(), exception); String serviceFile = ReflectUtils.getCodeBase(invoker.getInterface()); String exceptionFile = ReflectUtils.getCodeBase(exception.getClass()); if (serviceFile == null || exceptionFile == null || serviceFile.equals(exceptionFile)) { return result; } String className = exception.getClass().getName(); if (className.startsWith("java.") || className.startsWith("javax.")) { return result; } if (exception instanceof RpcException) { return result; } return new RpcResult(new RuntimeException(StringUtils.toString(exception))); } catch (Throwable e) { logger.warn("Fail to ExceptionFilter when called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); return result; } } return result; } catch (RuntimeException e) { logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); throw e; } } ExceptionFilter(); ExceptionFilter(Logger logger); Result invoke(Invoker<?> invoker, Invocation invocation); }
|
@Test public void testDeprecatedFilter() { URL url = URL.valueOf("test: LogUtil.start(); deprecatedFilter.invoke(new MyInvoker<DemoService>(url), new MockInvocation()); assertEquals(1, LogUtil.findMessage("The service method com.alibaba.dubbo.rpc.support.DemoService.echo(String) is DEPRECATED")); LogUtil.stop(); }
|
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { String key = invoker.getInterface().getName() + "." + invocation.getMethodName(); if (!logged.contains(key)) { logged.add(key); if (invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.DEPRECATED_KEY, false)) { LOGGER.error("The service method " + invoker.getInterface().getName() + "." + getMethodSignature(invocation) + " is DEPRECATED! Declare from " + invoker.getUrl()); } } return invoker.invoke(invocation); }
|
DeprecatedFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { String key = invoker.getInterface().getName() + "." + invocation.getMethodName(); if (!logged.contains(key)) { logged.add(key); if (invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.DEPRECATED_KEY, false)) { LOGGER.error("The service method " + invoker.getInterface().getName() + "." + getMethodSignature(invocation) + " is DEPRECATED! Declare from " + invoker.getUrl()); } } return invoker.invoke(invocation); } }
|
DeprecatedFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { String key = invoker.getInterface().getName() + "." + invocation.getMethodName(); if (!logged.contains(key)) { logged.add(key); if (invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.DEPRECATED_KEY, false)) { LOGGER.error("The service method " + invoker.getInterface().getName() + "." + getMethodSignature(invocation) + " is DEPRECATED! Declare from " + invoker.getUrl()); } } return invoker.invoke(invocation); } }
|
DeprecatedFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { String key = invoker.getInterface().getName() + "." + invocation.getMethodName(); if (!logged.contains(key)) { logged.add(key); if (invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.DEPRECATED_KEY, false)) { LOGGER.error("The service method " + invoker.getInterface().getName() + "." + getMethodSignature(invocation) + " is DEPRECATED! Declare from " + invoker.getUrl()); } } return invoker.invoke(invocation); } Result invoke(Invoker<?> invoker, Invocation invocation); }
|
DeprecatedFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { String key = invoker.getInterface().getName() + "." + invocation.getMethodName(); if (!logged.contains(key)) { logged.add(key); if (invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.DEPRECATED_KEY, false)) { LOGGER.error("The service method " + invoker.getInterface().getName() + "." + getMethodSignature(invocation) + " is DEPRECATED! Declare from " + invoker.getUrl()); } } return invoker.invoke(invocation); } Result invoke(Invoker<?> invoker, Invocation invocation); }
|
@Test public void testInvokeNoActives() { URL url = URL.valueOf("test: Invoker<ActiveLimitFilterTest> invoker = new MyInvoker<ActiveLimitFilterTest>(url); Invocation invocation = new MockInvocation(); activeLimitFilter.invoke(invoker, invocation); }
|
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); String methodName = invocation.getMethodName(); int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0); RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); if (max > 0) { long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; int active = count.getActive(); if (active >= max) { synchronized (count) { while ((active = count.getActive()) >= max) { try { count.wait(remain); } catch (InterruptedException e) { } long elapsed = System.currentTimeMillis() - start; remain = timeout - elapsed; if (remain <= 0) { throw new RpcException("Waiting concurrent invoke timeout in client-side for service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", elapsed: " + elapsed + ", timeout: " + timeout + ". concurrent invokes: " + active + ". max concurrent invoke limit: " + max); } } } } } try { long begin = System.currentTimeMillis(); RpcStatus.beginCount(url, methodName); try { Result result = invoker.invoke(invocation); RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true); return result; } catch (RuntimeException t) { RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false); throw t; } } finally { if (max > 0) { synchronized (count) { count.notify(); } } } }
|
ActiveLimitFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); String methodName = invocation.getMethodName(); int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0); RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); if (max > 0) { long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; int active = count.getActive(); if (active >= max) { synchronized (count) { while ((active = count.getActive()) >= max) { try { count.wait(remain); } catch (InterruptedException e) { } long elapsed = System.currentTimeMillis() - start; remain = timeout - elapsed; if (remain <= 0) { throw new RpcException("Waiting concurrent invoke timeout in client-side for service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", elapsed: " + elapsed + ", timeout: " + timeout + ". concurrent invokes: " + active + ". max concurrent invoke limit: " + max); } } } } } try { long begin = System.currentTimeMillis(); RpcStatus.beginCount(url, methodName); try { Result result = invoker.invoke(invocation); RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true); return result; } catch (RuntimeException t) { RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false); throw t; } } finally { if (max > 0) { synchronized (count) { count.notify(); } } } } }
|
ActiveLimitFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); String methodName = invocation.getMethodName(); int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0); RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); if (max > 0) { long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; int active = count.getActive(); if (active >= max) { synchronized (count) { while ((active = count.getActive()) >= max) { try { count.wait(remain); } catch (InterruptedException e) { } long elapsed = System.currentTimeMillis() - start; remain = timeout - elapsed; if (remain <= 0) { throw new RpcException("Waiting concurrent invoke timeout in client-side for service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", elapsed: " + elapsed + ", timeout: " + timeout + ". concurrent invokes: " + active + ". max concurrent invoke limit: " + max); } } } } } try { long begin = System.currentTimeMillis(); RpcStatus.beginCount(url, methodName); try { Result result = invoker.invoke(invocation); RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true); return result; } catch (RuntimeException t) { RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false); throw t; } } finally { if (max > 0) { synchronized (count) { count.notify(); } } } } }
|
ActiveLimitFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); String methodName = invocation.getMethodName(); int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0); RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); if (max > 0) { long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; int active = count.getActive(); if (active >= max) { synchronized (count) { while ((active = count.getActive()) >= max) { try { count.wait(remain); } catch (InterruptedException e) { } long elapsed = System.currentTimeMillis() - start; remain = timeout - elapsed; if (remain <= 0) { throw new RpcException("Waiting concurrent invoke timeout in client-side for service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", elapsed: " + elapsed + ", timeout: " + timeout + ". concurrent invokes: " + active + ". max concurrent invoke limit: " + max); } } } } } try { long begin = System.currentTimeMillis(); RpcStatus.beginCount(url, methodName); try { Result result = invoker.invoke(invocation); RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true); return result; } catch (RuntimeException t) { RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false); throw t; } } finally { if (max > 0) { synchronized (count) { count.notify(); } } } } Result invoke(Invoker<?> invoker, Invocation invocation); }
|
ActiveLimitFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); String methodName = invocation.getMethodName(); int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0); RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); if (max > 0) { long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; int active = count.getActive(); if (active >= max) { synchronized (count) { while ((active = count.getActive()) >= max) { try { count.wait(remain); } catch (InterruptedException e) { } long elapsed = System.currentTimeMillis() - start; remain = timeout - elapsed; if (remain <= 0) { throw new RpcException("Waiting concurrent invoke timeout in client-side for service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", elapsed: " + elapsed + ", timeout: " + timeout + ". concurrent invokes: " + active + ". max concurrent invoke limit: " + max); } } } } } try { long begin = System.currentTimeMillis(); RpcStatus.beginCount(url, methodName); try { Result result = invoker.invoke(invocation); RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true); return result; } catch (RuntimeException t) { RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false); throw t; } } finally { if (max > 0) { synchronized (count) { count.notify(); } } } } Result invoke(Invoker<?> invoker, Invocation invocation); }
|
@Test public void testInvokeLessActives() { URL url = URL.valueOf("test: Invoker<ActiveLimitFilterTest> invoker = new MyInvoker<ActiveLimitFilterTest>(url); Invocation invocation = new MockInvocation(); activeLimitFilter.invoke(invoker, invocation); }
|
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); String methodName = invocation.getMethodName(); int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0); RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); if (max > 0) { long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; int active = count.getActive(); if (active >= max) { synchronized (count) { while ((active = count.getActive()) >= max) { try { count.wait(remain); } catch (InterruptedException e) { } long elapsed = System.currentTimeMillis() - start; remain = timeout - elapsed; if (remain <= 0) { throw new RpcException("Waiting concurrent invoke timeout in client-side for service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", elapsed: " + elapsed + ", timeout: " + timeout + ". concurrent invokes: " + active + ". max concurrent invoke limit: " + max); } } } } } try { long begin = System.currentTimeMillis(); RpcStatus.beginCount(url, methodName); try { Result result = invoker.invoke(invocation); RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true); return result; } catch (RuntimeException t) { RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false); throw t; } } finally { if (max > 0) { synchronized (count) { count.notify(); } } } }
|
ActiveLimitFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); String methodName = invocation.getMethodName(); int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0); RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); if (max > 0) { long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; int active = count.getActive(); if (active >= max) { synchronized (count) { while ((active = count.getActive()) >= max) { try { count.wait(remain); } catch (InterruptedException e) { } long elapsed = System.currentTimeMillis() - start; remain = timeout - elapsed; if (remain <= 0) { throw new RpcException("Waiting concurrent invoke timeout in client-side for service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", elapsed: " + elapsed + ", timeout: " + timeout + ". concurrent invokes: " + active + ". max concurrent invoke limit: " + max); } } } } } try { long begin = System.currentTimeMillis(); RpcStatus.beginCount(url, methodName); try { Result result = invoker.invoke(invocation); RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true); return result; } catch (RuntimeException t) { RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false); throw t; } } finally { if (max > 0) { synchronized (count) { count.notify(); } } } } }
|
ActiveLimitFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); String methodName = invocation.getMethodName(); int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0); RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); if (max > 0) { long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; int active = count.getActive(); if (active >= max) { synchronized (count) { while ((active = count.getActive()) >= max) { try { count.wait(remain); } catch (InterruptedException e) { } long elapsed = System.currentTimeMillis() - start; remain = timeout - elapsed; if (remain <= 0) { throw new RpcException("Waiting concurrent invoke timeout in client-side for service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", elapsed: " + elapsed + ", timeout: " + timeout + ". concurrent invokes: " + active + ". max concurrent invoke limit: " + max); } } } } } try { long begin = System.currentTimeMillis(); RpcStatus.beginCount(url, methodName); try { Result result = invoker.invoke(invocation); RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true); return result; } catch (RuntimeException t) { RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false); throw t; } } finally { if (max > 0) { synchronized (count) { count.notify(); } } } } }
|
ActiveLimitFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); String methodName = invocation.getMethodName(); int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0); RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); if (max > 0) { long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; int active = count.getActive(); if (active >= max) { synchronized (count) { while ((active = count.getActive()) >= max) { try { count.wait(remain); } catch (InterruptedException e) { } long elapsed = System.currentTimeMillis() - start; remain = timeout - elapsed; if (remain <= 0) { throw new RpcException("Waiting concurrent invoke timeout in client-side for service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", elapsed: " + elapsed + ", timeout: " + timeout + ". concurrent invokes: " + active + ". max concurrent invoke limit: " + max); } } } } } try { long begin = System.currentTimeMillis(); RpcStatus.beginCount(url, methodName); try { Result result = invoker.invoke(invocation); RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true); return result; } catch (RuntimeException t) { RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false); throw t; } } finally { if (max > 0) { synchronized (count) { count.notify(); } } } } Result invoke(Invoker<?> invoker, Invocation invocation); }
|
ActiveLimitFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); String methodName = invocation.getMethodName(); int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0); RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); if (max > 0) { long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; int active = count.getActive(); if (active >= max) { synchronized (count) { while ((active = count.getActive()) >= max) { try { count.wait(remain); } catch (InterruptedException e) { } long elapsed = System.currentTimeMillis() - start; remain = timeout - elapsed; if (remain <= 0) { throw new RpcException("Waiting concurrent invoke timeout in client-side for service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", elapsed: " + elapsed + ", timeout: " + timeout + ". concurrent invokes: " + active + ". max concurrent invoke limit: " + max); } } } } } try { long begin = System.currentTimeMillis(); RpcStatus.beginCount(url, methodName); try { Result result = invoker.invoke(invocation); RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true); return result; } catch (RuntimeException t) { RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false); throw t; } } finally { if (max > 0) { synchronized (count) { count.notify(); } } } } Result invoke(Invoker<?> invoker, Invocation invocation); }
|
@Test public void testInvokeGreaterActives() { URL url = URL.valueOf("test: final Invoker<ActiveLimitFilterTest> invoker = new MyInvoker<ActiveLimitFilterTest>(url); final Invocation invocation = new MockInvocation(); for (int i = 0; i < 100; i++) { Thread thread = new Thread(new Runnable() { public void run() { for (int i = 0; i < 100; i++) { try { activeLimitFilter.invoke(invoker, invocation); } catch (RpcException expected) { count++; } } } }); thread.start(); } try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } assertNotSame(0, count); }
|
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); String methodName = invocation.getMethodName(); int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0); RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); if (max > 0) { long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; int active = count.getActive(); if (active >= max) { synchronized (count) { while ((active = count.getActive()) >= max) { try { count.wait(remain); } catch (InterruptedException e) { } long elapsed = System.currentTimeMillis() - start; remain = timeout - elapsed; if (remain <= 0) { throw new RpcException("Waiting concurrent invoke timeout in client-side for service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", elapsed: " + elapsed + ", timeout: " + timeout + ". concurrent invokes: " + active + ". max concurrent invoke limit: " + max); } } } } } try { long begin = System.currentTimeMillis(); RpcStatus.beginCount(url, methodName); try { Result result = invoker.invoke(invocation); RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true); return result; } catch (RuntimeException t) { RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false); throw t; } } finally { if (max > 0) { synchronized (count) { count.notify(); } } } }
|
ActiveLimitFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); String methodName = invocation.getMethodName(); int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0); RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); if (max > 0) { long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; int active = count.getActive(); if (active >= max) { synchronized (count) { while ((active = count.getActive()) >= max) { try { count.wait(remain); } catch (InterruptedException e) { } long elapsed = System.currentTimeMillis() - start; remain = timeout - elapsed; if (remain <= 0) { throw new RpcException("Waiting concurrent invoke timeout in client-side for service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", elapsed: " + elapsed + ", timeout: " + timeout + ". concurrent invokes: " + active + ". max concurrent invoke limit: " + max); } } } } } try { long begin = System.currentTimeMillis(); RpcStatus.beginCount(url, methodName); try { Result result = invoker.invoke(invocation); RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true); return result; } catch (RuntimeException t) { RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false); throw t; } } finally { if (max > 0) { synchronized (count) { count.notify(); } } } } }
|
ActiveLimitFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); String methodName = invocation.getMethodName(); int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0); RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); if (max > 0) { long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; int active = count.getActive(); if (active >= max) { synchronized (count) { while ((active = count.getActive()) >= max) { try { count.wait(remain); } catch (InterruptedException e) { } long elapsed = System.currentTimeMillis() - start; remain = timeout - elapsed; if (remain <= 0) { throw new RpcException("Waiting concurrent invoke timeout in client-side for service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", elapsed: " + elapsed + ", timeout: " + timeout + ". concurrent invokes: " + active + ". max concurrent invoke limit: " + max); } } } } } try { long begin = System.currentTimeMillis(); RpcStatus.beginCount(url, methodName); try { Result result = invoker.invoke(invocation); RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true); return result; } catch (RuntimeException t) { RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false); throw t; } } finally { if (max > 0) { synchronized (count) { count.notify(); } } } } }
|
ActiveLimitFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); String methodName = invocation.getMethodName(); int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0); RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); if (max > 0) { long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; int active = count.getActive(); if (active >= max) { synchronized (count) { while ((active = count.getActive()) >= max) { try { count.wait(remain); } catch (InterruptedException e) { } long elapsed = System.currentTimeMillis() - start; remain = timeout - elapsed; if (remain <= 0) { throw new RpcException("Waiting concurrent invoke timeout in client-side for service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", elapsed: " + elapsed + ", timeout: " + timeout + ". concurrent invokes: " + active + ". max concurrent invoke limit: " + max); } } } } } try { long begin = System.currentTimeMillis(); RpcStatus.beginCount(url, methodName); try { Result result = invoker.invoke(invocation); RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true); return result; } catch (RuntimeException t) { RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false); throw t; } } finally { if (max > 0) { synchronized (count) { count.notify(); } } } } Result invoke(Invoker<?> invoker, Invocation invocation); }
|
ActiveLimitFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); String methodName = invocation.getMethodName(); int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0); RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); if (max > 0) { long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; int active = count.getActive(); if (active >= max) { synchronized (count) { while ((active = count.getActive()) >= max) { try { count.wait(remain); } catch (InterruptedException e) { } long elapsed = System.currentTimeMillis() - start; remain = timeout - elapsed; if (remain <= 0) { throw new RpcException("Waiting concurrent invoke timeout in client-side for service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", elapsed: " + elapsed + ", timeout: " + timeout + ". concurrent invokes: " + active + ". max concurrent invoke limit: " + max); } } } } } try { long begin = System.currentTimeMillis(); RpcStatus.beginCount(url, methodName); try { Result result = invoker.invoke(invocation); RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, true); return result; } catch (RuntimeException t) { RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, false); throw t; } } finally { if (max > 0) { synchronized (count) { count.notify(); } } } } Result invoke(Invoker<?> invoker, Invocation invocation); }
|
@SuppressWarnings("unchecked") @Test public void testSetContext() { invocation = EasyMock.createMock(Invocation.class); EasyMock.expect(invocation.getMethodName()).andReturn("$enumlength").anyTimes(); EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[]{Enum.class}).anyTimes(); EasyMock.expect(invocation.getArguments()).andReturn(new Object[]{"hello"}).anyTimes(); EasyMock.expect(invocation.getAttachments()).andReturn(null).anyTimes(); EasyMock.replay(invocation); invoker = EasyMock.createMock(Invoker.class); EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes(); EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes(); RpcResult result = new RpcResult(); result.setValue("High"); EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes(); URL url = URL.valueOf("test: EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes(); EasyMock.replay(invoker); contextFilter.invoke(invoker, invocation); assertNull(RpcContext.getContext().getInvoker()); }
|
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { Map<String, String> attachments = invocation.getAttachments(); if (attachments != null) { attachments = new HashMap<String, String>(attachments); attachments.remove(Constants.PATH_KEY); attachments.remove(Constants.GROUP_KEY); attachments.remove(Constants.VERSION_KEY); attachments.remove(Constants.DUBBO_VERSION_KEY); attachments.remove(Constants.TOKEN_KEY); attachments.remove(Constants.TIMEOUT_KEY); } RpcContext.getContext() .setInvoker(invoker) .setInvocation(invocation) .setAttachments(attachments) .setLocalAddress(invoker.getUrl().getHost(), invoker.getUrl().getPort()); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(invoker); } try { return invoker.invoke(invocation); } finally { RpcContext.removeContext(); } }
|
ContextFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { Map<String, String> attachments = invocation.getAttachments(); if (attachments != null) { attachments = new HashMap<String, String>(attachments); attachments.remove(Constants.PATH_KEY); attachments.remove(Constants.GROUP_KEY); attachments.remove(Constants.VERSION_KEY); attachments.remove(Constants.DUBBO_VERSION_KEY); attachments.remove(Constants.TOKEN_KEY); attachments.remove(Constants.TIMEOUT_KEY); } RpcContext.getContext() .setInvoker(invoker) .setInvocation(invocation) .setAttachments(attachments) .setLocalAddress(invoker.getUrl().getHost(), invoker.getUrl().getPort()); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(invoker); } try { return invoker.invoke(invocation); } finally { RpcContext.removeContext(); } } }
|
ContextFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { Map<String, String> attachments = invocation.getAttachments(); if (attachments != null) { attachments = new HashMap<String, String>(attachments); attachments.remove(Constants.PATH_KEY); attachments.remove(Constants.GROUP_KEY); attachments.remove(Constants.VERSION_KEY); attachments.remove(Constants.DUBBO_VERSION_KEY); attachments.remove(Constants.TOKEN_KEY); attachments.remove(Constants.TIMEOUT_KEY); } RpcContext.getContext() .setInvoker(invoker) .setInvocation(invocation) .setAttachments(attachments) .setLocalAddress(invoker.getUrl().getHost(), invoker.getUrl().getPort()); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(invoker); } try { return invoker.invoke(invocation); } finally { RpcContext.removeContext(); } } }
|
ContextFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { Map<String, String> attachments = invocation.getAttachments(); if (attachments != null) { attachments = new HashMap<String, String>(attachments); attachments.remove(Constants.PATH_KEY); attachments.remove(Constants.GROUP_KEY); attachments.remove(Constants.VERSION_KEY); attachments.remove(Constants.DUBBO_VERSION_KEY); attachments.remove(Constants.TOKEN_KEY); attachments.remove(Constants.TIMEOUT_KEY); } RpcContext.getContext() .setInvoker(invoker) .setInvocation(invocation) .setAttachments(attachments) .setLocalAddress(invoker.getUrl().getHost(), invoker.getUrl().getPort()); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(invoker); } try { return invoker.invoke(invocation); } finally { RpcContext.removeContext(); } } Result invoke(Invoker<?> invoker, Invocation invocation); }
|
ContextFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { Map<String, String> attachments = invocation.getAttachments(); if (attachments != null) { attachments = new HashMap<String, String>(attachments); attachments.remove(Constants.PATH_KEY); attachments.remove(Constants.GROUP_KEY); attachments.remove(Constants.VERSION_KEY); attachments.remove(Constants.DUBBO_VERSION_KEY); attachments.remove(Constants.TOKEN_KEY); attachments.remove(Constants.TIMEOUT_KEY); } RpcContext.getContext() .setInvoker(invoker) .setInvocation(invocation) .setAttachments(attachments) .setLocalAddress(invoker.getUrl().getHost(), invoker.getUrl().getPort()); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(invoker); } try { return invoker.invoke(invocation); } finally { RpcContext.removeContext(); } } Result invoke(Invoker<?> invoker, Invocation invocation); }
|
@Test public void testWithAttachments() { URL url = URL.valueOf("test: Invoker<DemoService> invoker = new MyInvoker<DemoService>(url); Invocation invocation = new MockInvocation(); Result result = contextFilter.invoke(invoker, invocation); assertNull(RpcContext.getContext().getInvoker()); }
|
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { Map<String, String> attachments = invocation.getAttachments(); if (attachments != null) { attachments = new HashMap<String, String>(attachments); attachments.remove(Constants.PATH_KEY); attachments.remove(Constants.GROUP_KEY); attachments.remove(Constants.VERSION_KEY); attachments.remove(Constants.DUBBO_VERSION_KEY); attachments.remove(Constants.TOKEN_KEY); attachments.remove(Constants.TIMEOUT_KEY); } RpcContext.getContext() .setInvoker(invoker) .setInvocation(invocation) .setAttachments(attachments) .setLocalAddress(invoker.getUrl().getHost(), invoker.getUrl().getPort()); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(invoker); } try { return invoker.invoke(invocation); } finally { RpcContext.removeContext(); } }
|
ContextFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { Map<String, String> attachments = invocation.getAttachments(); if (attachments != null) { attachments = new HashMap<String, String>(attachments); attachments.remove(Constants.PATH_KEY); attachments.remove(Constants.GROUP_KEY); attachments.remove(Constants.VERSION_KEY); attachments.remove(Constants.DUBBO_VERSION_KEY); attachments.remove(Constants.TOKEN_KEY); attachments.remove(Constants.TIMEOUT_KEY); } RpcContext.getContext() .setInvoker(invoker) .setInvocation(invocation) .setAttachments(attachments) .setLocalAddress(invoker.getUrl().getHost(), invoker.getUrl().getPort()); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(invoker); } try { return invoker.invoke(invocation); } finally { RpcContext.removeContext(); } } }
|
ContextFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { Map<String, String> attachments = invocation.getAttachments(); if (attachments != null) { attachments = new HashMap<String, String>(attachments); attachments.remove(Constants.PATH_KEY); attachments.remove(Constants.GROUP_KEY); attachments.remove(Constants.VERSION_KEY); attachments.remove(Constants.DUBBO_VERSION_KEY); attachments.remove(Constants.TOKEN_KEY); attachments.remove(Constants.TIMEOUT_KEY); } RpcContext.getContext() .setInvoker(invoker) .setInvocation(invocation) .setAttachments(attachments) .setLocalAddress(invoker.getUrl().getHost(), invoker.getUrl().getPort()); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(invoker); } try { return invoker.invoke(invocation); } finally { RpcContext.removeContext(); } } }
|
ContextFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { Map<String, String> attachments = invocation.getAttachments(); if (attachments != null) { attachments = new HashMap<String, String>(attachments); attachments.remove(Constants.PATH_KEY); attachments.remove(Constants.GROUP_KEY); attachments.remove(Constants.VERSION_KEY); attachments.remove(Constants.DUBBO_VERSION_KEY); attachments.remove(Constants.TOKEN_KEY); attachments.remove(Constants.TIMEOUT_KEY); } RpcContext.getContext() .setInvoker(invoker) .setInvocation(invocation) .setAttachments(attachments) .setLocalAddress(invoker.getUrl().getHost(), invoker.getUrl().getPort()); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(invoker); } try { return invoker.invoke(invocation); } finally { RpcContext.removeContext(); } } Result invoke(Invoker<?> invoker, Invocation invocation); }
|
ContextFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { Map<String, String> attachments = invocation.getAttachments(); if (attachments != null) { attachments = new HashMap<String, String>(attachments); attachments.remove(Constants.PATH_KEY); attachments.remove(Constants.GROUP_KEY); attachments.remove(Constants.VERSION_KEY); attachments.remove(Constants.DUBBO_VERSION_KEY); attachments.remove(Constants.TOKEN_KEY); attachments.remove(Constants.TIMEOUT_KEY); } RpcContext.getContext() .setInvoker(invoker) .setInvocation(invocation) .setAttachments(attachments) .setLocalAddress(invoker.getUrl().getHost(), invoker.getUrl().getPort()); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(invoker); } try { return invoker.invoke(invocation); } finally { RpcContext.removeContext(); } } Result invoke(Invoker<?> invoker, Invocation invocation); }
|
@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: Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo: Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo: invokers.add(invoker1); invokers.add(invoker2); invokers.add(invoker3); List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer: Assert.assertEquals(0, fileredInvokers.size()); }
|
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); URL getUrl(); int compareTo(Router o); boolean matchWhen(URL url); boolean matchThen(URL url, URL param); }
|
ConditionRouter implements Router, Comparable<Router> { public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException { if (invokers == null || invokers.size() == 0) { return invokers; } try { if (!matchWhen(url)) { return invokers; } List<Invoker<T>> result = new ArrayList<Invoker<T>>(); if (thenCondition == null) { logger.warn("The current consumer in the service blacklist. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey()); return result; } for (Invoker<T> invoker : invokers) { if (matchThen(invoker.getUrl(), url)) { result.add(invoker); } } if (result.size() > 0) { return result; } else if (force) { logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); return result; } } catch (Throwable t) { logger.error("Failed to execute condition router rule: " + getUrl() + ", invokers: " + invokers + ", cause: " + t.getMessage(), t); } return invokers; } ConditionRouter(URL url); List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); URL getUrl(); int compareTo(Router o); boolean matchWhen(URL url); boolean matchThen(URL url, URL param); }
|
@Test public void testSetContext() { URL url = URL.valueOf("test: Invoker<DemoService> invoker = new MyInvoker<DemoService>(url); Invocation invocation = new MockInvocation(); consumerContextFilter.invoke(invoker, invocation); assertEquals(invoker, RpcContext.getContext().getInvoker()); assertEquals(invocation, RpcContext.getContext().getInvocation()); assertEquals(NetUtils.getLocalHost() + ":0", RpcContext.getContext().getLocalAddressString()); assertEquals("test:11", RpcContext.getContext().getRemoteAddressString()); }
|
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { RpcContext.getContext() .setInvoker(invoker) .setInvocation(invocation) .setLocalAddress(NetUtils.getLocalHost(), 0) .setRemoteAddress(invoker.getUrl().getHost(), invoker.getUrl().getPort()); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(invoker); } try { return invoker.invoke(invocation); } finally { RpcContext.getContext().clearAttachments(); } }
|
ConsumerContextFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { RpcContext.getContext() .setInvoker(invoker) .setInvocation(invocation) .setLocalAddress(NetUtils.getLocalHost(), 0) .setRemoteAddress(invoker.getUrl().getHost(), invoker.getUrl().getPort()); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(invoker); } try { return invoker.invoke(invocation); } finally { RpcContext.getContext().clearAttachments(); } } }
|
ConsumerContextFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { RpcContext.getContext() .setInvoker(invoker) .setInvocation(invocation) .setLocalAddress(NetUtils.getLocalHost(), 0) .setRemoteAddress(invoker.getUrl().getHost(), invoker.getUrl().getPort()); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(invoker); } try { return invoker.invoke(invocation); } finally { RpcContext.getContext().clearAttachments(); } } }
|
ConsumerContextFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { RpcContext.getContext() .setInvoker(invoker) .setInvocation(invocation) .setLocalAddress(NetUtils.getLocalHost(), 0) .setRemoteAddress(invoker.getUrl().getHost(), invoker.getUrl().getPort()); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(invoker); } try { return invoker.invoke(invocation); } finally { RpcContext.getContext().clearAttachments(); } } Result invoke(Invoker<?> invoker, Invocation invocation); }
|
ConsumerContextFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { RpcContext.getContext() .setInvoker(invoker) .setInvocation(invocation) .setLocalAddress(NetUtils.getLocalHost(), 0) .setRemoteAddress(invoker.getUrl().getHost(), invoker.getUrl().getPort()); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(invoker); } try { return invoker.invoke(invocation); } finally { RpcContext.getContext().clearAttachments(); } } Result invoke(Invoker<?> invoker, Invocation invocation); }
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.