Java Code Examples for com.alibaba.dubbo.common.utils.StringUtils

The following examples show how to use com.alibaba.dubbo.common.utils.StringUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: dubbox   Source File: ParseUtils.java    License: Apache License 2.0 6 votes vote down vote up
/** 
 * 是否匹配Glob模式。Glob模式是要插值的表达式。Glob模式有多个,只要匹配一个模式,就认为匹配成功。
 * 
 * @param patternsNeedInterpolate 多个要进行插值的Glob模式
 * @param interpolateParams 用于插值的变量集
 * @param value 进行Glob模式的值
 */
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;
            }
            // FIXME ERROR!! 原来的实现,这里只和第一个不为空的pattern比较,返回对应的结果! 和梁飞确认
            String pattern = interpolate(patternNeedItp, interpolateParams);
            if(isMatchGlobPattern(pattern, value)) {
            	return true;
            }
        }
    }
    return false;
}
 
Example 2
Source Project: j360-dubbo-app-all   Source File: HttpBraveServletFilter.java    License: Apache License 2.0 6 votes vote down vote up
/** Alternative to {@link #getStatus}, but for Servlet 2.5+ */
@Override public Collection<KeyValueAnnotation> responseAnnotations() {
    String status = getHeader("status");
    String message = getHeader("message");

    if(StringUtils.isNotEmpty(status)) {
        if (Integer.parseInt(status) != 0) {
            KeyValueAnnotation keyValueAnnotation1 = KeyValueAnnotation.create(DubboKeys.HTTP_STATUS, status);
            KeyValueAnnotation keyValueAnnotation2 = KeyValueAnnotation.create(DubboKeys.HTTP_MESSAGE, message);
            return Lists.newArrayList(keyValueAnnotation1 ,keyValueAnnotation2);
        }
    }
    return Collections.singleton(
            KeyValueAnnotation.create(zipkin.TraceKeys.HTTP_STATUS_CODE, String.valueOf(httpStatus))
    );
}
 
Example 3
Source Project: dubbox   Source File: ServiceFactory.java    License: Apache License 2.0 6 votes vote down vote up
protected T createClient(Class<T> cls, String targetIP, int targetPort, int connectTimeout,int clientNums, String protocol, String serialization){
    ReferenceConfig<T> referenceConfig = new ReferenceConfig<T>();
    referenceConfig.setInterface(cls);
    StringBuilder url = new StringBuilder();
    url.append(protocol);
    url.append("://");
    url.append(targetIP);
    url.append(":");
    url.append(targetPort);
    url.append("/");
    url.append(cls.getName());
    url.append("?optimizer=com.alibaba.dubbo.rpc.benchmark.SerializationOptimizerImpl");
    if (!StringUtils.isEmpty(serialization)) {
        url.append("&serialization=");
        url.append(serialization);
    }
    referenceConfig.setUrl(url.toString());
    // hardcode
    referenceConfig.setConnections(clientNums);
    ApplicationConfig application = new ApplicationConfig();
    application.setName("dubbo_consumer");
    referenceConfig.setApplication(application);
    referenceConfig.setTimeout(connectTimeout);
    return referenceConfig.get();
}
 
Example 4
Source Project: dubbo3   Source File: Builder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Serializable parseFrom(GenericObjectInput in) throws IOException {
    byte b = in.read0();
    if (b == OBJECT_NULL)
        return null;
    if (b != OBJECT_STREAM)
        throw new IOException("Input format error, expect OBJECT_NULL|OBJECT_STREAM, get " + b + ".");

    UnsafeByteArrayInputStream bis = new UnsafeByteArrayInputStream(in.read0(in.readUInt()));
    CompactedObjectInputStream ois = new CompactedObjectInputStream(bis);
    try {
        return (Serializable) ois.readObject();
    } catch (ClassNotFoundException e) {
        throw new IOException(StringUtils.toString(e));
    }
}
 
