use of com.shulie.instrument.simulator.core.classloader.ModuleClassLoader in project LinkAgent by shulieTech.
the class ClassLoaderFactoryImpl method getClassLoader.
@Override
public ClassLoader getClassLoader(ClassLoader businessClassLoader) {
if (!isMiddlewareModule) {
return defaultClassLoader;
}
try {
int id = ObjectIdUtils.identity(businessClassLoader);
/**
* 如果还没有默认的模块业务类加载器,则将默认模块业务类加载器设置成当前请求的业务类加载器
* 返回默认模块类加载器
*/
if (defaultBizClassLoaderRef.compareAndSet(null, id)) {
return defaultClassLoader;
}
/**
* 如果默认的模块业务类加载器与当前请求的业务类加载器一致,则使用默认模块类加载器
*/
if (defaultBizClassLoaderRef.get() == id) {
return defaultClassLoader;
}
ModuleClassLoader moduleClassLoader = this.classLoaderCache.get(id);
if (moduleClassLoader != null) {
return moduleClassLoader;
}
moduleClassLoader = new ModuleClassLoader(classLoaderService, moduleJarFile, moduleId, businessClassLoader == null ? null : businessClassLoader.toString());
ModuleClassLoader oldModuleClassLoader = classLoaderCache.putIfAbsent(id, moduleClassLoader);
if (oldModuleClassLoader != null) {
moduleClassLoader.closeIfPossible();
moduleClassLoader = oldModuleClassLoader;
}
return moduleClassLoader;
} catch (IOException e) {
throw new ModuleRuntimeException("SIMULATOR: getModuleClassLoader err", ModuleRuntimeException.ErrorCode.MODULE_LOAD_ERROR);
}
}
Aggregations