当前位置: 首页>>代码示例>>Java>>正文


Java Invoker.invoke方法代码示例

本文整理汇总了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;
  }
}
 
开发者ID:eXcellme,项目名称:eds,代码行数:26,代码来源:DubboServiceFilter.java

示例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);
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:21,代码来源:CacheFilter.java

示例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());
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:19,代码来源:MockClusterInvokerTest.java

示例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();
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:17,代码来源:ConsumerContextFilter.java

示例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);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:17,代码来源:ValidationFilter.java

示例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
    }
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:11,代码来源:FailsafeClusterInvoker.java

示例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());
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:14,代码来源:MockClusterInvokerTest.java

示例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;
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:16,代码来源:TimeoutFilter.java

示例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);
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:13,代码来源:FailfastClusterInvoker.java

示例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());
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:14,代码来源:MockClusterInvokerTest.java

示例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
    }
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:13,代码来源:FailbackClusterInvoker.java

示例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());
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:16,代码来源:MockClusterInvokerTest.java

示例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());
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:14,代码来源:MockClusterInvokerTest.java

示例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) {
	}
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:15,代码来源:MockClusterInvokerTest.java

示例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());
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:15,代码来源:MockClusterInvokerTest.java


注:本文中的com.alibaba.dubbo.rpc.Invoker.invoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。