Class IsoClassLoader
java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
cloud.opencode.base.classloader.loader.IsoClassLoader
- All Implemented Interfaces:
Closeable, AutoCloseable
Isolated ClassLoader - Supports independent class loading environment
隔离类加载器 - 支持独立的类加载环境
ClassLoader that supports class isolation for plugin systems and hot deployment.
支持类隔离的类加载器,用于插件系统和热部署。
Features | 主要功能:
- Isolated class loading - 隔离类加载
- Configurable loading strategy - 可配置的加载策略
- Package-level isolation control - 包级别隔离控制
- Resource access - 资源访问
Usage Examples | 使用示例:
IsoClassLoader loader = IsoClassLoader.fromJar("/path/to/plugin.jar")
.addIsolatedPackage("com.plugin")
.build();
Class<?> pluginClass = loader.loadClass("com.plugin.MyPlugin");
loader.close();
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-classloader V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for IsoClassLoader IsoClassLoader 构建器static enumClass loading strategy 类加载策略 -
Method Summary
Modifier and TypeMethodDescriptionbooleanCheck if class can be loaded 检查类是否可加载voidclose()protected Class<?> Find and define a class locally, enforcing bytecode policy checks before defineClass.static IsoClassLoader.BuilderfromDirectory(Path directory) Create builder from directory 从目录创建构建器static IsoClassLoader.BuilderCreate builder from JAR file path string 从 JAR 文件路径字符串创建构建器static IsoClassLoader.BuilderCreate builder from JAR file path 从 JAR 文件路径创建构建器static IsoClassLoader.BuilderCreate builder from URLs 从 URL 创建构建器Get leak detection level 获取泄漏检测级别Get loaded class names 获取已加载的类名Get loader name 获取加载器名称Get class loading policy 获取类加载策略getResource(String name) getResourceAsStream(String name) getResources(String name) booleanisClosed()Check if classloader is closed 检查类加载器是否已关闭Class<?> protected Class<?> Class<?> loadClassLocally(String name) Force load class locally (from this classloader) 强制从本加载器加载类Methods inherited from class URLClassLoader
addURL, definePackage, findResource, findResources, getPermissions, getURLs, newInstance, newInstanceMethods inherited from class SecureClassLoader
defineClass, defineClassMethods inherited from class ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Method Details
-
fromJar
Create builder from JAR file path string 从 JAR 文件路径字符串创建构建器- Parameters:
jarPath- JAR file path | JAR 文件路径- Returns:
- builder | 构建器
-
fromJar
Create builder from JAR file path 从 JAR 文件路径创建构建器- Parameters:
jarPath- JAR file path | JAR 文件路径- Returns:
- builder | 构建器
-
fromDirectory
Create builder from directory 从目录创建构建器- Parameters:
directory- directory path | 目录路径- Returns:
- builder | 构建器
-
fromUrls
Create builder from URLs 从 URL 创建构建器- Parameters:
urls- URLs | URL 数组- Returns:
- builder | 构建器
-
loadClass
- Overrides:
loadClassin classClassLoader- Throws:
ClassNotFoundException
-
loadClass
- Overrides:
loadClassin classClassLoader- Throws:
ClassNotFoundException
-
findClass
Find and define a class locally, enforcing bytecode policy checks before defineClass. 本地查找并定义类,在 defineClass 之前执行字节码策略检查。When a
ClassLoadingPolicyis configured withmaxBytecodeSizeor aBytecodeVerifier, this method reads the raw bytecode, validates it against the policy, and then defines the class. Without a policy (or without bytecode-level constraints), delegates to the parentURLClassLoader.findClass(String).- Overrides:
findClassin classURLClassLoader- Parameters:
name- the binary name of the class | 类的二进制名称- Returns:
- the resulting Class object | 结果 Class 对象
- Throws:
ClassNotFoundException- if the class could not be found | 类未找到时抛出
-
loadClassLocally
Force load class locally (from this classloader) 强制从本加载器加载类- Parameters:
name- class name | 类名- Returns:
- loaded class | 加载的类
- Throws:
ClassNotFoundException- if class not found | 类未找到时抛出
-
canLoad
Check if class can be loaded 检查类是否可加载- Parameters:
className- class name | 类名- Returns:
- true if can load | 可加载返回 true
-
getResource
- Overrides:
getResourcein classClassLoader
-
getResources
- Overrides:
getResourcesin classClassLoader- Throws:
IOException
-
getResourceAsStream
- Overrides:
getResourceAsStreamin classURLClassLoader
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classURLClassLoader
-
isClosed
public boolean isClosed()Check if classloader is closed 检查类加载器是否已关闭- Returns:
- true if closed | 已关闭返回 true
-
getLoadedClassNames
-
getLoaderName
-
getLeakDetection
Get leak detection level 获取泄漏检测级别- Returns:
- leak detection level | 泄漏检测级别
-
getPolicy
Get class loading policy 获取类加载策略- Returns:
- class loading policy, or null if not set | 类加载策略,未设置则为 null
-