本文整理汇总了Java中com.alibaba.dubbo.rpc.Invoker.invoke方法的典型用法代码示例。如果您正苦于以下问题:Java Invoker.invoke方法的具体用法?Java Invoker.invoke怎么用?Java Invoker.invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.dubbo.rpc.Invoker
的用法示例。
在下文中一共展示了Invoker.invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的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: invoke
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) {
Cache cache = cacheFactory.getCache(invoker.getUrl().addParameter(Constants.METHOD_KEY, invocation.getMethodName()));
if (cache != null) {
String key = StringUtils.toArgumentString(invocation.getArguments());
if (cache != null && key != null) {
Object value = cache.get(key);
if (value != null) {
return new RpcResult(value);
}
Result result = invoker.invoke(invocation);
if (! result.hasException()) {
cache.put(key, result.getValue());
}
return result;
}
}
}
return invoker.invoke(invocation);
}
示例3: testMockInvokerInvoke_forcemock_defaultreturn
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
@Test
public void testMockInvokerInvoke_forcemock_defaultreturn(){
URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName());
url = url.addParameter(Constants.MOCK_KEY, "force" );
Invoker<IHelloService> cluster = getClusterInvoker(url);
URL mockUrl = URL.valueOf("mock://localhost/"+IHelloService.class.getName()
+"?getSomething.mock=return aa&getSomething3xx.mock=return xx&sayHello.mock=return ")
.addParameters(url.getParameters());
Protocol protocol = new MockProtocol();
Invoker<IHelloService> mInvoker1 = protocol.refer(IHelloService.class, mockUrl);
invokers.add(mInvoker1);
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("sayHello");
Result ret = cluster.invoke(invocation);
Assert.assertEquals(null, ret.getValue());
}
示例4: invoke
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
RpcContext.getContext()
.setInvoker(invoker)
.setInvocation(invocation)
.setLocalAddress(NetUtils.getLocalHost(), 0)
.setRemoteAddress(invoker.getUrl().getHost(),
invoker.getUrl().getPort());
if (invocation instanceof RpcInvocation) {
((RpcInvocation)invocation).setInvoker(invoker);
}
try {
return invoker.invoke(invocation);
} finally {
RpcContext.getContext().clearAttachments();
}
}
示例5: invoke
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
if (validation != null && ! invocation.getMethodName().startsWith("$")
&& ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.VALIDATION_KEY))) {
try {
Validator validator = validation.getValidator(invoker.getUrl());
if (validator != null) {
validator.validate(invocation.getMethodName(), invocation.getParameterTypes(), invocation.getArguments());
}
} catch (RpcException e) {
throw e;
} catch (Throwable t) {
throw new RpcException(t.getMessage(), t);
}
}
return invoker.invoke(invocation);
}
示例6: doInvoke
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
try {
checkInvokers(invokers, invocation);
Invoker<T> invoker = select(loadbalance, invocation, invokers, null);
return invoker.invoke(invocation);
} catch (Throwable e) {
logger.error("Failsafe ignore exception: " + e.getMessage(), e);
return new RpcResult(); // ignore
}
}
示例7: testMockInvokerFromOverride_Invoke_check_ListString_empty
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testMockInvokerFromOverride_Invoke_check_ListString_empty(){
URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName())
.addParameter("getListString.mock","force:return empty")
.addParameter("invoke_return_error", "true" );
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getListString");
Result ret = cluster.invoke(invocation);
Assert.assertEquals(0, ((List<String>)ret.getValue()).size());
}
示例8: invoke
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
long start = System.currentTimeMillis();
Result result = invoker.invoke(invocation);
long elapsed = System.currentTimeMillis() - start;
if (invoker.getUrl() != null
&& elapsed > invoker.getUrl().getMethodParameter(invocation.getMethodName(),
"timeout", Integer.MAX_VALUE)) {
if (logger.isWarnEnabled()) {
logger.warn("invoke time out. method: " + invocation.getMethodName()
+ "arguments: " + Arrays.toString(invocation.getArguments()) + " , url is "
+ invoker.getUrl() + ", invoke elapsed " + elapsed + " ms.");
}
}
return result;
}
示例9: doInvoke
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
checkInvokers(invokers, invocation);
Invoker<T> invoker = select(loadbalance, invocation, invokers, null);
try {
return invoker.invoke(invocation);
} catch (Throwable e) {
if (e instanceof RpcException && ((RpcException)e).isBiz()) { // biz exception.
throw (RpcException) e;
}
throw new RpcException(e instanceof RpcException ? ((RpcException)e).getCode() : 0, "Failfast invoke providers " + invoker.getUrl() + " " + loadbalance.getClass().getSimpleName() + " select from all providers " + invokers + " for service " + getInterface().getName() + " method " + invocation.getMethodName() + " on consumer " + NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion() + ", but no luck to perform the invocation. Last error is: " + e.getMessage(), e.getCause() != null ? e.getCause() : e);
}
}
示例10: testMockInvokerFromOverride_Invoke_check_ListPojo_empty
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testMockInvokerFromOverride_Invoke_check_ListPojo_empty() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName())
.addParameter("getUsers.mock", "force:return empty")
.addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getUsers");
Result ret = cluster.invoke(invocation);
Assert.assertEquals(0, ((List<User>) ret.getValue()).size());
}
示例11: doInvoke
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
protected Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
try {
checkInvokers(invokers, invocation);
Invoker<T> invoker = select(loadbalance, invocation, invokers, null);
return invoker.invoke(invocation);
} catch (Throwable e) {
logger.error("Failback to invoke method " + invocation.getMethodName() + ", wait for retry in background. Ignored exception: "
+ e.getMessage() + ", ", e);
addFailed(invocation, this);
return new RpcResult(); // ignore
}
}
示例12: testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock2
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
/**
* 测试mock策略是否正常-fail-mock
*/
@Test
public void testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock2(){
URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName())
.addParameter("mock","fail")
.addParameter("invoke_return_error", "true" );
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getSomething");
Result ret = cluster.invoke(invocation);
Assert.assertEquals("somethingmock", ret.getValue());
}
示例13: testMockInvokerFromOverride_Invoke_check_String
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
@Test
public void testMockInvokerFromOverride_Invoke_check_String(){
URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName())
.addParameter("getSomething.mock","force:return 1688")
.addParameter("invoke_return_error", "true" );
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getSomething");
Result ret = cluster.invoke(invocation);
Assert.assertTrue("result type must be String but was : " + ret.getValue().getClass(), ret.getValue() instanceof String);
Assert.assertEquals("1688", (String)ret.getValue());
}
示例14: testMockInvokerFromOverride_Invoke_check_ListPojo_error
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
@Test
public void testMockInvokerFromOverride_Invoke_check_ListPojo_error(){
URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName())
.addParameter("getUsers.mock","force:return [{id:x, name:\"hi1\"}]")
.addParameter("invoke_return_error", "true" );
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getUsers");
try{
cluster.invoke(invocation);
}catch (RpcException e) {
}
}
示例15: testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock3
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
/**
* 测试mock策略是否正常-fail-mock
*/
@Test
public void testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock3(){
URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName())
.addParameter("mock","force");
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getSomething");
Result ret = cluster.invoke(invocation);
Assert.assertEquals("somethingmock", ret.getValue());
}