use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by alipay.
the class GlobalEventHandlerTest method testEvent.
@Test
public void testEvent() {
Biz biz = new BizModel().setBizName("test-biz").setBizVersion("1.0.0").setBizState(BizState.RESOLVED);
Plugin plugin = new PluginModel().setPluginName("test-plugin").setVersion("1.0.0");
eventAdminService.sendEvent(new AfterBizStartupEvent(biz));
Assert.assertTrue(result.size() == 3);
Assert.assertTrue(result.contains("AbstractArkEvent->AfterBizStartupEvent"));
eventAdminService.sendEvent(new BeforePluginStartupEvent(plugin));
Assert.assertTrue(result.size() == 5);
// test for ArkEvent.class.isAssignableFrom(event.getClass()
eventAdminService.sendEvent(new ArkEvent() {
@Override
public String getTopic() {
return "ark-event";
}
});
Assert.assertTrue(result.size() == 7);
}
use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by alipay.
the class ClassloaderServiceImpl method isClassInImport.
@Override
public boolean isClassInImport(String pluginName, String className) {
Plugin plugin = pluginManagerService.getPluginByName(pluginName);
AssertUtils.assertNotNull(plugin, "plugin: " + pluginName + " is null");
for (String importName : plugin.getImportIndex()) {
if (className.startsWith(importName)) {
return true;
}
}
return false;
}
use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by alipay.
the class PluginFactoryServiceTest method testCreatePluginWithExtensions.
@Test
public void testCreatePluginWithExtensions() throws Throwable {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL samplePlugin = cl.getResource("sample-plugin.jar");
File file = new File(samplePlugin.getFile());
JarFile pluginFile = new JarFile(file);
JarFileArchive jarFileArchive = new JarFileArchive(pluginFile);
JarPluginArchive jarPluginArchive = new JarPluginArchive(jarFileArchive);
// inject
URL[] extensions = new URL[1];
URL sampleBiz = cl.getResource("sample-biz.jar");
JarFile bizFile = new JarFile(new File(sampleBiz.getFile()));
extensions[0] = bizFile.getUrl();
// export
Set<String> exportPackages = new HashSet<>();
exportPackages.add("com.alipay.test.export.*");
ArkConfigs.putStringValue(String.format(PLUGIN_EXTENSION_FORMAT, "sample-ark-plugin"), "tracer-core:3.0.10");
Plugin plugin = pluginFactoryService.createPlugin(jarPluginArchive, extensions, exportPackages);
Assert.assertNotNull(plugin);
Assert.assertEquals(plugin.getExportPackages().size(), 2);
Assert.assertTrue(Arrays.asList(plugin.getClassPath()).contains(bizFile.getUrl()));
}
use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by alipay.
the class ClassLoaderServiceImpl method isResourceInImport.
@Override
public boolean isResourceInImport(String pluginName, String resourceName) {
Plugin plugin = pluginManagerService.getPluginByName(pluginName);
AssertUtils.assertNotNull(plugin, "plugin: " + pluginName + " is null");
for (String importResource : plugin.getImportResources()) {
if (importResource.equals(resourceName)) {
return true;
}
}
for (String importResource : plugin.getImportPrefixResourceStems()) {
if (resourceName.startsWith(importResource)) {
return true;
}
}
for (String importResource : plugin.getImportSuffixResourceStems()) {
if (resourceName.endsWith(importResource)) {
return true;
}
}
return false;
}
use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by alipay.
the class ClassLoaderServiceImpl method prepareExportClassAndResourceCache.
@Override
public void prepareExportClassAndResourceCache() {
for (Plugin plugin : pluginManagerService.getPluginsInOrder()) {
for (String exportIndex : plugin.getExportPackageNodes()) {
exportNodeAndClassLoaderMap.putIfAbsent(exportIndex, plugin.getPluginClassLoader());
}
for (String exportIndex : plugin.getExportPackageStems()) {
exportStemAndClassLoaderMap.putIfAbsent(exportIndex, plugin.getPluginClassLoader());
}
for (String exportIndex : plugin.getExportClasses()) {
exportClassAndClassLoaderMap.putIfAbsent(exportIndex, plugin.getPluginClassLoader());
}
for (String resource : plugin.getExportResources()) {
exportResourceAndClassLoaderMap.putIfAbsent(resource, new LinkedList<>());
exportResourceAndClassLoaderMap.get(resource).add(plugin.getPluginClassLoader());
}
for (String resource : plugin.getExportPrefixResourceStems()) {
exportPrefixStemResourceAndClassLoaderMap.putIfAbsent(resource, new LinkedList<>());
exportPrefixStemResourceAndClassLoaderMap.get(resource).add(plugin.getPluginClassLoader());
}
for (String resource : plugin.getExportSuffixResourceStems()) {
exportSuffixStemResourceAndClassLoaderMap.putIfAbsent(resource, new LinkedList<>());
exportSuffixStemResourceAndClassLoaderMap.get(resource).add(plugin.getPluginClassLoader());
}
}
}
Aggregations