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


Java Exporter类代码示例

本文整理汇总了Java中com.alibaba.dubbo.rpc.Exporter的典型用法代码示例。如果您正苦于以下问题:Java Exporter类的具体用法?Java Exporter怎么用?Java Exporter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Exporter类属于com.alibaba.dubbo.rpc包,在下文中一共展示了Exporter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testNotifyOverride

import com.alibaba.dubbo.rpc.Exporter; //导入依赖的package包/类
@Test
public void testNotifyOverride() throws Exception{
    URL newRegistryUrl = registryUrl.addParameter(Constants.EXPORT_KEY, serviceUrl);
    Invoker<RegistryProtocolTest> invoker = new MockInvoker<RegistryProtocolTest>(RegistryProtocolTest.class, newRegistryUrl);
    Exporter<?> exporter = protocol.export(invoker);
    RegistryProtocol rprotocol = RegistryProtocol.getRegistryProtocol();
    NotifyListener listener = getListener(rprotocol);
    List<URL> urls = new ArrayList<URL>();
    urls.add(URL.valueOf("override://0.0.0.0/?timeout=1000"));
    urls.add(URL.valueOf("override://0.0.0.0/"+ service + "?timeout=100"));
    urls.add(URL.valueOf("override://0.0.0.0/"+ service + "?x=y"));
    listener.notify(urls);
    
    assertEquals(true, exporter.getInvoker().isAvailable());
    assertEquals("100", exporter.getInvoker().getUrl().getParameter("timeout"));
    assertEquals("y", exporter.getInvoker().getUrl().getParameter("x"));
    
    exporter.unexport();
    assertEquals(false, exporter.getInvoker().isAvailable());
    destroyRegistryProtocol();
    
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:23,代码来源:RegistryProtocolTest.java

示例2: testMultiRegistry

import com.alibaba.dubbo.rpc.Exporter; //导入依赖的package包/类
@Test
public void testMultiRegistry() {
    SimpleRegistryService registryService1 = new SimpleRegistryService();
    Exporter<RegistryService> exporter1 = SimpleRegistryExporter.export(4545, registryService1);
    SimpleRegistryService registryService2 = new SimpleRegistryService();
    Exporter<RegistryService> exporter2 = SimpleRegistryExporter.export(4546, registryService2);
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-registry.xml");
    ctx.start();
    try {
        List<URL> urls1 = registryService1.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
        assertNull(urls1);
        List<URL> urls2 = registryService2.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
        assertNotNull(urls2);
        assertEquals(1, urls2.size());
        assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20880/com.alibaba.dubbo.config.spring.api.DemoService", urls2.get(0).toIdentityString());
    } finally {
        ctx.stop();
        ctx.close();
        exporter1.unexport();
        exporter2.unexport();
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:23,代码来源:ConfigTest.java

示例3: exportLocal

import com.alibaba.dubbo.rpc.Exporter; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private void exportLocal(URL url) {
    if (!Constants.LOCAL_PROTOCOL.equalsIgnoreCase(url.getProtocol())) {
        URL local = URL.valueOf(url.toFullString())
                .setProtocol(Constants.LOCAL_PROTOCOL)
                .setHost(NetUtils.LOCALHOST)
                .setPort(0);

        // modified by lishen
        ServiceClassHolder.getInstance().pushServiceClass(getServiceClass(ref));

        Exporter<?> exporter = protocol.export(
                proxyFactory.getInvoker(ref, (Class) interfaceClass, local));
        exporters.add(exporter);
        logger.info("Export dubbo service " + interfaceClass.getName() +" to local registry");
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:18,代码来源:ServiceConfig.java

示例4: testHttpClient

import com.alibaba.dubbo.rpc.Exporter; //导入依赖的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:dachengxi,项目名称:EatDubbo,代码行数:17,代码来源:HessianProtocolTest.java

示例5: testCustomException

import com.alibaba.dubbo.rpc.Exporter; //导入依赖的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();
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:18,代码来源:HessianProtocolTest.java

示例6: export

import com.alibaba.dubbo.rpc.Exporter; //导入依赖的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: testRmiProtocolTimeout

import com.alibaba.dubbo.rpc.Exporter; //导入依赖的package包/类
@Test
public void testRmiProtocolTimeout() throws Exception
{
    System.setProperty("sun.rmi.transport.tcp.responseTimeout", "1000");
    DemoService service = new DemoServiceImpl();
    Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("rmi://127.0.0.1:9001/TestService")));
    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("rmi://127.0.0.1:9001/TestService")));
    try {
        try {
            service.throwTimeout();
        } catch (RpcException e) {
            assertEquals(true, e.isTimeout());
            assertEquals(true, e.getMessage().contains("Read timed out"));
        }
    } finally {
        rpcExporter.unexport();
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:19,代码来源:RmiProtocolTest.java

示例8: testRmiProtocol_echoService

import com.alibaba.dubbo.rpc.Exporter; //导入依赖的package包/类
@Ignore
@Test
public void testRmiProtocol_echoService() throws Exception
   {
    DemoService service = new DemoServiceImpl();
    Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("rmi://127.0.0.1:9002/TestService")));
       
    // cast to EchoService
       EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("rmi://127.0.0.1:9002/TestService")));
       assertEquals(echo.$echo("test"), "test");
       assertEquals(echo.$echo("abcdefg"), "abcdefg");
       assertEquals(echo.$echo(1234), 1234);
       
       rpcExporter.unexport();
       
       RemoteService remoteService = new RemoteServiceImpl();
       rpcExporter = protocol.export(proxy.getInvoker(remoteService, RemoteService.class, URL.valueOf("rmi://127.0.0.1:9002/remoteService")));
       
       // cast to EchoService
       echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("rmi://127.0.0.1:9002/remoteService")));
       assertEquals(echo.$echo("test"), "test");
       assertEquals(echo.$echo("abcdefg"), "abcdefg");
       assertEquals(echo.$echo(1234), 1234);
       
       rpcExporter.unexport();
   }
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:27,代码来源:RmiProtocolTest.java

