dubbo-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From timestatic (GitHub) <git...@apache.org>
Subject [GitHub] [incubator-dubbo] timestatic opened issue #3848: A question about configuring priority judgment, such as isAsync, isOneway
Date Wed, 10 Apr 2019 12:32:46 GMT
在dubbo的设计原则中, 配置优先级, 方法级优先,接口级次之,全局配置再次之,
Java代码中的配置优先级大于初始化时的配置

In the design principles of dubbo, configuration priority, method first, interface second,
global configuration at last, and configuration priority in Java code is higher than that
in initialization.

举个例子:

For example:

```java
    public static boolean isOneway(URL url, Invocation inv) {
        boolean isOneway;
        if (Boolean.FALSE.toString().equals(inv.getAttachment(Constants.RETURN_KEY))) {
            isOneway = true;
        } else {
            isOneway = !url.getMethodParameter(getMethodName(inv), Constants.RETURN_KEY, true);
        }
        return isOneway;
    }
```

在判断是否`oneway`调用时, 先判断Java代码的配置, 然后再根据url中的方法级别配置判断

When judging whether oneway is called, first determine the configuration of the Java code,
and then judge according to the method level configuration in the url.



但是我在实际的使用中, 某个方法配置的默认值就是`oneway`调用, 需要在少数情况下设置为同步调用

那么在上述逻辑中, 我无法将一个已经设置为`oneway`调用的方法(RETURN_KEY,
fasle) 再设置为同步调用(RETURN_KEY, true), 因为在else分支中是从url中判断方法级别的RETURN_KEY,
而在调用之前无法修改url上的参数

But in my actual use, the default value of a method configuration is oneway call, which needs
to be set to synchronous call in a few cases.

So in the above logic, I can't set a method (RETURN_KEY, fasle) that has been set to oneway
call to synchronous call (RETURN_KEY, true), because in the else branch, the method level
RETURN_KEY is determined from the url, but in unable to modify parameters on url before calling



因此我认为这里的判断优先级应该是如下所示比较合理: 

Therefore, I think the priority of judgment here should be reasonable as follows:

```java
    public static boolean isOneway(URL url, Invocation inv) {
        boolean isOneway;
        String config;
        if ((config = inv.getAttachment(getMethodName(inv) + Constants.HIDE_KEY_PREFIX + Constants.RETURN_KEY))
!= null) {
            isOneway =  Boolean.valueOf(config);
        } else if ((config = inv.getAttachment(Constants.RETURN_KEY)) != null) {
            isOneway =  Boolean.valueOf(config);
        } else {
            isOneway = !url.getMethodParameter(getMethodName(inv), Constants.RETURN_KEY, true);
        }
        return isOneway;
    }
```



类似的在`isAsync`判断中,

Similar in the isAsync judgment,

```java
    public static boolean isAsync(URL url, Invocation inv) {
        boolean isAsync;
        String config;
        if ((config = inv.getAttachment(getMethodName(inv) + Constants.HIDE_KEY_PREFIX + Constants.ASYNC_KEY))
!= null) {
            isAsync = Boolean.valueOf(config);
        } else if ((config = inv.getAttachment(Constants.ASYNC_KEY)) != null) {
            isAsync = Boolean.valueOf(config);
        } else if ((config = url.getMethodParameter(getMethodName(inv), Constants.ASYNC_KEY))
!= null) {
            isAsync = Boolean.valueOf(config);
        } else {
            isAsync = url.getParameter(Constants.ASYNC_KEY, false);
        }
        return isAsync;
    }
```


[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3848 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org
Mime
View raw message