本文整理汇总了Java中com.alibaba.dubbo.rpc.Result.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java Result.getValue方法的具体用法?Java Result.getValue怎么用?Java Result.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.dubbo.rpc.Result
的用法示例。
在下文中一共展示了Result.getValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import com.alibaba.dubbo.rpc.Result; //导入方法依赖的package包/类
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
long start = System.currentTimeMillis();
String classDotMethod = (invocation.getInvoker().getInterface().getName().concat(".").concat(invocation
.getMethodName()));
try {
Result r = invoker.invoke(invocation);
long end = System.currentTimeMillis();
LogBean log = new LogBean();
log.ct = (end - start);
log.k = (invocation.getInvoker().getInterface().getName() + "." + invocation.getMethodName());
// provider
log.ext = (invoker.getUrl().getAddress());
log.t = System.currentTimeMillis();
log.p = Arrays.toString(invocation.getArguments());
log.r = (r != null ? r.getValue() : null);
log.tp = LogBean.TYPE_DUBBO_PERF; // DUBBO_PERF
dubboLogger.info(JSON.toJSONString(log));
return r;
} catch (Exception e) {
logger.error("DubboServiceFilter.invoke error args : invoker={},invocation={},e={} ", invoker, invocation, e);
throw e;
}
}
示例2: testMockInvokerFromOverride_Invoke_check_ListPojo
import com.alibaba.dubbo.rpc.Result; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testMockInvokerFromOverride_Invoke_check_ListPojo(){
URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName())
.addParameter("getUsers.mock","force:return [{id:1, name:\"hi1\"}, {id:2, name:\"hi2\"}]")
.addParameter("invoke_return_error", "true" );
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getUsers");
Result ret = cluster.invoke(invocation);
List<User> rl = (List<User>)ret.getValue();
System.out.println(rl);
Assert.assertEquals(2, rl.size());
Assert.assertEquals("hi1", ((User)rl.get(0)).getName());
}
示例3: encodeResponseData
import com.alibaba.dubbo.rpc.Result; //导入方法依赖的package包/类
@Override
protected void encodeResponseData(Channel channel, ObjectOutput out, Object data) throws IOException {
Result result = (Result) data;
Throwable th = result.getException();
if (th == null) {
Object ret = result.getValue();
if (ret == null) {
out.writeByte(RESPONSE_NULL_VALUE);
} else {
out.writeByte(RESPONSE_VALUE);
out.writeObject(ret);
}
} else {
out.writeByte(RESPONSE_WITH_EXCEPTION);
out.writeObject(th);
}
}
示例4: encodeResponseData
import com.alibaba.dubbo.rpc.Result; //导入方法依赖的package包/类
@Override
protected void encodeResponseData(Channel channel, ObjectOutput out, Object data) throws IOException {
Result result = (Result) data;
Throwable th = result.getException();
if (th == null) {
Object ret = result.getValue();
if (ret == null) {
out.writeByte(RESPONSE_NULL_VALUE);
} else {
out.writeByte(RESPONSE_VALUE);
out.writeObject(ret);
}
} else {
out.writeByte(RESPONSE_WITH_EXCEPTION);
out.writeObject(th);
}
//2016-12-12张科伟 provider encode attachmend
out.writeObject(result.getAttachments());
}
示例5: testMockInvokerFromOverride_Invoke_check_ListPojo
import com.alibaba.dubbo.rpc.Result; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testMockInvokerFromOverride_Invoke_check_ListPojo() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName())
.addParameter("getUsers.mock", "force:return [{id:1, name:\"hi1\"}, {id:2, name:\"hi2\"}]")
.addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getUsers");
Result ret = cluster.invoke(invocation);
List<User> rl = (List<User>) ret.getValue();
System.out.println(rl);
Assert.assertEquals(2, rl.size());
Assert.assertEquals("hi1", ((User) rl.get(0)).getName());
}
示例6: testMockInvokerFromOverride_Invoke_check_ListString
import com.alibaba.dubbo.rpc.Result; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testMockInvokerFromOverride_Invoke_check_ListString(){
URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName())
.addParameter("getListString.mock","force:return [\"hi\",\"hi2\"]")
.addParameter("invoke_return_error", "true" );
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getListString");
Result ret = cluster.invoke(invocation);
List<String> rl = (List<String>)ret.getValue();
Assert.assertEquals(2, rl.size());
Assert.assertEquals("hi", rl.get(0));
}
示例7: testMockInvokerFromOverride_Invoke_check_ListString
import com.alibaba.dubbo.rpc.Result; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testMockInvokerFromOverride_Invoke_check_ListString() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName())
.addParameter("getListString.mock", "force:return [\"hi\",\"hi2\"]")
.addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getListString");
Result ret = cluster.invoke(invocation);
List<String> rl = (List<String>) ret.getValue();
Assert.assertEquals(2, rl.size());
Assert.assertEquals("hi", rl.get(0));
}