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


Java ExtensionLoader类代码示例

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


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

示例1: testHessianProtocol

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

示例2: test_getAdaptiveExtension_inject

import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入依赖的package包/类
@Test
public void test_getAdaptiveExtension_inject() throws Exception {
    LogUtil.start();
    Ext6 ext = ExtensionLoader.getExtensionLoader(Ext6.class).getAdaptiveExtension();

    URL url = new URL("p1", "1.2.3.4", 1010, "path1");
    url = url.addParameters("ext6", "impl1");
    
    assertEquals("Ext6Impl1-echo-Ext1Impl1-echo", ext.echo(url, "ha"));
    
    Assert.assertTrue("can not find error.", LogUtil.checkNoError());
    LogUtil.stop();
    
    url = url.addParameters("simple.ext", "impl2");
    assertEquals("Ext6Impl1-echo-Ext1Impl2-echo", ext.echo(url, "ha"));
    
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:18,代码来源:ExtensionLoader_Adaptive_Test.java

示例3: test_getAdaptiveExtension_ExceptionWhenNotAdaptiveMethod

import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入依赖的package包/类
@Test
public void test_getAdaptiveExtension_ExceptionWhenNotAdaptiveMethod() throws Exception {
    SimpleExt ext = ExtensionLoader.getExtensionLoader(SimpleExt.class).getAdaptiveExtension();

    Map<String, String> map = new HashMap<String, String>();
    URL url = new URL("p1", "1.2.3.4", 1010, "path1", map);

    try {
        ext.bang(url, 33);
        fail();
    } catch (UnsupportedOperationException expected) {
        assertThat(expected.getMessage(), containsString("method "));
        assertThat(
                expected.getMessage(),
                containsString("of interface com.alibaba.dubbo.common.extensionloader.ext1.SimpleExt is not adaptive method!"));
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:18,代码来源:ExtensionLoader_Adaptive_Test.java

示例4: test_getExtension_WithWrapper

import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入依赖的package包/类
@Test
public void test_getExtension_WithWrapper() throws Exception {
    WrappedExt impl1 = ExtensionLoader.getExtensionLoader(WrappedExt.class).getExtension("impl1");
    assertThat(impl1, anyOf(instanceOf(Ext5Wrapper1.class), instanceOf(Ext5Wrapper2.class)));
    
    WrappedExt impl2 = ExtensionLoader.getExtensionLoader(WrappedExt.class).getExtension("impl2") ;
    assertThat(impl2, anyOf(instanceOf(Ext5Wrapper1.class), instanceOf(Ext5Wrapper2.class)));
    
    
    URL url = new URL("p1", "1.2.3.4", 1010, "path1");
    int echoCount1 = Ext5Wrapper1.echoCount.get();
    int echoCount2 = Ext5Wrapper2.echoCount.get();

    assertEquals("Ext5Impl1-echo", impl1.echo(url, "ha"));
    assertEquals(echoCount1 + 1, Ext5Wrapper1.echoCount.get());
    assertEquals(echoCount2 + 1, Ext5Wrapper2.echoCount.get());
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:18,代码来源:ExtensionLoaderTest.java

示例5: testHttpClient

import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入依赖的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

示例6: testLoadDefaultActivateExtension

import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入依赖的package包/类
@Test
public void testLoadDefaultActivateExtension() throws Exception {
    // test default
    URL url = URL.valueOf("test://localhost/test?ext=order1,default");
    List<ActivateExt1> list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
            .getActivateExtension(url, "ext", "default_group");
    Assert.assertEquals(2, list.size());
    Assert.assertTrue(list.get(0).getClass() == OrderActivateExtImpl1.class);
    Assert.assertTrue(list.get(1).getClass() == ActivateExt1Impl1.class);
    
    url = URL.valueOf("test://localhost/test?ext=default,order1");
    list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
            .getActivateExtension(url, "ext", "default_group");
    Assert.assertEquals(2, list.size());
    Assert.assertTrue(list.get(0).getClass() == ActivateExt1Impl1.class);
    Assert.assertTrue(list.get(1).getClass() == OrderActivateExtImpl1.class);
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:18,代码来源:ExtensionLoaderTest.java

示例7: init

import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入依赖的package包/类
@Override
public void init() throws ServletException {
    super.init();
    INSTANCE = this;
    String config = getServletConfig().getInitParameter("pages");
    Collection<String> names;
    if (config != null && config.length() > 0) {
        names = Arrays.asList(Constants.COMMA_SPLIT_PATTERN.split(config));
    } else {
        names = ExtensionLoader.getExtensionLoader(PageHandler.class).getSupportedExtensions();
    }
    for (String name : names) {
        PageHandler handler = ExtensionLoader.getExtensionLoader(PageHandler.class).getExtension(name);
        pages.put(ExtensionLoader.getExtensionLoader(PageHandler.class).getExtensionName(handler), handler);
        Menu menu = handler.getClass().getAnnotation(Menu.class);
        if (menu != null) {
            menus.add(handler);
        }
    }
    Collections.sort(menus, new MenuComparator());
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:22,代码来源:PageServlet.java

示例8: checkMultiExtension

import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入依赖的package包/类
protected static void checkMultiExtension(Class<?> type, String property, String value) {
    checkMultiName(property, value);
    if (value != null && value.length() > 0) {
        String[] values = value.split("\\s*[,]+\\s*");
        for (String v : values) {
            if (v.startsWith(Constants.REMOVE_VALUE_PREFIX)) {
                v = v.substring(1);
            }
            if (Constants.DEFAULT_KEY.equals(v)) {
            	continue;
            }
            if (! ExtensionLoader.getExtensionLoader(type).hasExtension(v)) {
                throw new IllegalStateException("No such extension " + v + " for " + property + "/" + type.getName());
            }
        }
    }
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:18,代码来源:AbstractConfig.java

示例9: test_destroyWontCloseAllProtocol

import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入依赖的package包/类
@Test
public void test_destroyWontCloseAllProtocol() throws Exception {
    Protocol autowireProtocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    
    Protocol InjvmProtocol = ExtensionLoader.getExtensionLoader(Protocol.class).getExtension("injvm");
    
    InjvmProtocol.export(invoker);
    
    Invoker<IEcho> refer = InjvmProtocol.refer(IEcho.class, url);
    IEcho echoProxy = proxyFactory.getProxy(refer);
    
    assertEquals("ok", echoProxy.echo("ok"));
    
    try {
        autowireProtocol.destroy();
    } catch (UnsupportedOperationException expected) {
        assertThat(expected.getMessage(), containsString("of interface com.alibaba.dubbo.rpc.Protocol is not adaptive method!"));
    }
    
    assertEquals("ok2", echoProxy.echo("ok2"));
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:22,代码来源:ProtocolTest.java

示例10: testCustomException

import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入依赖的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:yunhaibin,项目名称:dubbox-hystrix,代码行数:18,代码来源:HessianProtocolTest.java

示例11: writeMenu

import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入依赖的package包/类
protected final void writeMenu(HttpServletRequest request, PrintWriter writer, String nav) {
    writer.println("<table>");
    writer.println("<thead>");
    writer.println("    <tr>");
    for (PageHandler handler : menus) {
        String uri = ExtensionLoader.getExtensionLoader(PageHandler.class).getExtensionName(handler);
        Menu menu = handler.getClass().getAnnotation(Menu.class);
        writer.println("        <th><a href=\"" + uri + ".html\">" + menu.name() + "</a></th>");
    }
    writer.println("    </tr>");
    writer.println("</thead>");
    writer.println("<tbody>");
    writer.println("    <tr>");
    writer.println("        <td style=\"text-align: left\" colspan=\"" + menus.size() + "\">");
    writer.println(nav);
    writer.println("        </td>");
    writer.println("    </tr>");
    writer.println("</tbody>");
    writer.println("</table>");
    writer.println("<br/>");
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:22,代码来源:PageServlet.java

示例12: invoke

import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入依赖的package包/类
public Result invoke(final Invocation invocation) throws RpcException {

        checkWheatherDestoried();

        LoadBalance loadbalance;
        
        List<Invoker<T>> invokers = list(invocation);
        if (invokers != null && invokers.size() > 0) {
            loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl()
                    .getMethodParameter(invocation.getMethodName(),Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE));
        } else {
            loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE);
        }
        RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);
        return doInvoke(invocation, invokers, loadbalance);
    }
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:17,代码来源:AbstractClusterInvoker.java

示例13: test_getAdaptiveExtension_customizeAdaptiveKey

import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入依赖的package包/类
@Test
public void test_getAdaptiveExtension_customizeAdaptiveKey() throws Exception {
    SimpleExt ext = ExtensionLoader.getExtensionLoader(SimpleExt.class).getAdaptiveExtension();

    Map<String, String> map = new HashMap<String, String>();
    map.put("key2", "impl2");
    URL url = new URL("p1", "1.2.3.4", 1010, "path1", map);

    String echo = ext.yell(url, "haha");
    assertEquals("Ext1Impl2-yell", echo);

    url = url.addParameter("key1", "impl3"); // 注意: URL是值类型
    echo = ext.yell(url, "haha");
    assertEquals("Ext1Impl3-yell", echo);
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:16,代码来源:ExtensionLoader_Adaptive_Test.java

示例14: destroyAll

import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入依赖的package包/类
public static void destroyAll() {
    AbstractRegistryFactory.destroyAll();
    ExtensionLoader<Protocol> loader = ExtensionLoader.getExtensionLoader(Protocol.class);
    for (String protocolName : loader.getLoadedExtensions()) {
        try {
            Protocol protocol = loader.getLoadedExtension(protocolName);
            if (protocol != null) {
                protocol.destroy();
            }
        } catch (Throwable t) {
            logger.warn(t.getMessage(), t);
        }
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:15,代码来源:ProtocolConfig.java

示例15: test_replaceExtension_Adaptive

import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入依赖的package包/类
@Test
public void test_replaceExtension_Adaptive() throws Exception {
    ExtensionLoader<AddExt3> loader = ExtensionLoader.getExtensionLoader(AddExt3.class);

    AddExt3 adaptive = loader.getAdaptiveExtension();
    assertFalse(adaptive instanceof AddExt3_ManualAdaptive);

    loader.replaceExtension(null, AddExt3_ManualAdaptive.class);

    adaptive = loader.getAdaptiveExtension();
    assertTrue(adaptive instanceof AddExt3_ManualAdaptive);
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:13,代码来源:ExtensionLoaderTest.java


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