Example 5
Source Project: dubbox-hystrix   Source File: CacheFilter.java    License: Apache License 2.0 6 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) {
        Cache cache = cacheFactory.getCache(invoker.getUrl().addParameter(Constants.METHOD_KEY, invocation.getMethodName()));
        if (cache != null) {
            String key = StringUtils.toArgumentString(invocation.getArguments());
            if (cache != null && key != null) {
                Object value = cache.get(key);
                if (value != null) {
                    return new RpcResult(value);
                }
                Result result = invoker.invoke(invocation);
                if (! result.hasException()) {
                    cache.put(key, result.getValue());
                }
                return result;
            }
        }
    }
    return invoker.invoke(invocation);
}
 
Example 6
Source Project: dubbo-2.6.5   Source File: CacheFilter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) {
        Cache cache = cacheFactory.getCache(invoker.getUrl(), invocation);
        if (cache != null) {
            String key = StringUtils.toArgumentString(invocation.getArguments());
            Object value = cache.get(key);
            if (value != null) {
                return new RpcResult(value);
            }
            Result result = invoker.invoke(invocation);
            if (!result.hasException() && result.getValue() != null) {
                cache.put(key, result.getValue());
            }
            return result;
        }
    }
    return invoker.invoke(invocation);
}
 
Example 7
Source Project: dubbo-2.6.5   Source File: RpcContextFilter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
    HttpServletRequest request = ResteasyProviderFactory.getContextData(HttpServletRequest.class);
    RpcContext.getContext().setRequest(request);

    // this only works for servlet containers
    if (request != null && RpcContext.getContext().getRemoteAddress() == null) {
        RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
    }

    RpcContext.getContext().setResponse(ResteasyProviderFactory.getContextData(HttpServletResponse.class));

    String headers = requestContext.getHeaderString(DUBBO_ATTACHMENT_HEADER);
    if (headers != null) {
        for (String header : headers.split(",")) {
            int index = header.indexOf("=");
            if (index > 0) {
                String key = header.substring(0, index);
                String value = header.substring(index + 1);
                if (!StringUtils.isEmpty(key)) {
                    RpcContext.getContext().setAttachment(key.trim(), value.trim());
                }
            }
        }
    }
}
 
Example 8
Source Project: dubbox   Source File: DubboRegistryFactory.java    License: Apache License 2.0 6 votes vote down vote up
private static URL getRegistryURL(URL url) {
    return url.setPath(RegistryService.class.getName())
            .removeParameter(Constants.EXPORT_KEY).removeParameter(Constants.REFER_KEY)
            .addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName())
            .addParameter(Constants.CLUSTER_STICKY_KEY, "true")
            .addParameter(Constants.LAZY_CONNECT_KEY, "true")
            .addParameter(Constants.RECONNECT_KEY, "false")
            .addParameterIfAbsent(Constants.TIMEOUT_KEY, "10000")
            .addParameterIfAbsent(Constants.CALLBACK_INSTANCES_LIMIT_KEY, "10000")
            .addParameterIfAbsent(Constants.CONNECT_TIMEOUT_KEY, "10000")
            .addParameter(Constants.METHODS_KEY, StringUtils.join(new HashSet<String>(Arrays.asList(Wrapper.getWrapper(RegistryService.class).getDeclaredMethodNames())), ","))
            //.addParameter(Constants.STUB_KEY, RegistryServiceStub.class.getName())
            //.addParameter(Constants.STUB_EVENT_KEY, Boolean.TRUE.toString()) //for event dispatch
            //.addParameter(Constants.ON_DISCONNECT_KEY, "disconnect")
            .addParameter("subscribe.1.callback", "true")
            .addParameter("unsubscribe.1.callback", "false");
}
 
Example 9
Source Project: dubbo3   Source File: Consumer.java    License: Apache License 2.0 6 votes vote down vote up
public URL toUrl() {
    String group = null;
    String version = null;
    String path = service;
    int i = path.indexOf("/");
    if (i > 0) {
        group = path.substring(0, i);
        path = path.substring(i + 1);
    }
    i = path.lastIndexOf(":");
    if (i > 0) {
        version = path.substring(i + 1);
        path = path.substring(0, i);
    }
    Map<String, String> param = StringUtils.parseQueryString(parameters);
    param.put(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY);
    if (group != null) {
        param.put(Constants.GROUP_KEY, group);
    }
    if (version != null) {
        param.put(Constants.VERSION_KEY, version);
    }
    return URL.valueOf(Constants.CONSUMER_PROTOCOL + "://" + address + "/" + path 
            + "?" + StringUtils.toQueryString(param));
}
 
