提交 2d444775 编写于 作者: L liangfei0201

DUBBO-480 统一异步调用各参数的key为async=true和return=false

上级 10a3d8bd
......@@ -272,8 +272,12 @@ public class Constants {
public static final String CLIENT_KEY = "client";
public static final String ID_KEY = "id";
public static final String ASYNC_KEY = "async";
public static final String RETURN_KEY = "return";
public static final String TOKEN_KEY = "token";
public static final String METHOD_KEY = "method";
......@@ -503,8 +507,6 @@ public class Constants {
public static final String ON_DISCONNECT_KEY = "ondisconnect";
public static final String RETURN_KEY = "return";
public static final String ON_INVOKE_METHOD_KEY = "oninvoke.method";
public static final String ON_RETURN_METHOD_KEY = "onreturn.method";
......@@ -568,11 +570,5 @@ public class Constants {
/*
* private Constants(){ }
*/
public static class Attachments {
public static final String IS_ASYNC_KEY = "attachments.async";
public static final String IS_ONEWAY_KEY = "attachments.oneway";
public static final String INVOCATIONID_KEY = "attachments.invocation.id";
}
}
......@@ -564,7 +564,7 @@ public class RpcContext {
public <T> Future<T> asyncCall(Callable<T> callable) {
try {
try {
setAttachment(Constants.Attachments.IS_ASYNC_KEY, Boolean.TRUE.toString());
setAttachment(Constants.ASYNC_KEY, Boolean.TRUE.toString());
final T o = callable.call();
//local调用会直接返回结果.
if (o != null) {
......@@ -581,7 +581,7 @@ public class RpcContext {
} catch (Exception e) {
throw new RpcException(e);
} finally {
removeAttachment(Constants.Attachments.IS_ASYNC_KEY);
removeAttachment(Constants.ASYNC_KEY);
}
} catch (final RpcException e) {
return new Future<T>() {
......@@ -613,13 +613,13 @@ public class RpcContext {
*/
public void asyncCall(Runnable runable) {
try {
setAttachment(Constants.Attachments.IS_ONEWAY_KEY, Boolean.TRUE.toString());
setAttachment(Constants.RETURN_KEY, Boolean.FALSE.toString());
runable.run();
} catch (Throwable e) {
//FIXME 异常是否应该放在future中?
throw new RpcException("oneway call error ." + e.getMessage(), e);
} finally {
removeAttachment(Constants.Attachments.IS_ONEWAY_KEY);
removeAttachment(Constants.RETURN_KEY);
}
}
}
\ No newline at end of file
......@@ -116,7 +116,7 @@ public abstract class AbstractInvoker<T> implements Invoker<T> {
}
public String toString() {
return getInterface() + " -> " + getUrl()==null?" ":getUrl().toString();
return getInterface() + " -> " + (getUrl() == null ? "" : getUrl().toString());
}
public Result invoke(Invocation inv) throws RpcException {
......@@ -135,7 +135,7 @@ public abstract class AbstractInvoker<T> implements Invoker<T> {
invocation.addAttachmentsIfAbsent(context);
}
if (getUrl().getMethodParameter(invocation.getMethodName(), Constants.ASYNC_KEY, false)){
invocation.setAttachment(Constants.Attachments.IS_ASYNC_KEY, Boolean.TRUE.toString());
invocation.setAttachment(Constants.ASYNC_KEY, Boolean.TRUE.toString());
}
RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);
......
......@@ -82,7 +82,7 @@ public class RpcUtils {
private static final AtomicLong INVOKE_ID = new AtomicLong(0);
public static Long getInvocationId(Invocation inv) {
String id = inv.getAttachment(Constants.Attachments.INVOCATIONID_KEY);
String id = inv.getAttachment(Constants.ID_KEY);
return id == null ? null : new Long(id);
}
......@@ -93,7 +93,7 @@ public class RpcUtils {
*/
public static void attachInvocationIdIfAsync(URL url, Invocation inv){
if (isAttachInvocationId(url, inv) && getInvocationId(inv) == null && inv instanceof RpcInvocation) {
((RpcInvocation)inv).setAttachment(Constants.Attachments.INVOCATIONID_KEY, String.valueOf(INVOKE_ID.getAndIncrement()));
((RpcInvocation)inv).setAttachment(Constants.ID_KEY, String.valueOf(INVOKE_ID.getAndIncrement()));
}
}
......@@ -152,10 +152,10 @@ public class RpcUtils {
public static boolean isAsync(URL url, Invocation inv) {
boolean isAsync ;
//如果Java代码中设置优先.
if (Boolean.TRUE.toString().equals(inv.getAttachment(Constants.Attachments.IS_ASYNC_KEY))) {
if (Boolean.FALSE.toString().equals(inv.getAttachment(Constants.ASYNC_KEY))) {
isAsync = true;
} else {
isAsync = url.getMethodParameter(getMethodName(inv), Constants.ASYNC_KEY, false);
isAsync = url.getMethodParameter(getMethodName(inv), Constants.ASYNC_KEY, true);
}
return isAsync;
}
......@@ -163,10 +163,10 @@ public class RpcUtils {
public static boolean isOneway(URL url, Invocation inv) {
boolean isOneway ;
//如果Java代码中设置优先.
if (Boolean.TRUE.toString().equals(inv.getAttachment(Constants.Attachments.IS_ONEWAY_KEY))) {
if (Boolean.FALSE.toString().equals(inv.getAttachment(Constants.RETURN_KEY))) {
isOneway = true;
} else {
isOneway = url.getMethodParameter(getMethodName(inv), Constants.RETURN_KEY, false);
isOneway = ! url.getMethodParameter(getMethodName(inv), Constants.RETURN_KEY, true);
}
return isOneway;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册