dubbo-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chickenlj (GitHub) <git...@apache.org>
Subject [GitHub] [incubator-dubbo] chickenlj commented on issue #3738: Async optimization
Date Wed, 10 Apr 2019 11:43:20 GMT
Although many files have been modified in the PR, there are only 3 key points, all other changes
are made to adapt to these core designs.
1. Refactoring of internal Filters, making them work with the async pattern by registering
Listener to each Filter.
2. Use AsyncRpcResult as the type return back to the Filter chain.
* Add status interface to Result interface
```java
public interface Result extends Serializable {
  
    Result thenApplyWithContext(Function<Result, Result> fn);

    <U> CompletableFuture<U> thenApply(Function<Result, ? extends U> fn);

    Result get() throws InterruptedException, ExecutionException;

}
```
* AsyncRpcResult
```java
public class AsyncRpcResult implements Result {
    private CompletableFuture<AppResponse> responseFuture;
    ...
}
```
* Rename RpcResult to AppResponse with the meaning no changed
```java
public class AppResponse implements Result, Serializable {
}
```

3. Add async method with CompletableFuture signature to GenericService
```java
public interface GenericService {

    /**
     * Generic invocation
     *
     * @param method         Method name, e.g. findPerson. If there are overridden methods,
parameter info is
     *                       required, e.g. findPerson(java.lang.String)
     * @param parameterTypes Parameter types
     * @param args           Arguments
     * @return invocation return value
     * @throws GenericException potential exception thrown from the invocation
     */
    Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException;

    default CompletableFuture<Object> $invokeAsync(String method, String[] parameterTypes,
Object[] args) throws GenericException {
        Object object = $invoke(method, parameterTypes, args);
        if (object instanceof CompletableFuture) {
            return (CompletableFuture<Object>) object;
        }
        return CompletableFuture.completedFuture(object);
    }

}
```

Below are the async and sync workflows respectively:
![3 0 async workflow](https://user-images.githubusercontent.com/18097545/55873811-3526db00-5bc3-11e9-9a3a-8f8b62404553.png)

![3 0 async-to-sync workflow](https://user-images.githubusercontent.com/18097545/55873821-3ce67f80-5bc3-11e9-9b4e-55dd29b42b15.png)



[ Full content available at: https://github.com/apache/incubator-dubbo/pull/3738 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


Mime
View raw message