Example 10
private void transferProdIdCountJson(OrderInsertReq orderInsertReq) {
    if (orderInsertReq != null && StringUtils.isNotEmpty(orderInsertReq.getProdIdCountJson())) {
        try {
            Map<String, Long> prodIdCountMapPre = JSON.parse(orderInsertReq.getProdIdCountJson(), Map.class);
            Map<String, Integer> prodIdCountMap = Maps.newHashMap();
            if (prodIdCountMapPre.size() > 0) {
                for (String key : prodIdCountMapPre.keySet()) {
                    prodIdCountMap.put(key, (Integer) prodIdCountMapPre.get(key).intValue());
                }
            }
            orderInsertReq.setProdIdCountMap(prodIdCountMap);
        } catch (ParseException e) {
            throw new CommonBizException(ExpCodeEnum.JSONERROR);
        }
    }

}
 
Example 11
Source Project: dubbo-2.6.5   Source File: ServiceConfig.java    License: Apache License 2.0 6 votes vote down vote up
private void checkProtocol() {
//        如果没有协议配置就从provider中获取协议配置
        if ((protocols == null || protocols.isEmpty())
                && provider != null) {
//            从provider中获取协议配置
            setProtocols(provider.getProtocols());
        }
        // backward compatibility 如果provider协议配置也没有就创建默认协议配置
        if (protocols == null || protocols.isEmpty()) {
            setProtocol(new ProtocolConfig());
        }
//        <dubbo:protocol name="dubbo" port="-1" id="dubbo" />
        for (ProtocolConfig protocolConfig : protocols) {
            if (StringUtils.isEmpty(protocolConfig.getName())) {
//                如果协议名称为空,默认dubbo协议
                protocolConfig.setName(Constants.DUBBO_VERSION_KEY);
            }
//            从系统属性中解析协议配置=》
            appendProperties(protocolConfig);
        }
    }
 
Example 12
Source Project: open-capacity-platform   Source File: RouteUtils.java    License: Apache License 2.0 6 votes vote down vote up
static Map<String, String> appendMethodsToUrls(Map<String, String> serviceUrls,
                                               Map<String, Set<String>> url2Methods) {
    // Add method parameters to URL
    Map<String, String> results = new HashMap<String, String>();
    for (Map.Entry<String, Set<String>> entry : url2Methods.entrySet()) {
        String url = entry.getKey();
        String query = serviceUrls.get(url);

        Set<String> methodNames = entry.getValue();
        if (methodNames != null && methodNames.size() > 0) {
            String ms = StringUtils.join(methodNames.toArray(new String[0]), ParseUtils.METHOD_SPLIT);
            query = ParseUtils.replaceParameter(query, "methods", ms);
        }
        results.put(url, query);
    }
    return results;
}
 
Example 13
Source Project: dubbox   Source File: Addresses.java    License: Apache License 2.0 6 votes vote down vote up
public void search(Map<String, Object> context) {
    index(context);
    
    Set<String> newList = new HashSet<String>();
    @SuppressWarnings("unchecked")
    Set<String> list = (Set<String>)context.get("addresses");
    String keyword = (String) context.get("keyword");
    if(StringUtils.isNotEmpty(keyword)){
        keyword = keyword.toLowerCase();
        for(String o : list){
            if(o.toLowerCase().indexOf(keyword)!=-1){
                newList.add(o);
            }
        }
    }
    context.put("addresses", newList);
}
 
Example 14
@RequestMapping("")
public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model, "index", "overrides");
    BindingAwareModelMap newModel = (BindingAwareModelMap)model;
    String service = (String)newModel.get("service");
    String application = (String)newModel.get("app");
    String address = (String)newModel.get("address");
    List<Override> overrides;
    if (StringUtils.isNotEmpty(service)) {
        overrides = overrideService.findByService(service);
    } else if (StringUtils.isNotEmpty(application)) {
        overrides = overrideService.findByApplication(application);
    } else if (StringUtils.isNotEmpty(address)) {
        overrides = overrideService.findByAddress(address);
    } else {
        overrides = overrideService.findAll();
    }
    model.addAttribute("overrides", overrides);
    return "governance/screen/overrides/index";
}
 
