in common/src/main/java/org/apache/seata/common/loader/EnhancedServiceLoader.java [569:628]
private void loadFile(String dir, Class type, ClassLoader loader, List<ExtensionDefinition<S>> extensions)
throws IOException {
String fileName = dir + type.getName();
Enumeration<java.net.URL> urls;
if (loader != null) {
urls = loader.getResources(fileName);
} else {
urls = ClassLoader.getSystemResources(fileName);
}
if (urls != null) {
boolean hasServiceFile = false;
boolean hasClasses = false;
while (urls.hasMoreElements()) {
hasServiceFile = true;
java.net.URL url = urls.nextElement();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), Constants.DEFAULT_CHARSET))) {
String line;
while ((line = reader.readLine()) != null) {
final int ci = line.indexOf('#');
if (ci >= 0) {
line = line.substring(0, ci);
}
line = line.trim();
if (line.length() > 0) {
hasClasses = true;
try {
ExtensionDefinition<S> extensionDefinition = getUnloadedExtensionDefinition(line, loader);
if (extensionDefinition == null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("The same extension {} has already been loaded, skipped", line);
}
continue;
}
extensions.add(extensionDefinition);
} catch (LinkageError | ClassNotFoundException e) {
LOGGER.warn("Load [{}] class fail: {}", line, e.getMessage());
} catch (ClassCastException e) {
LOGGER.error("Load [{}] class fail, please make sure the extension" +
" config in {} implements {}.", line, fileName, type.getName());
}
}
}
} catch (Throwable e) {
LOGGER.warn("load class instance error:", e);
}
}
if (LOGGER.isDebugEnabled()) {
if (!hasServiceFile) {
LOGGER.warn("Load [{}] class fail: no service files found in '{}'.", type.getName(), dir);
} else if (!hasClasses) {
LOGGER.warn("Load [{}] class fail: the service files in '{}' is all empty.", type.getName(), dir);
}
}
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.warn("Load [{}] class fail: no urls found in '{}'.", type.getName(), dir);
}
}
}