@Test public void testMergeUrl() throws Exception { URL providerURL = URL.valueOf("dubbo: providerURL = providerURL.setPath("path") .setUsername("username") .setPassword("password"); providerURL = providerURL.addParameter(Constants.GROUP_KEY, "dubbo") .addParameter(Constants.VERSION_KEY, "1.2.3") .addParameter(Constants.DUBBO_VERSION_KEY, "2.3.7") .addParameter(Constants.THREADPOOL_KEY, "fixed") .addParameter(Constants.THREADS_KEY, Integer.MAX_VALUE) .addParameter(Constants.THREAD_NAME_KEY, "test") .addParameter(Constants.CORE_THREADS_KEY, Integer.MAX_VALUE) .addParameter(Constants.QUEUES_KEY, Integer.MAX_VALUE) .addParameter(Constants.ALIVE_KEY, Integer.MAX_VALUE) .addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY, Integer.MAX_VALUE) .addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY, "fixed") .addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY, Integer.MAX_VALUE) .addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY, Integer.MAX_VALUE) .addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY, Integer.MAX_VALUE) .addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY, "test"); URL consumerURL = URL.valueOf("dubbo: consumerURL = consumerURL.addParameter(Constants.PID_KEY, "1234"); consumerURL = consumerURL.addParameter(Constants.THREADPOOL_KEY, "foo"); URL url = ClusterUtils.mergeUrl(providerURL, consumerURL.getParameters()); Assert.assertFalse(url.hasParameter(Constants.THREADS_KEY)); Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY)); Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY)); Assert.assertFalse(url.hasParameter(Constants.CORE_THREADS_KEY)); Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY)); Assert.assertFalse(url.hasParameter(Constants.QUEUES_KEY)); Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY)); Assert.assertFalse(url.hasParameter(Constants.ALIVE_KEY)); Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY)); Assert.assertFalse(url.hasParameter(Constants.THREAD_NAME_KEY)); Assert.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY)); Assert.assertEquals(url.getPath(), "path"); Assert.assertEquals(url.getUsername(), "username"); Assert.assertEquals(url.getPassword(), "password"); Assert.assertEquals(url.getParameter(Constants.PID_KEY), "1234"); Assert.assertEquals(url.getParameter(Constants.THREADPOOL_KEY), "foo"); }
public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) { Map<String, String> map = new HashMap<String, String>(); Map<String, String> remoteMap = remoteUrl.getParameters(); if (remoteMap != null && remoteMap.size() > 0) { map.putAll(remoteMap); map.remove(Constants.THREAD_NAME_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY); map.remove(Constants.THREADPOOL_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY); map.remove(Constants.CORE_THREADS_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY); map.remove(Constants.THREADS_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY); map.remove(Constants.QUEUES_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY); map.remove(Constants.ALIVE_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY); map.remove(Constants.TRANSPORTER_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.TRANSPORTER_KEY); } if (localMap != null && localMap.size() > 0) { map.putAll(localMap); } if (remoteMap != null && remoteMap.size() > 0) { String dubbo = remoteMap.get(Constants.DUBBO_VERSION_KEY); if (dubbo != null && dubbo.length() > 0) { map.put(Constants.DUBBO_VERSION_KEY, dubbo); } String version = remoteMap.get(Constants.VERSION_KEY); if (version != null && version.length() > 0) { map.put(Constants.VERSION_KEY, version); } String group = remoteMap.get(Constants.GROUP_KEY); if (group != null && group.length() > 0) { map.put(Constants.GROUP_KEY, group); } String methods = remoteMap.get(Constants.METHODS_KEY); if (methods != null && methods.length() > 0) { map.put(Constants.METHODS_KEY, methods); } String remoteTimestamp = remoteMap.get(Constants.TIMESTAMP_KEY); if (remoteTimestamp != null && remoteTimestamp.length() > 0) { map.put(Constants.REMOTE_TIMESTAMP_KEY, remoteMap.get(Constants.TIMESTAMP_KEY)); } String remoteFilter = remoteMap.get(Constants.REFERENCE_FILTER_KEY); String localFilter = localMap.get(Constants.REFERENCE_FILTER_KEY); if (remoteFilter != null && remoteFilter.length() > 0 && localFilter != null && localFilter.length() > 0) { localMap.put(Constants.REFERENCE_FILTER_KEY, remoteFilter + "," + localFilter); } String remoteListener = remoteMap.get(Constants.INVOKER_LISTENER_KEY); String localListener = localMap.get(Constants.INVOKER_LISTENER_KEY); if (remoteListener != null && remoteListener.length() > 0 && localListener != null && localListener.length() > 0) { localMap.put(Constants.INVOKER_LISTENER_KEY, remoteListener + "," + localListener); } } return remoteUrl.clearParameters().addParameters(map); }
ClusterUtils { public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) { Map<String, String> map = new HashMap<String, String>(); Map<String, String> remoteMap = remoteUrl.getParameters(); if (remoteMap != null && remoteMap.size() > 0) { map.putAll(remoteMap); map.remove(Constants.THREAD_NAME_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY); map.remove(Constants.THREADPOOL_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY); map.remove(Constants.CORE_THREADS_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY); map.remove(Constants.THREADS_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY); map.remove(Constants.QUEUES_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY); map.remove(Constants.ALIVE_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY); map.remove(Constants.TRANSPORTER_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.TRANSPORTER_KEY); } if (localMap != null && localMap.size() > 0) { map.putAll(localMap); } if (remoteMap != null && remoteMap.size() > 0) { String dubbo = remoteMap.get(Constants.DUBBO_VERSION_KEY); if (dubbo != null && dubbo.length() > 0) { map.put(Constants.DUBBO_VERSION_KEY, dubbo); } String version = remoteMap.get(Constants.VERSION_KEY); if (version != null && version.length() > 0) { map.put(Constants.VERSION_KEY, version); } String group = remoteMap.get(Constants.GROUP_KEY); if (group != null && group.length() > 0) { map.put(Constants.GROUP_KEY, group); } String methods = remoteMap.get(Constants.METHODS_KEY); if (methods != null && methods.length() > 0) { map.put(Constants.METHODS_KEY, methods); } String remoteTimestamp = remoteMap.get(Constants.TIMESTAMP_KEY); if (remoteTimestamp != null && remoteTimestamp.length() > 0) { map.put(Constants.REMOTE_TIMESTAMP_KEY, remoteMap.get(Constants.TIMESTAMP_KEY)); } String remoteFilter = remoteMap.get(Constants.REFERENCE_FILTER_KEY); String localFilter = localMap.get(Constants.REFERENCE_FILTER_KEY); if (remoteFilter != null && remoteFilter.length() > 0 && localFilter != null && localFilter.length() > 0) { localMap.put(Constants.REFERENCE_FILTER_KEY, remoteFilter + "," + localFilter); } String remoteListener = remoteMap.get(Constants.INVOKER_LISTENER_KEY); String localListener = localMap.get(Constants.INVOKER_LISTENER_KEY); if (remoteListener != null && remoteListener.length() > 0 && localListener != null && localListener.length() > 0) { localMap.put(Constants.INVOKER_LISTENER_KEY, remoteListener + "," + localListener); } } return remoteUrl.clearParameters().addParameters(map); } }
ClusterUtils { public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) { Map<String, String> map = new HashMap<String, String>(); Map<String, String> remoteMap = remoteUrl.getParameters(); if (remoteMap != null && remoteMap.size() > 0) { map.putAll(remoteMap); map.remove(Constants.THREAD_NAME_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY); map.remove(Constants.THREADPOOL_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY); map.remove(Constants.CORE_THREADS_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY); map.remove(Constants.THREADS_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY); map.remove(Constants.QUEUES_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY); map.remove(Constants.ALIVE_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY); map.remove(Constants.TRANSPORTER_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.TRANSPORTER_KEY); } if (localMap != null && localMap.size() > 0) { map.putAll(localMap); } if (remoteMap != null && remoteMap.size() > 0) { String dubbo = remoteMap.get(Constants.DUBBO_VERSION_KEY); if (dubbo != null && dubbo.length() > 0) { map.put(Constants.DUBBO_VERSION_KEY, dubbo); } String version = remoteMap.get(Constants.VERSION_KEY); if (version != null && version.length() > 0) { map.put(Constants.VERSION_KEY, version); } String group = remoteMap.get(Constants.GROUP_KEY); if (group != null && group.length() > 0) { map.put(Constants.GROUP_KEY, group); } String methods = remoteMap.get(Constants.METHODS_KEY); if (methods != null && methods.length() > 0) { map.put(Constants.METHODS_KEY, methods); } String remoteTimestamp = remoteMap.get(Constants.TIMESTAMP_KEY); if (remoteTimestamp != null && remoteTimestamp.length() > 0) { map.put(Constants.REMOTE_TIMESTAMP_KEY, remoteMap.get(Constants.TIMESTAMP_KEY)); } String remoteFilter = remoteMap.get(Constants.REFERENCE_FILTER_KEY); String localFilter = localMap.get(Constants.REFERENCE_FILTER_KEY); if (remoteFilter != null && remoteFilter.length() > 0 && localFilter != null && localFilter.length() > 0) { localMap.put(Constants.REFERENCE_FILTER_KEY, remoteFilter + "," + localFilter); } String remoteListener = remoteMap.get(Constants.INVOKER_LISTENER_KEY); String localListener = localMap.get(Constants.INVOKER_LISTENER_KEY); if (remoteListener != null && remoteListener.length() > 0 && localListener != null && localListener.length() > 0) { localMap.put(Constants.INVOKER_LISTENER_KEY, remoteListener + "," + localListener); } } return remoteUrl.clearParameters().addParameters(map); } private  ClusterUtils(); }
ClusterUtils { public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) { Map<String, String> map = new HashMap<String, String>(); Map<String, String> remoteMap = remoteUrl.getParameters(); if (remoteMap != null && remoteMap.size() > 0) { map.putAll(remoteMap); map.remove(Constants.THREAD_NAME_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY); map.remove(Constants.THREADPOOL_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY); map.remove(Constants.CORE_THREADS_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY); map.remove(Constants.THREADS_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY); map.remove(Constants.QUEUES_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY); map.remove(Constants.ALIVE_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY); map.remove(Constants.TRANSPORTER_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.TRANSPORTER_KEY); } if (localMap != null && localMap.size() > 0) { map.putAll(localMap); } if (remoteMap != null && remoteMap.size() > 0) { String dubbo = remoteMap.get(Constants.DUBBO_VERSION_KEY); if (dubbo != null && dubbo.length() > 0) { map.put(Constants.DUBBO_VERSION_KEY, dubbo); } String version = remoteMap.get(Constants.VERSION_KEY); if (version != null && version.length() > 0) { map.put(Constants.VERSION_KEY, version); } String group = remoteMap.get(Constants.GROUP_KEY); if (group != null && group.length() > 0) { map.put(Constants.GROUP_KEY, group); } String methods = remoteMap.get(Constants.METHODS_KEY); if (methods != null && methods.length() > 0) { map.put(Constants.METHODS_KEY, methods); } String remoteTimestamp = remoteMap.get(Constants.TIMESTAMP_KEY); if (remoteTimestamp != null && remoteTimestamp.length() > 0) { map.put(Constants.REMOTE_TIMESTAMP_KEY, remoteMap.get(Constants.TIMESTAMP_KEY)); } String remoteFilter = remoteMap.get(Constants.REFERENCE_FILTER_KEY); String localFilter = localMap.get(Constants.REFERENCE_FILTER_KEY); if (remoteFilter != null && remoteFilter.length() > 0 && localFilter != null && localFilter.length() > 0) { localMap.put(Constants.REFERENCE_FILTER_KEY, remoteFilter + "," + localFilter); } String remoteListener = remoteMap.get(Constants.INVOKER_LISTENER_KEY); String localListener = localMap.get(Constants.INVOKER_LISTENER_KEY); if (remoteListener != null && remoteListener.length() > 0 && localListener != null && localListener.length() > 0) { localMap.put(Constants.INVOKER_LISTENER_KEY, remoteListener + "," + localListener); } } return remoteUrl.clearParameters().addParameters(map); } private  ClusterUtils(); static URL mergeUrl(URL remoteUrl, Map<String, String> localMap); }
ClusterUtils { public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) { Map<String, String> map = new HashMap<String, String>(); Map<String, String> remoteMap = remoteUrl.getParameters(); if (remoteMap != null && remoteMap.size() > 0) { map.putAll(remoteMap); map.remove(Constants.THREAD_NAME_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY); map.remove(Constants.THREADPOOL_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY); map.remove(Constants.CORE_THREADS_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY); map.remove(Constants.THREADS_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY); map.remove(Constants.QUEUES_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY); map.remove(Constants.ALIVE_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY); map.remove(Constants.TRANSPORTER_KEY); map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.TRANSPORTER_KEY); } if (localMap != null && localMap.size() > 0) { map.putAll(localMap); } if (remoteMap != null && remoteMap.size() > 0) { String dubbo = remoteMap.get(Constants.DUBBO_VERSION_KEY); if (dubbo != null && dubbo.length() > 0) { map.put(Constants.DUBBO_VERSION_KEY, dubbo); } String version = remoteMap.get(Constants.VERSION_KEY); if (version != null && version.length() > 0) { map.put(Constants.VERSION_KEY, version); } String group = remoteMap.get(Constants.GROUP_KEY); if (group != null && group.length() > 0) { map.put(Constants.GROUP_KEY, group); } String methods = remoteMap.get(Constants.METHODS_KEY); if (methods != null && methods.length() > 0) { map.put(Constants.METHODS_KEY, methods); } String remoteTimestamp = remoteMap.get(Constants.TIMESTAMP_KEY); if (remoteTimestamp != null && remoteTimestamp.length() > 0) { map.put(Constants.REMOTE_TIMESTAMP_KEY, remoteMap.get(Constants.TIMESTAMP_KEY)); } String remoteFilter = remoteMap.get(Constants.REFERENCE_FILTER_KEY); String localFilter = localMap.get(Constants.REFERENCE_FILTER_KEY); if (remoteFilter != null && remoteFilter.length() > 0 && localFilter != null && localFilter.length() > 0) { localMap.put(Constants.REFERENCE_FILTER_KEY, remoteFilter + "," + localFilter); } String remoteListener = remoteMap.get(Constants.INVOKER_LISTENER_KEY); String localListener = localMap.get(Constants.INVOKER_LISTENER_KEY); if (remoteListener != null && remoteListener.length() > 0 && localListener != null && localListener.length() > 0) { localMap.put(Constants.INVOKER_LISTENER_KEY, remoteListener + "," + localListener); } } return remoteUrl.clearParameters().addParameters(map); } private  ClusterUtils(); static URL mergeUrl(URL remoteUrl, Map<String, String> localMap);  }