當前位置: 首頁>>代碼示例>>Java>>正文


Java Invoker類代碼示例

本文整理匯總了Java中com.alibaba.dubbo.rpc.Invoker的典型用法代碼示例。如果您正苦於以下問題:Java Invoker類的具體用法?Java Invoker怎麽用?Java Invoker使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Invoker類屬於com.alibaba.dubbo.rpc包,在下文中一共展示了Invoker類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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:dachengxi,項目名稱:EatDubbo,代碼行數:17,代碼來源:ConsumerContextFilter.java

示例2: testInvokerJsonPojoSerialization

import com.alibaba.dubbo.rpc.Invoker; //導入依賴的package包/類
@Test
public void testInvokerJsonPojoSerialization() {
    invocation = EasyMock.createMock(Invocation.class);
    EasyMock.expect(invocation.getMethodName()).andReturn("enumlength").anyTimes();
    EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Type[].class }).anyTimes();
    EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
    EasyMock.replay(invocation);
    invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
    RpcResult result = new RpcResult();
    result.setValue("High");
    EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1&serialization=json");
    EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
    EasyMock.replay(invoker);
    Result filterResult = compatibleFilter.invoke(invoker, invocation);
    assertEquals(Type.High, filterResult.getValue());
}
 
開發者ID:yunhaibin,項目名稱:dubbox-hystrix,代碼行數:20,代碼來源:CompatibleFilterFilterTest.java

示例3: test_Notified_acceptProtocol2

import com.alibaba.dubbo.rpc.Invoker; //導入依賴的package包/類
@Test
public void test_Notified_acceptProtocol2() {
	URL errorPathUrl  = URL.valueOf("notsupport:/xxx");
	errorPathUrl = errorPathUrl.addParameterAndEncoded(Constants.REFER_KEY, "interface="+service + "&protocol=dubbo,injvm");
    RegistryDirectory registryDirectory = getRegistryDirectory(errorPathUrl);
    List<URL> serviceUrls = new ArrayList<URL>();
    URL dubbo1URL = URL.valueOf("dubbo://127.0.0.1:9098?lazy=true&methods=getXXX");
    URL dubbo2URL = URL.valueOf("injvm://127.0.0.1:9099?lazy=true&methods=getXXX");
    serviceUrls.add(dubbo1URL);
    serviceUrls.add(dubbo2URL);
    registryDirectory.notify(serviceUrls);

    invocation = new RpcInvocation();

    List<Invoker<DemoService>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers.size());
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:18,代碼來源:RegistryDirectoryTest.java

示例4: findMethod

import com.alibaba.dubbo.rpc.Invoker; //導入依賴的package包/類
private static Method findMethod(Exporter<?> exporter, String method, List<Object> args) {
    Invoker<?> invoker = exporter.getInvoker();
    Method[] methods = invoker.getInterface().getMethods();
    Method invokeMethod = null;
    for (Method m : methods) {
        if (m.getName().equals(method) && m.getParameterTypes().length == args.size()) {
            if (invokeMethod != null) { // 重載
                if (isMatch(invokeMethod.getParameterTypes(), args)) {
                    invokeMethod = m;
                    break;
                }
            } else {
                invokeMethod = m;
            }
            invoker = exporter.getInvoker();
        }
    }
    return invokeMethod;
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:20,代碼來源:InvokeTelnetHandler.java

示例5: testNotifyoverrideUrls_withInvoker

import com.alibaba.dubbo.rpc.Invoker; //導入依賴的package包/類
/**
 * 測試override規則是否優先
 * 場景:與invoker 一起推override規則
 */
@Test
public void testNotifyoverrideUrls_withInvoker(){
    RegistryDirectory registryDirectory = getRegistryDirectory();
    
    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.addParameter("timeout", "1000"));
    durls.add(SERVICEURL2.addParameter("timeout", "1000").addParameter("connections", "10"));
    durls.add(URL.valueOf("override://0.0.0.0?timeout=1&connections=5"));

    registryDirectory.notify(durls);
    Assert.assertEquals(true, registryDirectory.isAvailable());
    
    //開始驗證參數值

    invocation = new RpcInvocation();

    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers.size());
    
    Assert.assertEquals("override rute must be first priority", "1", invokers.get(0).getUrl().getParameter("timeout"));
    Assert.assertEquals("override rute must be first priority", "5", invokers.get(0).getUrl().getParameter("connections"));
}
 
