Skip to content

Commit 13c1571

Browse files
chickenljcarryxyh
authored andcommitted
Rename some variables to avoid possible confusion between Result and AppResponse. (#3889)
Clear that the `Result` of the call back is actually an `AppResponse`.
1 parent b26604f commit 13c1571

File tree

19 files changed

+84
-85
lines changed

19 files changed

+84
-85
lines changed

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailsafeClusterInvoker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import java.util.List;
3030

3131
/**
32-
* When invoke fails, log the error message and ignore this error by returning an empty RpcResult.
32+
* When invoke fails, log the error message and ignore this error by returning an empty Result.
3333
* Usually used to write audit logs and other operations
3434
*
3535
* <a href="http://en.wikipedia.org/wiki/Fail-safe">Fail-safe</a>

dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/MockResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.io.Serializable;
2020

2121
/**
22-
* RpcResult.
22+
* AppResponse.
2323
*/
2424

2525
public class MockResult implements Serializable {

dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public AsyncRpcResult(CompletableFuture<AppResponse> future, Invocation invocati
4747

4848
@Override
4949
public Object getValue() {
50-
return getRpcResult().getValue();
50+
return getAppResponse().getValue();
5151
}
5252

5353
@Override
@@ -57,7 +57,7 @@ public void setValue(Object value) {
5757

5858
@Override
5959
public Throwable getException() {
60-
return getRpcResult().getException();
60+
return getAppResponse().getException();
6161
}
6262

6363
@Override
@@ -67,7 +67,7 @@ public void setException(Throwable t) {
6767

6868
@Override
6969
public boolean hasException() {
70-
return getRpcResult().hasException();
70+
return getAppResponse().hasException();
7171
}
7272

7373
public CompletableFuture<AppResponse> getResponseFuture() {
@@ -78,7 +78,7 @@ public void setResponseFuture(CompletableFuture<AppResponse> responseFuture) {
7878
this.responseFuture = responseFuture;
7979
}
8080

81-
public Result getRpcResult() {
81+
public Result getAppResponse() {
8282
try {
8383
if (responseFuture.isDone()) {
8484
return responseFuture.get();
@@ -94,9 +94,9 @@ public Result getRpcResult() {
9494
public Object recreate() throws Throwable {
9595
RpcInvocation rpcInvocation = (RpcInvocation) invocation;
9696
if (InvokeMode.FUTURE == rpcInvocation.getInvokeMode()) {
97-
AppResponse rpcResult = new AppResponse();
97+
AppResponse appResponse = new AppResponse();
9898
CompletableFuture<Object> future = new CompletableFuture<>();
99-
rpcResult.setValue(future);
99+
appResponse.setValue(future);
100100
responseFuture.whenComplete((result, t) -> {
101101
if (t != null) {
102102
if (t instanceof CompletionException) {
@@ -111,7 +111,7 @@ public Object recreate() throws Throwable {
111111
}
112112
}
113113
});
114-
return rpcResult.recreate();
114+
return appResponse.recreate();
115115
} else if (responseFuture.isDone()) {
116116
return responseFuture.get().recreate();
117117
}
@@ -135,32 +135,32 @@ public <U> CompletableFuture<U> thenApply(Function<Result,? extends U> fn) {
135135

136136
@Override
137137
public Map<String, String> getAttachments() {
138-
return getRpcResult().getAttachments();
138+
return getAppResponse().getAttachments();
139139
}
140140

141141
@Override
142142
public void setAttachments(Map<String, String> map) {
143-
getRpcResult().setAttachments(map);
143+
getAppResponse().setAttachments(map);
144144
}
145145

146146
@Override
147147
public void addAttachments(Map<String, String> map) {
148-
getRpcResult().addAttachments(map);
148+
getAppResponse().addAttachments(map);
149149
}
150150

151151
@Override
152152
public String getAttachment(String key) {
153-
return getRpcResult().getAttachment(key);
153+
return getAppResponse().getAttachment(key);
154154
}
155155

156156
@Override
157157
public String getAttachment(String key, String defaultValue) {
158-
return getRpcResult().getAttachment(key, defaultValue);
158+
return getAppResponse().getAttachment(key, defaultValue);
159159
}
160160

161161
@Override
162162
public void setAttachment(String key, String value) {
163-
getRpcResult().setAttachment(key, value);
163+
getAppResponse().setAttachment(key, value);
164164
}
165165

166166
/**

dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Filter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public interface Filter {
4949

5050
interface Listener {
5151

52-
void onResponse(Result result, Invoker<?> invoker, Invocation invocation);
52+
void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation);
5353

5454
void onError(Throwable t, Invoker<?> invoker, Invocation invocation);
5555
}

dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ActiveLimitFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
8383

8484
static class ActiveLimitListener implements Listener {
8585
@Override
86-
public void onResponse(Result result, Invoker<?> invoker, Invocation invocation) {
86+
public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
8787
String methodName = invocation.getMethodName();
8888
URL url = invoker.getUrl();
8989
int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0);

dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/CompatibleFilter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
6060

6161
static class CompatibleListener implements Listener {
6262
@Override
63-
public void onResponse(Result result, Invoker<?> invoker, Invocation invocation) {
64-
if (!invocation.getMethodName().startsWith("$") && !result.hasException()) {
65-
Object value = result.getValue();
63+
public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
64+
if (!invocation.getMethodName().startsWith("$") && !appResponse.hasException()) {
65+
Object value = appResponse.getValue();
6666
if (value != null) {
6767
try {
6868
Method method = invoker.getInterface().getMethod(invocation.getMethodName(), invocation.getParameterTypes());
@@ -81,7 +81,7 @@ public void onResponse(Result result, Invoker<?> invoker, Invocation invocation)
8181
newValue = value;
8282
}
8383
if (newValue != value) {
84-
result.setValue(newValue);
84+
appResponse.setValue(newValue);
8585
}
8686
} catch (Throwable t) {
8787
logger.warn(t.getMessage(), t);

dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ConsumerContextFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
6262

6363
static class ConsumerContextListener implements Listener {
6464
@Override
65-
public void onResponse(Result result, Invoker<?> invoker, Invocation invocation) {
66-
RpcContext.getServerContext().setAttachments(result.getAttachments());
65+
public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
66+
RpcContext.getServerContext().setAttachments(appResponse.getAttachments());
6767
}
6868

6969
@Override

dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
9090

9191
static class ContextListener implements Listener {
9292
@Override
93-
public void onResponse(Result result, Invoker<?> invoker, Invocation invocation) {
93+
public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
9494
// pass attachments to result
95-
result.addAttachments(RpcContext.getServerContext().getAttachments());
95+
appResponse.addAttachments(RpcContext.getServerContext().getAttachments());
9696
}
9797

9898
@Override

dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExceptionFilter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ static class ExceptionListener implements Listener {
6060
private Logger logger = LoggerFactory.getLogger(ExceptionListener.class);
6161

6262
@Override
63-
public void onResponse(Result result, Invoker<?> invoker, Invocation invocation) {
64-
if (result.hasException() && GenericService.class != invoker.getInterface()) {
63+
public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
64+
if (appResponse.hasException() && GenericService.class != invoker.getInterface()) {
6565
try {
66-
Throwable exception = result.getException();
66+
Throwable exception = appResponse.getException();
6767

6868
// directly throw if it's checked exception
6969
if (!(exception instanceof RuntimeException) && (exception instanceof Exception)) {
@@ -102,7 +102,7 @@ public void onResponse(Result result, Invoker<?> invoker, Invocation invocation)
102102
}
103103

104104
// otherwise, wrap with RuntimeException and throw back to the client
105-
result.setException(new RuntimeException(StringUtils.toString(exception)));
105+
appResponse.setException(new RuntimeException(StringUtils.toString(exception)));
106106
return;
107107
} catch (Throwable e) {
108108
logger.warn("Fail to ExceptionFilter when called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e);

dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExecuteLimitFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
6868

6969
static class ExecuteLimitListener implements Listener {
7070
@Override
71-
public void onResponse(Result result, Invoker<?> invoker, Invocation invocation) {
71+
public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
7272
RpcStatus.endCount(invoker.getUrl(), invocation.getMethodName(), getElapsed(invocation), true);
7373
}
7474

0 commit comments

Comments
 (0)