Example 15
Source Project: dubbox   Source File: Consumer.java    License: Apache License 2.0 6 votes vote down vote up
public URL toUrl() {
    String group = null;
    String version = null;
    String path = service;
    int i = path.indexOf("/");
    if (i > 0) {
        group = path.substring(0, i);
        path = path.substring(i + 1);
    }
    i = path.lastIndexOf(":");
    if (i > 0) {
        version = path.substring(i + 1);
        path = path.substring(0, i);
    }
    Map<String, String> param = StringUtils.parseQueryString(parameters);
    param.put(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY);
    if (group != null) {
        param.put(Constants.GROUP_KEY, group);
    }
    if (version != null) {
        param.put(Constants.VERSION_KEY, version);
    }
    return URL.valueOf(Constants.CONSUMER_PROTOCOL + "://" + address + "/" + path 
            + "?" + StringUtils.toQueryString(param));
}
 
Example 16
Source Project: open-capacity-platform   Source File: ParseUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static String appendParamsToUri(String uri, Map<String, String> params) {
    StringBuilder buf = new StringBuilder(uri);
    boolean first = (uri.indexOf('?') < 0);
    for (Map.Entry<String, String> entry : params.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        if (StringUtils.isEmpty(key) || StringUtils.isEmpty(value))
            continue;
        if (first) {
            buf.append("?");
            first = false;
        } else {
            buf.append("&");
        }
        buf.append(key);
        buf.append("=");
        buf.append(value);
    }
    return buf.toString();
}
 
Example 17
Source Project: dubbo3   Source File: OverrideUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static List<Weight> overridesToWeights(List<Override> overrides){
    List<Weight> weights = new ArrayList<Weight>();
    if(overrides == null){
        return weights;
    }
    for(Override o : overrides){
            if(StringUtils.isEmpty(o.getParams())){
                continue;
            }else{
                Map<String,String> params = StringUtils.parseQueryString(o.getParams());
                for(Map.Entry<String, String> entry : params.entrySet()){
                    if(entry.getKey().equals("weight")){
                        Weight weight = new Weight();
                        weight.setAddress(o.getAddress());
                        weight.setId(o.getId());
                        weight.setService(o.getService());
                        weight.setWeight(Integer.valueOf(entry.getValue()));
                        weights.add(weight);
                    }
                }
            }
        }
    return weights;
}
 
Example 18
Source Project: dubbox   Source File: Applications.java    License: Apache License 2.0 6 votes vote down vote up
public void search(Map<String, Object> context) {
    index(context);
    
    Set<String> newList = new HashSet<String>();
    @SuppressWarnings("unchecked")
    Set<String> apps = (Set<String>)context.get("applications");
    String keyword = (String) context.get("keyword");
    if(StringUtils.isNotEmpty(keyword)){
        keyword = keyword.toLowerCase();
        for(String o : apps){
            if(o.toLowerCase().indexOf(keyword)!=-1){
                newList.add(o);
            }
        }
    }
    context.put("applications", newList);
}
 
Example 19
Source Project: dubbo3   Source File: ParseUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static String appendParamsToUri(String uri, Map<String, String> params) {
	StringBuilder buf = new StringBuilder(uri);
	boolean first = (uri.indexOf('?') < 0);
    for(Map.Entry<String, String> entry : params.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        if(StringUtils.isEmpty(key) || StringUtils.isEmpty(value))
        	continue;
        if (first) {
        	buf.append("?");
            first = false;
        } else {
        	buf.append("&");
        }
        buf.append(key);
    	buf.append("=");
    	buf.append(value);
    }
    return buf.toString();
}
 
