本文整理汇总了Java中com.alibaba.dubbo.rpc.Invoker.destroy方法的典型用法代码示例。如果您正苦于以下问题:Java Invoker.destroy方法的具体用法?Java Invoker.destroy怎么用?Java Invoker.destroy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.dubbo.rpc.Invoker
的用法示例。
在下文中一共展示了Invoker.destroy方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testHessianProtocol
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
@Test
public void testHessianProtocol() {
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");
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();
}
示例2: 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();
}
示例3: testGenericEnum
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
@Test
public void testGenericEnum() throws InterruptedException{
int port = NetUtils.getAvailablePort();
URL serviceurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?timeout="+Integer.MAX_VALUE
);
DemoService demo = new DemoServiceImpl();
Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.class, serviceurl);
protocol.export(invoker);
URL consumerurl = serviceurl;
Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);
GenericService demoProxy = (GenericService)proxy.getProxy(reference);
Object obj = demoProxy.$invoke("enumlength", new String[]{Type[].class.getName()}, new Object[]{new Type[]{Type.High,Type.High}});
System.out.println("obj---------->"+obj);
invoker.destroy();
reference.destroy();
}
示例4: testTimeOut
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
@Test
public void testTimeOut() {
HessianServiceImpl server = new HessianServiceImpl();
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&timeout=10");
Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
Invoker<HessianService> invoker = protocol.refer(HessianService.class, url);
HessianService client = proxyFactory.getProxy(invoker);
try {
client.timeOut(6000);
fail();
} catch (RpcException expected) {
Assert.assertEquals(true, expected.isTimeout());
}finally{
invoker.destroy();
exporter.unexport();
}
}
示例5: testCustomException
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
@Test
public void testCustomException() {
HessianServiceImpl server = new HessianServiceImpl();
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");
Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
Invoker<HessianService> invoker = protocol.refer(HessianService.class, url);
HessianService client = proxyFactory.getProxy(invoker);
try {
client.customException();
fail();
} catch (MyException expected) {
}
invoker.destroy();
exporter.unexport();
}
示例6: testGenricCustomArg
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
public void testGenricCustomArg(){
int port = 20880;
URL consumerurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?timeout=2000000"
);
Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);
GenericService demoProxy = (GenericService)proxy.getProxy(reference);
Map<String, Object> arg = new HashMap<String, Object>();
arg.put("type", "High");
arg.put("name", "hi");
Object obj = demoProxy.$invoke("get", new String[]{"com.alibaba.dubbo.rpc.CustomArgument"}, new Object[]{arg});
System.out.println("obj---------->"+obj);
reference.destroy();
}
示例7: testGenricEnumCompat
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
public void testGenricEnumCompat(){
int port = 20880;
URL consumerurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?timeout="+Integer.MAX_VALUE
);
Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);
GenericService demoProxy = (GenericService)proxy.getProxy(reference);
Object obj = demoProxy.$invoke("enumlength", new String[]{Type[].class.getName()}, new Object[]{new Type[]{Type.High,Type.High}});
System.out.println("obj---------->"+obj);
reference.destroy();
}
示例8: testEnumCompat
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
public void testEnumCompat(){
int port = 20880;
URL consumerurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?timeout="+Integer.MAX_VALUE
);
Invoker<DemoService> reference = protocol.refer(DemoService.class, consumerurl);
DemoService demoProxy = (DemoService)proxy.getProxy(reference);
Type type = demoProxy.enumlength(Type.High);
System.out.println(type);
Assert.assertEquals(Type.High, type);
reference.destroy();
}
示例9: testInvokerDestoryAndReList
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
/**
* 测试在调用重试过程中,directory列表变更,invoke重试时重新进行list选择
*/
@Test
public void testInvokerDestoryAndReList(){
final URL url = URL.valueOf("test://localhost/"+ Demo.class.getName() + "?loadbalance=roundrobin&retries="+retries);
RpcException exception = new RpcException(RpcException.TIMEOUT_EXCEPTION);
MockInvoker<Demo> invoker1 = new MockInvoker<Demo>(Demo.class, url);
invoker1.setException(exception);
MockInvoker<Demo> invoker2 = new MockInvoker<Demo>(Demo.class, url);
invoker2.setException(exception);
final List<Invoker<Demo>> invokers = new ArrayList<Invoker<Demo>>();
invokers.add(invoker1);
invokers.add(invoker2);
Callable<Object> callable = new Callable<Object>() {
public Object call() throws Exception {
//模拟invoker全部被destroy掉
for (Invoker<Demo> invoker:invokers){
invoker.destroy();
}
invokers.clear();
MockInvoker<Demo> invoker3 = new MockInvoker<Demo>(Demo.class, url);
invokers.add(invoker3);
return null;
}
};
invoker1.setCallable(callable);
invoker2.setCallable(callable);
RpcInvocation inv = new RpcInvocation();
inv.setMethodName("test");
Directory<Demo> dic = new MockDirectory<Demo>(url, invokers);
FailoverClusterInvoker<Demo> clusterinvoker = new FailoverClusterInvoker<Demo>(dic);
clusterinvoker.invoke(inv);
}
示例10: buildInvokerChain
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
private static <T> Invoker<T> buildInvokerChain(final Invoker<T> invoker, String key, String group) {
Invoker<T> last = invoker;
List<Filter> filters = ExtensionLoader.getExtensionLoader(Filter.class).getActivateExtension(invoker.getUrl(), key, group);
if (filters.size() > 0) {
for (int i = filters.size() - 1; i >= 0; i --) {
final Filter filter = filters.get(i);
final Invoker<T> next = last;
last = new Invoker<T>() {
public Class<T> getInterface() {
return invoker.getInterface();
}
public URL getUrl() {
return invoker.getUrl();
}
public boolean isAvailable() {
return invoker.isAvailable();
}
public Result invoke(Invocation invocation) throws RpcException {
return filter.invoke(next, invocation);
}
public void destroy() {
invoker.destroy();
}
@Override
public String toString() {
return invoker.toString();
}
};
}
}
return last;
}
示例11: testInvokerDestoryAndReList
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
/**
* 测试在调用重试过程中,directory列表变更,invoke重试时重新进行list选择
*/
@Test
public void testInvokerDestoryAndReList() {
final URL url = URL.valueOf("test://localhost/" + Demo.class.getName() + "?loadbalance=roundrobin&retries=" + retries);
RpcException exception = new RpcException(RpcException.TIMEOUT_EXCEPTION);
MockInvoker<Demo> invoker1 = new MockInvoker<Demo>(Demo.class, url);
invoker1.setException(exception);
MockInvoker<Demo> invoker2 = new MockInvoker<Demo>(Demo.class, url);
invoker2.setException(exception);
final List<Invoker<Demo>> invokers = new ArrayList<Invoker<Demo>>();
invokers.add(invoker1);
invokers.add(invoker2);
Callable<Object> callable = new Callable<Object>() {
public Object call() throws Exception {
//模拟invoker全部被destroy掉
for (Invoker<Demo> invoker : invokers) {
invoker.destroy();
}
invokers.clear();
MockInvoker<Demo> invoker3 = new MockInvoker<Demo>(Demo.class, url);
invokers.add(invoker3);
return null;
}
};
invoker1.setCallable(callable);
invoker2.setCallable(callable);
RpcInvocation inv = new RpcInvocation();
inv.setMethodName("test");
Directory<Demo> dic = new MockDirectory<Demo>(url, invokers);
FailoverClusterInvoker<Demo> clusterinvoker = new FailoverClusterInvoker<Demo>(dic);
clusterinvoker.invoke(inv);
}
示例12: destroyUnusedInvokers
import com.alibaba.dubbo.rpc.Invoker; //导入方法依赖的package包/类
/**
* 检查缓存中的invoker是否需要被destroy
* 如果url中指定refer.autodestroy=false,则只增加不减少,可能会有refer泄漏,
*
* @param invokers
*/
private void destroyUnusedInvokers(Map<String, Invoker<T>> oldUrlInvokerMap, Map<String, Invoker<T>> newUrlInvokerMap) {
if (newUrlInvokerMap == null || newUrlInvokerMap.size() == 0) {
destroyAllInvokers();
return;
}
// check deleted invoker
List<String> deleted = null;
if (oldUrlInvokerMap != null) {
Collection<Invoker<T>> newInvokers = newUrlInvokerMap.values();
for (Map.Entry<String, Invoker<T>> entry : oldUrlInvokerMap.entrySet()) {
if (!newInvokers.contains(entry.getValue())) {
if (deleted == null) {
deleted = new ArrayList<String>();
}
deleted.add(entry.getKey());
}
}
}
if (deleted != null) {
for (String url : deleted) {
if (url != null) {
Invoker<T> invoker = oldUrlInvokerMap.remove(url);
if (invoker != null) {
try {
invoker.destroy();
if (logger.isDebugEnabled()) {
logger.debug("destory invoker[" + invoker.getUrl() + "] success. ");
}
} catch (Exception e) {
logger.warn("destory invoker[" + invoker.getUrl() + "] faild. " + e.getMessage(), e);
}
}
}
}
}
}