開發者ID:yunhaibin,項目名稱:dubbox-hystrix,代碼行數:27,代碼來源:RegistryDirectoryTest.java

示例6: export

import com.alibaba.dubbo.rpc.Invoker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public <T> Exporter<T> export(final Invoker<T> invoker) throws RpcException {
       final String uri = serviceKey(invoker.getUrl());
       Exporter<T> exporter = (Exporter<T>) exporterMap.get(uri);
       if (exporter != null) {
       	return exporter;
       }
       final Runnable runnable = doExport(proxyFactory.getProxy(invoker), invoker.getInterface(), invoker.getUrl());
       exporter = new AbstractExporter<T>(invoker) {
           public void unexport() {
               super.unexport();
               exporterMap.remove(uri);
               if (runnable != null) {
                   try {
                       runnable.run();
                   } catch (Throwable t) {
                       logger.warn(t.getMessage(), t);
                   }
               }
           }
       };
       exporterMap.put(uri, exporter);
       return exporter;
   }
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:25,代碼來源:AbstractProxyProtocol.java

示例7: testNofityOverrideUrls_Provider

import com.alibaba.dubbo.rpc.Invoker; //導入依賴的package包/類
/**
 * 測試針對某個provider的Override規則
 */
@Test
public void testNofityOverrideUrls_Provider() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();

    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1"));//一個一樣,一個不一樣
    durls.add(SERVICEURL2.setHost("10.20.30.141").addParameter("timeout", "2"));
    registryDirectory.notify(durls);

    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?timeout=3"));
    durls.add(URL.valueOf("override://10.20.30.141:9092?timeout=4"));
    registryDirectory.notify(durls);

    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Invoker<?> aInvoker = invokers.get(0);
    Invoker<?> bInvoker = invokers.get(1);
    Assert.assertEquals("3", aInvoker.getUrl().getParameter("timeout"));
    Assert.assertEquals("4", bInvoker.getUrl().getParameter("timeout"));
}
 
開發者ID:l1325169021,項目名稱:github-test,代碼行數:25,代碼來源:RegistryDirectoryTest.java

示例8: testSetContext

