public ChannelHandlerDispatcher(Collection<ChannelHandler> handlers) { if (CollectionUtils.isNotEmpty(handlers)) { this.channelHandlers.addAll(handlers); } }
public void addUrlToRetry(List<URL> urls) { if (CollectionUtils.isEmpty(urls)) { return; } this.urls.addAll(urls); }
private static String[] getFilteredKeys(URL url) { Map<String, String> params = url.getParameters(); if (CollectionUtils.isNotEmptyMap(params)) { return params.keySet().stream() .filter(k -> k.startsWith(HIDE_KEY_PREFIX)) .toArray(String[]::new); } else { return new String[0]; } }
public StaticDirectory(URL url, List<Invoker<T>> invokers, RouterChain<T> routerChain) { super(url == null && CollectionUtils.isNotEmpty(invokers) ? invokers.get(0).getUrl() : url, routerChain); if (CollectionUtils.isEmpty(invokers)) { throw new IllegalArgumentException("invokers == null"); } this.invokers = invokers; }
private void clean(Jedis jedis) { Set<String> keys = jedis.keys(root + Constants.ANY_VALUE); if (CollectionUtils.isNotEmpty(keys)) { for (String key : keys) { Map<String, String> values = jedis.hgetAll(key); if (CollectionUtils.isNotEmptyMap(values)) { boolean delete = false; long now = System.currentTimeMillis(); for (Map.Entry<String, String> entry : values.entrySet()) { URL url = URL.valueOf(entry.getKey()); if (url.getParameter(Constants.DYNAMIC_KEY, true)) { long expire = Long.parseLong(entry.getValue()); if (expire < now) { jedis.hdel(key, entry.getKey()); delete = true; if (logger.isWarnEnabled()) { logger.warn("Delete expired key: " + key + " -> value: " + entry.getKey() + ", expire: " + new Date(expire) + ", now: " + new Date(now)); } } } } if (delete) { jedis.publish(key, Constants.UNREGISTER); } } } } }
if (providerConfigMap != null && providerConfigMap.size() > 0) { Map<String, ProtocolConfig> protocolConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, ProtocolConfig.class, false, false); if (CollectionUtils.isEmptyMap(protocolConfigMap) && providerConfigMap.size() > 1) { // backward compatibility List<ProviderConfig> providerConfigs = new ArrayList<ProviderConfig>(); if ((CollectionUtils.isEmpty(getRegistries())) && (getProvider() == null || CollectionUtils.isEmpty(getProvider().getRegistries())) && (getApplication() == null || CollectionUtils.isEmpty(getApplication().getRegistries()))) { Map<String, RegistryConfig> registryConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, RegistryConfig.class, false, false); if (CollectionUtils.isNotEmptyMap(registryConfigMap)) { List<RegistryConfig> registryConfigs = new ArrayList<>(); if (StringUtils.isNotEmpty(registryIds)) { if (CollectionUtils.isEmpty(getProtocols()) && (getProvider() == null || CollectionUtils.isEmpty(getProvider().getProtocols()))) { Map<String, ProtocolConfig> protocolConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, ProtocolConfig.class, false, false); if (protocolConfigMap != null && protocolConfigMap.size() > 0) {
private static String toParameterString(ConfigItem item) { StringBuilder sb = new StringBuilder(); sb.append("category="); sb.append(Constants.DYNAMIC_CONFIGURATORS_CATEGORY); if (item.getSide() != null) { sb.append("&side="); sb.append(item.getSide()); } Map<String, String> parameters = item.getParameters(); if (CollectionUtils.isEmptyMap(parameters)) { throw new IllegalStateException("Invalid configurator rule, please specify at least one parameter " + "you want to change in the rule."); } parameters.forEach((k, v) -> { sb.append("&"); sb.append(k); sb.append("="); sb.append(v); }); if (CollectionUtils.isNotEmpty(item.getProviderAddresses())) { sb.append("&"); sb.append(Constants.OVERRIDE_PROVIDERS_KEY); sb.append("="); sb.append(CollectionUtils.join(item.getProviderAddresses(), ",")); } return sb.toString(); }
if (CollectionUtils.isNotEmptyMap(values)) { for (Map.Entry<String, String> entry : values.entrySet()) { URL u = URL.valueOf(entry.getKey()); if (CollectionUtils.isEmpty(result)) { return;
private static String toParameterString(ConfigItem item) { StringBuilder sb = new StringBuilder(); sb.append("category="); sb.append(Constants.DYNAMIC_CONFIGURATORS_CATEGORY); if (item.getSide() != null) { sb.append("&side="); sb.append(item.getSide()); } Map<String, String> parameters = item.getParameters(); if (parameters == null || parameters.isEmpty()) { throw new IllegalStateException("Invalid configurator rule, please specify at least one parameter " + "you want to change in the rule."); } parameters.forEach((k, v) -> { sb.append("&"); sb.append(k); sb.append("="); sb.append(v); }); if (CollectionUtils.isNotEmpty(item.getProviderAddresses())) { sb.append("&"); sb.append(Constants.OVERRIDE_PROVIDERS_KEY); sb.append("="); sb.append(CollectionUtils.join(item.getProviderAddresses(), ",")); } return sb.toString(); }
public static boolean isNotEmptyMap(Map map) { return !isEmptyMap(map); }
public URL(String protocol, String host, int port, String path, String... pairs) { super(protocol, null, null, host, port, path, CollectionUtils.toStringMap(pairs)); }
public static Map<String, List<String>> joinAll(Map<String, Map<String, String>> map, String separator) { if (map == null) { return null; } Map<String, List<String>> result = new HashMap<>(); for (Map.Entry<String, Map<String, String>> entry : map.entrySet()) { result.put(entry.getKey(), join(entry.getValue(), separator)); } return result; }
private void clean(Jedis jedis) { Set<String> keys = jedis.keys(root + Constants.ANY_VALUE); if (CollectionUtils.isNotEmpty(keys)) { for (String key : keys) { Map<String, String> values = jedis.hgetAll(key); if (CollectionUtils.isNotEmptyMap(values)) { boolean delete = false; long now = System.currentTimeMillis(); for (Map.Entry<String, String> entry : values.entrySet()) { URL url = URL.valueOf(entry.getKey()); if (url.getParameter(Constants.DYNAMIC_KEY, true)) { long expire = Long.parseLong(entry.getValue()); if (expire < now) { jedis.hdel(key, entry.getKey()); delete = true; if (logger.isWarnEnabled()) { logger.warn("Delete expired key: " + key + " -> value: " + entry.getKey() + ", expire: " + new Date(expire) + ", now: " + new Date(now)); } } } } if (delete) { jedis.publish(key, Constants.UNREGISTER); } } } } }
if (providerConfigMap != null && providerConfigMap.size() > 0) { Map<String, ProtocolConfig> protocolConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, ProtocolConfig.class, false, false); if (CollectionUtils.isEmptyMap(protocolConfigMap) && providerConfigMap.size() > 1) { // backward compatibility List<ProviderConfig> providerConfigs = new ArrayList<ProviderConfig>(); if ((CollectionUtils.isEmpty(getRegistries())) && (getProvider() == null || CollectionUtils.isEmpty(getProvider().getRegistries())) && (getApplication() == null || CollectionUtils.isEmpty(getApplication().getRegistries()))) { Map<String, RegistryConfig> registryConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, RegistryConfig.class, false, false); if (CollectionUtils.isNotEmptyMap(registryConfigMap)) { List<RegistryConfig> registryConfigs = new ArrayList<>(); if (StringUtils.isNotEmpty(registryIds)) { if (CollectionUtils.isEmpty(getProtocols()) && (getProvider() == null || CollectionUtils.isEmpty(getProvider().getProtocols()))) { Map<String, ProtocolConfig> protocolConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, ProtocolConfig.class, false, false); if (protocolConfigMap != null && protocolConfigMap.size() > 0) {
public StaticDirectory(URL url, List<Invoker<T>> invokers, RouterChain<T> routerChain) { super(url == null && CollectionUtils.isNotEmpty(invokers) ? invokers.get(0).getUrl() : url, routerChain); if (CollectionUtils.isEmpty(invokers)) { throw new IllegalArgumentException("invokers == null"); } this.invokers = invokers; }
private static String toParameterString(ConfigItem item) { StringBuilder sb = new StringBuilder(); sb.append("category="); sb.append(Constants.DYNAMIC_CONFIGURATORS_CATEGORY); if (item.getSide() != null) { sb.append("&side="); sb.append(item.getSide()); } Map<String, String> parameters = item.getParameters(); if (CollectionUtils.isEmptyMap(parameters)) { throw new IllegalStateException("Invalid configurator rule, please specify at least one parameter " + "you want to change in the rule."); } parameters.forEach((k, v) -> { sb.append("&"); sb.append(k); sb.append("="); sb.append(v); }); if (CollectionUtils.isNotEmpty(item.getProviderAddresses())) { sb.append("&"); sb.append(Constants.OVERRIDE_PROVIDERS_KEY); sb.append("="); sb.append(CollectionUtils.join(item.getProviderAddresses(), ",")); } return sb.toString(); }
if (CollectionUtils.isNotEmptyMap(values)) { for (Map.Entry<String, String> entry : values.entrySet()) { URL u = URL.valueOf(entry.getKey()); if (CollectionUtils.isEmpty(result)) { return;
private static String toParameterString(ConfigItem item) { StringBuilder sb = new StringBuilder(); sb.append("category="); sb.append(Constants.DYNAMIC_CONFIGURATORS_CATEGORY); if (item.getSide() != null) { sb.append("&side="); sb.append(item.getSide()); } Map<String, String> parameters = item.getParameters(); if (parameters == null || parameters.isEmpty()) { throw new IllegalStateException("Invalid configurator rule, please specify at least one parameter " + "you want to change in the rule."); } parameters.forEach((k, v) -> { sb.append("&"); sb.append(k); sb.append("="); sb.append(v); }); if (CollectionUtils.isNotEmpty(item.getProviderAddresses())) { sb.append("&"); sb.append(Constants.OVERRIDE_PROVIDERS_KEY); sb.append("="); sb.append(CollectionUtils.join(item.getProviderAddresses(), ",")); } return sb.toString(); }
public static boolean isNotEmptyMap(Map map) { return !isEmptyMap(map); }
private static Map<String, String> toMap(String... pairs) { return CollectionUtils.toStringMap(pairs); }