Example 20
Source Project: dubbo3   Source File: Applications.java    License: Apache License 2.0 6 votes vote down vote up
public void search(Map<String, Object> context) {
    index(context);
    
    Set<String> newList = new HashSet<String>();
    @SuppressWarnings("unchecked")
    Set<String> apps = (Set<String>)context.get("applications");
    String keyword = (String) context.get("keyword");
    if(StringUtils.isNotEmpty(keyword)){
        keyword = keyword.toLowerCase();
        for(String o : apps){
            if(o.toLowerCase().indexOf(keyword)!=-1){
                newList.add(o);
            }
        }
    }
    context.put("applications", newList);
}
 
Example 21
Source Project: dubbox   Source File: ReferenceConfigCache.java    License: Apache License 2.0 6 votes vote down vote up
public String generateKey(ReferenceConfig<?> referenceConfig) {
    String iName = referenceConfig.getInterface();
    if(StringUtils.isBlank(iName)) {
        Class<?> clazz = referenceConfig.getInterfaceClass();
        iName = clazz.getName();
    }
    if(StringUtils.isBlank(iName)) {
        throw new IllegalArgumentException("No interface info in ReferenceConfig" + referenceConfig);
    }

    StringBuilder ret = new StringBuilder();
    if(! StringUtils.isBlank(referenceConfig.getGroup())) {
        ret.append(referenceConfig.getGroup()).append("/");
    }
    ret.append(iName);
    if(! StringUtils.isBlank(referenceConfig.getVersion())) {
        ret.append(":").append(referenceConfig.getVersion());
    }
    return ret.toString();
}
 
Example 22
Source Project: dubbox   Source File: MulticastGroup.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isMulticastAddress(String ip) {
    int i = ip.indexOf('.');
    if (i > 0) {
        String prefix = ip.substring(0, i);
        if (StringUtils.isInteger(prefix)) {
            int p = Integer.parseInt(prefix);
            return p >= 224 && p <= 239;
        }
    }
    return false;
}
 
Example 23
Source Project: dubbo3   Source File: ExtensionLoader.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 编程方式添加新扩展点。
 *
 * @param name  扩展点名
 * @param clazz 扩展点类
 * @throws IllegalStateException 要添加扩展点名已经存在。
 */
public void addExtension(String name, Class<?> clazz) {
    getExtensionClasses(); // load classes

    if (!type.isAssignableFrom(clazz)) {
        throw new IllegalStateException("Input type " +
                clazz + "not implement Extension " + type);
    }
    if (clazz.isInterface()) {
        throw new IllegalStateException("Input type " +
                clazz + "can not be interface!");
    }

    if (!clazz.isAnnotationPresent(Adaptive.class)) {
        if (StringUtils.isBlank(name)) {
            throw new IllegalStateException("Extension name is blank (Extension " + type + ")!");
        }
        if (cachedClasses.get().containsKey(name)) {
            throw new IllegalStateException("Extension name " +
                    name + " already existed(Extension " + type + ")!");
        }

        cachedNames.put(clazz, name);
        cachedClasses.get().put(name, clazz);
    } else {
        if (cachedAdaptiveClass != null) {
            throw new IllegalStateException("Adaptive Extension already existed(Extension " + type + ")!");
        }

        cachedAdaptiveClass = clazz;
    }
}
 
Example 24
Source Project: dubbox-hystrix   Source File: MulticastExchangeGroup.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isMulticastAddress(String ip) {
    int i = ip.indexOf('.');
    if (i > 0) {
        String prefix = ip.substring(0, i);
        if (StringUtils.isInteger(prefix)) {
            int p = Integer.parseInt(prefix);
            return p >= 224 && p <= 239;
        }
    }
    return false;
}
 
Example 25
/**
 * 参数校验
 * @param param 待校验参数
 * @param expCodeEnum 异常错误码
 */
protected <T> void checkParam(T param, ExpCodeEnum expCodeEnum) {
    if (param == null) {
        throw new CommonBizException(expCodeEnum);
    }

    if (param instanceof String && StringUtils.isEmpty((String) param)) {
        throw new CommonBizException(expCodeEnum);
    }

    if (param instanceof Collection && CollectionUtils.isEmpty((Collection<?>) param)) {
        throw new CommonBizException(expCodeEnum);
    }
}
 