import com.alibaba.dubbo.rpc.Invoker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void testSetContext() {
    invocation = EasyMock.createMock(Invocation.class);
    EasyMock.expect(invocation.getMethodName()).andReturn("$enumlength").anyTimes();
    EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes();
    EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
    EasyMock.expect(invocation.getAttachments()).andReturn(null).anyTimes();
    EasyMock.replay(invocation);
    invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
    RpcResult result = new RpcResult();
    result.setValue("High");
    EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
    EasyMock.replay(invoker);
    contextFilter.invoke(invoker, invocation);
    assertNull(RpcContext.getContext().getInvoker());
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:22,代碼來源:ContextFilterTest.java

示例9: testHttpClient

import com.alibaba.dubbo.rpc.Invoker; //導入依賴的package包/類
@Test
public void testHttpClient() {
    HessianServiceImpl server = new HessianServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.class.getName() + "?version=1.0.0&client=httpclient");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<HessianService> invoker = protocol.refer(HessianService.class, url);
    HessianService client = proxyFactory.getProxy(invoker);
    String result = client.sayHello("haha");
    Assert.assertTrue(server.isCalled());
    Assert.assertEquals("Hello, haha", result);
    invoker.destroy();
    exporter.unexport();
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:17,代碼來源:HessianProtocolTest.java

示例10: testResulthasException

import com.alibaba.dubbo.rpc.Invoker; //導入依賴的package包/類
@Test
public void testResulthasException() {
    invocation = EasyMock.createMock(Invocation.class);
    EasyMock.expect(invocation.getMethodName()).andReturn("enumlength").anyTimes();
    EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes();
    EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
    EasyMock.replay(invocation);
    invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
    RpcResult result = new RpcResult();
    result.setException(new RuntimeException());
    result.setValue("High");
    EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
    EasyMock.replay(invoker);
    Result filterResult = compatibleFilter.invoke(invoker, invocation);
    assertEquals(filterResult, result);
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:21,代碼來源:CompatibleFilterFilterTest.java

示例11: testInvokeDefaultSService

import com.alibaba.dubbo.rpc.Invoker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void testInvokeDefaultSService() throws RemotingException {
    mockInvoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
    EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20883/demo")).anyTimes();
    EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService").anyTimes();
    EasyMock.expect(mockChannel.getLocalAddress()).andReturn(NetUtils.toAddress("127.0.0.1:5555")).anyTimes();
    EasyMock.expect(mockChannel.getRemoteAddress()).andReturn(NetUtils.toAddress("127.0.0.1:20883")).anyTimes();
    EasyMock.replay(mockChannel, mockInvoker);
    DubboProtocol.getDubboProtocol().export(mockInvoker);
    String result = invoke.telnet(mockChannel, "DemoService.echo(\"ok\")");
    assertTrue(result.contains("Use default service com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService.\r\n\"ok\"\r\n"));
    EasyMock.reset(mockChannel, mockInvoker);
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:18,代碼來源:InvokerTelnetHandlerTest.java

示例12: testNofityOverrideUrls_disabled_allProvider

import com.alibaba.dubbo.rpc.Invoker; //導入依賴的package包/類
/**
 * 測試override通過enable=false,禁用所有服務提供者
 * 預期:不能通過override禁用所有服務提供者.
 */
@Test
public void testNofityOverrideUrls_disabled_allProvider(){
	RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();
    
    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.setHost("10.20.30.140"));
    durls.add(SERVICEURL.setHost("10.20.30.141"));
    registryDirectory.notify(durls);
    
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?"+Constants.ENABLED_KEY+"=false"));
    registryDirectory.notify(durls);
    
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    //不能通過override禁用所有服務提供者.
    Assert.assertEquals(2,invokers.size());
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:23,代碼來源:RegistryDirectoryTest.java

示例13: testMockInvokerFromOverride_Invoke_check_ListPojo

import com.alibaba.dubbo.rpc.Invoker; //導入依賴的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());
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:17,代碼來源:MockClusterInvokerTest.java

示例14: ListenerInvokerWrapper

import com.alibaba.dubbo.rpc.Invoker; //導入依賴的package包/類
public ListenerInvokerWrapper(Invoker<T> invoker, List<InvokerListener> listeners){
    if (invoker == null) {
        throw new IllegalArgumentException("invoker == null");
    }
    this.invoker = invoker;
    this.listeners = listeners;
    if (listeners != null && listeners.size() > 0) {
        for (InvokerListener listener : listeners) {
            if (listener != null) {
                try {
                    listener.referred(invoker);
                } catch (Throwable t) {
                    logger.error(t.getMessage(), t);
                }
            }
        }
    }
}
 
開發者ID:yunhaibin,項目名稱:dubbox-hystrix,代碼行數:19,代碼來源:ListenerInvokerWrapper.java

示例15: testListDetail

import com.alibaba.dubbo.rpc.Invoker; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void testListDetail() throws RemotingException {
    int port = NetUtils.getAvailablePort();
    mockInvoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
    EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:"+port+"/demo")).anyTimes();
    EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
    EasyMock.replay(mockChannel, mockInvoker);
    DubboProtocol.getDubboProtocol().export(mockInvoker);
    String result = list.telnet(mockChannel, "-l");
    assertEquals("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService -> dubbo://127.0.0.1:"+port+"/demo", result);
    EasyMock.reset(mockChannel);
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:17,代碼來源:ListTelnetHandlerTest.java


注:本文中的com.alibaba.dubbo.rpc.Invoker類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。