本文整理汇总了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();
}
}
示例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());
}
示例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());
}
示例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;
}
示例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"));
}
示例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;
}
示例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"));
}
示例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());
}
示例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();
}
示例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);
}
示例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);
}
示例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());
}
示例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());
}
示例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);
}
}
}
}
}
示例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);
}