Example 26
Source Project: dubbo-2.6.5   Source File: CuratorZookeeperClient.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void process(WatchedEvent event) throws Exception {
    if (listener != null) {
        String path = event.getPath() == null ? "" : event.getPath();
        listener.childChanged(path,
                // if path is null, curator using watcher will throw NullPointerException.
                // if client connect or disconnect to server, zookeeper will queue
                // watched event(Watcher.Event.EventType.None, .., path = null).
                StringUtils.isNotEmpty(path)
                        ? client.getChildren().usingWatcher(this).forPath(path)
                        : Collections.<String>emptyList());
    }
}
 
Example 27
Source Project: dubbo-2.6.5   Source File: MulticastExchangeGroup.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isMulticastAddress(String ip) {
    int i = ip.indexOf('.');
    if (i > 0) {
        String prefix = ip.substring(0, i);
        if (StringUtils.isInteger(prefix)) {
            int p = Integer.parseInt(prefix);
            return p >= 224 && p <= 239;
        }
    }
    return false;
}
 
Example 28
Source Project: dubbox   Source File: ParseUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static String appendParamToUri(String uri, String name, String value) {
    if (StringUtils.isEmpty(name) || StringUtils.isEmpty(value)) return uri;
    if (uri.indexOf('?') != -1) {
        uri += "&" + name + "=" + value;
    } else {
        uri += "?" + name + "=" + value;
    }
    return uri;
}
 
Example 29
Source Project: dubbo3   Source File: AbstractInterfaceConfig.java    License: Apache License 2.0 5 votes vote down vote up
protected URL loadMonitor(URL registryURL) {
    if (monitor == null) {
        String monitorAddress = ConfigUtils.getProperty("dubbo.monitor.address");
        String monitorProtocol = ConfigUtils.getProperty("dubbo.monitor.protocol");
        if (monitorAddress != null && monitorAddress.length() > 0
                || monitorProtocol != null && monitorProtocol.length() > 0) {
            monitor = new MonitorConfig();
        } else {
            return null;
        }
    }
    appendProperties(monitor);
    Map<String, String> map = new HashMap<>();
    map.put(Constants.INTERFACE_KEY, MonitorService.class.getName());
    map.put("dubbo", Version.getVersion());
    map.put(Constants.TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
    if (ConfigUtils.getPid() > 0) {
        map.put(Constants.PID_KEY, String.valueOf(ConfigUtils.getPid()));
    }
    appendParameters(map, monitor);
    String address = monitor.getAddress();
    String sysaddress = System.getProperty("dubbo.monitor.address");
    if (sysaddress != null && sysaddress.length() > 0) {
        address = sysaddress;
    }
    if (ConfigUtils.isNotEmpty(address)) {
        if (! map.containsKey(Constants.PROTOCOL_KEY)) {
            if (ExtensionLoader.getExtensionLoader(MonitorFactory.class).hasExtension("logstat")) {
                map.put(Constants.PROTOCOL_KEY, "logstat");
            } else {
                map.put(Constants.PROTOCOL_KEY, "dubbo");
            }
        }
        return UrlUtils.parseURL(address, map);
    } else if (Constants.REGISTRY_PROTOCOL.equals(monitor.getProtocol()) && registryURL != null) {
        return registryURL.setProtocol("dubbo").addParameter(Constants.PROTOCOL_KEY, "registry").addParameterAndEncoded(Constants.REFER_KEY, StringUtils.toQueryString(map));
    }
    return null;
}
 
Example 30
Source Project: dubbox-hystrix   Source File: Tool.java    License: Apache License 2.0 5 votes vote down vote up
public static int getProviderWeight(Provider provider, List<Override> oList) {
	for(Override o : oList){
		if (o.isMatch(provider)) {
 		Map<String, String> params = StringUtils.parseQueryString(o.getParams());
 		String weight = params.get(Constants.WEIGHT_KEY);
     	if(weight != null && weight.length() > 0){
     		return Integer.parseInt(weight);
     	}
		}
	}
	return provider.getWeight();
}