Java Code Examples for com.alibaba.dubbo.common.extension.ExtensionLoader#getExtensionLoader()
The following examples show how to use
com.alibaba.dubbo.common.extension.ExtensionLoader#getExtensionLoader() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatusesController.java From open-capacity-platform with Apache License 2.0 | 6 votes |
@RequestMapping("") public String index(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception { prepare(request, response, model, "index", "status"); ExtensionLoader<StatusChecker> loader = ExtensionLoader.getExtensionLoader(StatusChecker.class); Map<String, Status> statusList = new LinkedHashMap<String, Status>(); for (String name : loader.getSupportedExtensions()) { com.alibaba.dubbo.common.status.Status status = loader.getExtension(name).check(); if (status.getLevel() != null && status.getLevel() != com.alibaba.dubbo.common.status.Status.Level.UNKNOWN) { statusList.put(name, status); } } statusList.put("summary", StatusManager.getStatusSummary(statusList)); model.addAttribute("statusList", statusList); return "sysinfo/screen/statuses/index"; }
Example 2
Source File: DubboShutdownHook.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
/** * Destroy all the resources, including registries and protocols. */ public void destroyAll() { // 自旋锁,保证只处理一次,一般在项目中多线程情况下做线程开关很好用 if (!destroyed.compareAndSet(false, true)) { return; } // destroy all the registries 销毁所有注册信息=》 AbstractRegistryFactory.destroyAll(); // destroy all the protocols 销毁所有协议信息 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); } } }
Example 3
Source File: AdaptiveExtensionFactory.java From dubbox with Apache License 2.0 | 5 votes |
public AdaptiveExtensionFactory() { ExtensionLoader<ExtensionFactory> loader = ExtensionLoader.getExtensionLoader(ExtensionFactory.class); List<ExtensionFactory> list = new ArrayList<ExtensionFactory>(); for (String name : loader.getSupportedExtensions()) { list.add(loader.getExtension(name)); } factories = Collections.unmodifiableList(list); }
Example 4
Source File: ExtensionLoaderTest.java From dubbo3 with Apache License 2.0 | 5 votes |
@Test public void test_AddExtension_Adaptive_ExceptionWhenExistedAdaptive() throws Exception { ExtensionLoader<AddExt1> loader = ExtensionLoader.getExtensionLoader(AddExt1.class); loader.getAdaptiveExtension(); try { loader.addExtension(null, AddExt1_ManualAdaptive.class); fail(); } catch (IllegalStateException expected) { assertThat(expected.getMessage(), containsString("Adaptive Extension already existed(Extension interface com.alibaba.dubbo.common.extensionloader.ext8_add.AddExt1)!")); } }
Example 5
Source File: AdaptiveCompiler.java From dubbo3 with Apache License 2.0 | 5 votes |
public Class<?> compile(String code, ClassLoader classLoader) { Compiler compiler; ExtensionLoader<Compiler> loader = ExtensionLoader.getExtensionLoader(Compiler.class); String name = DEFAULT_COMPILER; // copy reference if (name != null && name.length() > 0) { compiler = loader.getExtension(name); } else { compiler = loader.getDefaultExtension(); } return compiler.compile(code, classLoader); }
Example 6
Source File: ExtensionLoaderTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@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); }
Example 7
Source File: ExtensionLoaderTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void test_AddExtension_Adaptive() throws Exception { ExtensionLoader<AddExt2> loader = ExtensionLoader.getExtensionLoader(AddExt2.class); loader.addExtension(null, AddExt2_ManualAdaptive.class); AddExt2 adaptive = loader.getAdaptiveExtension(); assertTrue(adaptive instanceof AddExt2_ManualAdaptive); }
Example 8
Source File: AdaptiveExtensionFactory.java From dubbox with Apache License 2.0 | 5 votes |
public AdaptiveExtensionFactory() { ExtensionLoader<ExtensionFactory> loader = ExtensionLoader.getExtensionLoader(ExtensionFactory.class); List<ExtensionFactory> list = new ArrayList<ExtensionFactory>(); for (String name : loader.getSupportedExtensions()) { list.add(loader.getExtension(name)); } factories = Collections.unmodifiableList(list); }
Example 9
Source File: SpiExtensionFactory.java From dubbox with Apache License 2.0 | 5 votes |
public <T> T getExtension(Class<T> type, String name) { if (type.isInterface() && type.isAnnotationPresent(SPI.class)) { ExtensionLoader<T> loader = ExtensionLoader.getExtensionLoader(type); if (loader.getSupportedExtensions().size() > 0) { return loader.getAdaptiveExtension(); } } return null; }
Example 10
Source File: ExtensionLoaderTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@Test public void test_getExtensionLoader_NotInterface() throws Exception { try { ExtensionLoader.getExtensionLoader(ExtensionLoaderTest.class); fail(); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage(), containsString("Extension type(class com.alibaba.dubbo.common.extensionloader.ExtensionLoaderTest) is not interface")); } }
Example 11
Source File: AdaptiveExtensionFactory.java From dubbox with Apache License 2.0 | 5 votes |
public AdaptiveExtensionFactory() { ExtensionLoader<ExtensionFactory> loader = ExtensionLoader.getExtensionLoader(ExtensionFactory.class); List<ExtensionFactory> list = new ArrayList<ExtensionFactory>(); for (String name : loader.getSupportedExtensions()) { list.add(loader.getExtension(name)); } factories = Collections.unmodifiableList(list); }
Example 12
Source File: ExtensionLoaderTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@Test public void test_AddExtension_Adaptive() throws Exception { ExtensionLoader<AddExt2> loader = ExtensionLoader.getExtensionLoader(AddExt2.class); loader.addExtension(null, AddExt2_ManualAdaptive.class); AddExt2 adaptive = loader.getAdaptiveExtension(); assertTrue(adaptive instanceof AddExt2_ManualAdaptive); }
Example 13
Source File: ExtensionLoaderTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void test_getExtensionLoader_NotInterface() throws Exception { try { ExtensionLoader.getExtensionLoader(ExtensionLoaderTest.class); fail(); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage(), containsString("Extension type(class com.alibaba.dubbo.common.extensionloader.ExtensionLoaderTest) is not interface")); } }
Example 14
Source File: ExtensionLoaderTest.java From dubbo3 with Apache License 2.0 | 5 votes |
@Test public void test_replaceExtension_Adaptive_ExceptionWhenNotExistedExtension() throws Exception { ExtensionLoader<AddExt4> loader = ExtensionLoader.getExtensionLoader(AddExt4.class); try { loader.replaceExtension(null, AddExt4_ManualAdaptive.class); fail(); } catch (IllegalStateException expected) { assertThat(expected.getMessage(), containsString("Adaptive Extension not existed(Extension interface com.alibaba.dubbo.common.extensionloader.ext8_add.AddExt4)")); } }
Example 15
Source File: ExtensionLoaderTest.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Test public void test_getExtensionLoader_NotSpiAnnotation() throws Exception { try { ExtensionLoader.getExtensionLoader(NoSpiExt.class); fail(); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage(), allOf(containsString("com.alibaba.dubbo.common.extensionloader.NoSpiExt"), containsString("is not extension"), containsString("WITHOUT @SPI Annotation"))); } }
Example 16
Source File: ExtensionLoaderTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void test_getExtensionLoader_Null() throws Exception { try { ExtensionLoader.getExtensionLoader(null); fail(); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage(), containsString("Extension type == null")); } }
Example 17
Source File: ProtocolConfig.java From dubbo3 with Apache License 2.0 | 5 votes |
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); } } }
Example 18
Source File: AdaptiveCompiler.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Override public Class<?> compile(String code, ClassLoader classLoader) { Compiler compiler; ExtensionLoader<Compiler> loader = ExtensionLoader.getExtensionLoader(Compiler.class); String name = DEFAULT_COMPILER; // copy reference if (name != null && name.length() > 0) { compiler = loader.getExtension(name); } else { compiler = loader.getDefaultExtension(); } return compiler.compile(code, classLoader); }
Example 19
Source File: ExtensionLoaderTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void test_getExtensionLoader_NotSpiAnnotation() throws Exception { try { ExtensionLoader.getExtensionLoader(NoSpiExt.class); fail(); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage(), allOf(containsString("com.alibaba.dubbo.common.extensionloader.NoSpiExt"), containsString("is not extension"), containsString("WITHOUT @SPI Annotation"))); } }
Example 20
Source File: ExtensionLoader_Adaptive_Test.java From dubbox with Apache License 2.0 | 4 votes |
@Test public void test_useAdaptiveClass() throws Exception { ExtensionLoader<HasAdaptiveExt> loader = ExtensionLoader.getExtensionLoader(HasAdaptiveExt.class); HasAdaptiveExt ext = loader.getAdaptiveExtension(); assertTrue(ext instanceof HasAdaptiveExt_ManualAdaptive); }