示例9: unexport

import com.alibaba.dubbo.rpc.Exporter; //导入依赖的package包/类
public synchronized void unexport() {
    if (! exported) {
        return;
    }
    if (unexported) {
        return;
    }
	if (exporters != null && exporters.size() > 0) {
		for (Exporter<?> exporter : exporters) {
			try {
                exporter.unexport();
            } catch (Throwable t) {
                logger.warn("unexpected err when unexport" + exporter, t);
            }
		}
		exporters.clear();
	}
    unexported = true;
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:20,代码来源:ServiceConfig.java

示例10: testMultiProtocolRegister

import com.alibaba.dubbo.rpc.Exporter; //导入依赖的package包/类
@Test
public void testMultiProtocolRegister() {
    SimpleRegistryService registryService = new SimpleRegistryService();
    Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4547, registryService);
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-register.xml");
    ctx.start();
    try {
        List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
        assertNotNull(urls);
        assertEquals(1, urls.size());
        assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20824/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString());
    } finally {
        ctx.stop();
        ctx.close();
        exporter.unexport();
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:18,代码来源:ConfigTest.java

示例11: ListenerExporterWrapper

import com.alibaba.dubbo.rpc.Exporter; //导入依赖的package包/类
public ListenerExporterWrapper(Exporter<T> exporter, List<ExporterListener> listeners){
    if (exporter == null) {
        throw new IllegalArgumentException("exporter == null");
    }
    this.exporter = exporter;
    this.listeners = listeners;
    if (listeners != null && listeners.size() > 0) {
        RuntimeException exception = null;
        for (ExporterListener listener : listeners) {
            if (listener != null) {
                try {
                    listener.exported(this);
                } catch (RuntimeException t) {
                    logger.error(t.getMessage(), t);
                    exception = t;
                }
            }
        }
        if (exception != null) {
            throw exception;
        }
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:24,代码来源:ListenerExporterWrapper.java

示例12: testAnnotation

import com.alibaba.dubbo.rpc.Exporter; //导入依赖的package包/类
@Test
public void testAnnotation() {
    SimpleRegistryService registryService = new SimpleRegistryService();
    Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService);
    try {
        ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/annotation-provider.xml");
        providerContext.start();
        try {
            ClassPathXmlApplicationContext consumerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/annotation-consumer.xml");
            consumerContext.start();
            try {
                AnnotationAction annotationAction = (AnnotationAction) consumerContext.getBean("annotationAction");
                String hello = annotationAction.doSayName("hello");
                assertEquals("annotation:hello", hello);
            } finally {
                consumerContext.stop();
                consumerContext.close();
            }
        } finally {
            providerContext.stop();
            providerContext.close();
        }
    } finally {
        exporter.unexport();
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:27,代码来源:ConfigTest.java

示例13: testDelayOnInitialized

import com.alibaba.dubbo.rpc.Exporter; //导入依赖的package包/类
@Test
public void testDelayOnInitialized() throws Exception {
    SimpleRegistryService registryService = new SimpleRegistryService();
    Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService);
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/delay-on-initialized.xml");
    //ctx.start();
    try {
        List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
        assertNotNull(urls);
        assertEquals(1, urls.size());
        assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20883/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString());
    } finally {
        ctx.stop();
        ctx.close();
        exporter.unexport();
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:18,代码来源:ConfigTest.java

示例14: testExport

import com.alibaba.dubbo.rpc.Exporter; //导入依赖的package包/类
@Test
public void testExport() {
    RegistryProtocol registryProtocol = new RegistryProtocol();
    registryProtocol.setCluster(new FailfastCluster());
    registryProtocol.setRegistryFactory(ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension());

    Protocol dubboProtocol = DubboProtocol.getDubboProtocol();
    registryProtocol.setProtocol(dubboProtocol);
    URL newRegistryUrl = registryUrl.addParameter(Constants.EXPORT_KEY, serviceUrl);
    DubboInvoker<DemoService> invoker = new DubboInvoker<DemoService>(DemoService.class,
            newRegistryUrl, new ExchangeClient[] { new MockedClient("10.20.20.20", 2222, true) });
    Exporter<DemoService> exporter = registryProtocol.export(invoker);
    Exporter<DemoService> exporter2 = registryProtocol.export(invoker);
    //同一个invoker,多次export的exporter不同
    Assert.assertNotSame(exporter, exporter2);
    exporter.unexport();
    exporter2.unexport();
    
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:20,代码来源:RegistryProtocolTest.java

示例15: doLocalExport

import com.alibaba.dubbo.rpc.Exporter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T> ExporterChangeableWrapper<T>  doLocalExport(final Invoker<T> originInvoker){
    String key = getCacheKey(originInvoker);
    ExporterChangeableWrapper<T> exporter = (ExporterChangeableWrapper<T>) bounds.get(key);
    if (exporter == null) {
        synchronized (bounds) {
            exporter = (ExporterChangeableWrapper<T>) bounds.get(key);
            if (exporter == null) {
                final Invoker<?> invokerDelegete = new InvokerDelegete<T>(originInvoker, getProviderUrl(originInvoker));
                exporter = new ExporterChangeableWrapper<T>((Exporter<T>)protocol.export(invokerDelegete), originInvoker);
                bounds.put(key, exporter);
            }
        }
    }
    return (ExporterChangeableWrapper<T>) exporter;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:17,代码来源:RegistryProtocol.java


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