本文整理汇总了Java中com.alibaba.dubbo.common.extension.ExtensionLoader.getExtensionLoader方法的典型用法代码示例。如果您正苦于以下问题:Java ExtensionLoader.getExtensionLoader方法的具体用法?Java ExtensionLoader.getExtensionLoader怎么用?Java ExtensionLoader.getExtensionLoader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.dubbo.common.extension.ExtensionLoader
的用法示例。
在下文中一共展示了ExtensionLoader.getExtensionLoader方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getExtension
import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入方法依赖的package包/类
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;
}
示例2: compile
import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入方法依赖的package包/类
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);
}
示例3: test_InitError
import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入方法依赖的package包/类
@Test
public void test_InitError() throws Exception {
ExtensionLoader<InitErrorExt> loader = ExtensionLoader.getExtensionLoader(InitErrorExt.class);
loader.getExtension("ok");
try {
loader.getExtension("error");
fail();
} catch (IllegalStateException expected) {
assertThat(expected.getMessage(), containsString("Failed to load extension class(interface: interface com.alibaba.dubbo.common.extensionloader.ext7.InitErrorExt"));
assertThat(expected.getCause(), instanceOf(ExceptionInInitializerError.class));
}
}
示例4: test_getExtensionLoader_Null
import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入方法依赖的package包/类
@Test
public void test_getExtensionLoader_Null() throws Exception {
try {
ExtensionLoader.getExtensionLoader(null);
fail();
} catch (IllegalArgumentException expected) {
assertThat(expected.getMessage(),
containsString("Extension type == null"));
}
}
示例5: 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);
}
}
}
示例6: test_getExtensionLoader_NotSpiAnnotation
import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入方法依赖的package包/类
@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")));
}
}
示例7: test_AddExtension_Adaptive
import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入方法依赖的package包/类
@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);
}
示例8: test_AddExtension_Adaptive_ExceptionWhenExistedAdaptive
import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入方法依赖的package包/类
@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)!"));
}
}
示例9: test_replaceExtension_Adaptive_ExceptionWhenNotExistedExtension
import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入方法依赖的package包/类
@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)"));
}
}
示例10: 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);
}
示例11: test_getExtensionLoader_NotInterface
import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入方法依赖的package包/类
@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"));
}
}
示例12: test_useAdaptiveClass
import com.alibaba.dubbo.common.extension.ExtensionLoader; //导入方法依赖的package包/类
@Test
public void test_useAdaptiveClass() throws Exception {
ExtensionLoader<HasAdaptiveExt> loader = ExtensionLoader.getExtensionLoader(HasAdaptiveExt.class);
HasAdaptiveExt ext = loader.getAdaptiveExtension();
assertTrue(ext instanceof HasAdaptiveExt_ManualAdaptive);
}