use of com.shulie.instrument.simulator.core.CoreModule in project LinkAgent by shulieTech.
the class DefaultCoreModuleManager method forceFlush.
/**
* 强制刷新
* 对所有已经加载的用户模块进行强行卸载并重新加载
*
* @throws ModuleException 模块操作失败
*/
private void forceFlush() throws ModuleException {
if (isInfoEnabled) {
logger.info("SIMULATOR: force-flushing modules:{}", loadedModuleMap.keySet());
}
// 1. 卸载模块
// 等待卸载的模块集合
final Collection<CoreModule> waitingUnloadCoreModules = new ArrayList<CoreModule>();
// 找出所有USER的模块,所以这些模块都卸载了
for (final CoreModule coreModule : loadedModuleMap.values()) {
// 如果判断是属于USER模块目录下的模块,则加入到待卸载模块集合,稍后统一进行卸载
if (!isSystemModule(coreModule.getJarFile())) {
waitingUnloadCoreModules.add(coreModule);
}
}
// 记录下即将被卸载的模块ID集合
if (isInfoEnabled) {
final Set<String> moduleIds = new LinkedHashSet<String>();
for (final CoreModule coreModule : waitingUnloadCoreModules) {
moduleIds.add(coreModule.getModuleId());
}
if (isInfoEnabled) {
logger.info("SIMULATOR: force-flush modules: will be unloading modules : {}", moduleIds);
}
}
// 强制卸载掉所有等待卸载的模块集合中的模块
for (final CoreModule coreModule : waitingUnloadCoreModules) {
unload(coreModule, true);
}
// 2. 加载模块
// 用户模块加载目录,加载用户模块目录下的所有模块
// 对模块访问权限进行校验
// 用户模块目录
List<File> userModuleLibJars = getAllModuleLibJar(userModuleLibs);
List<ModuleSpec> userModuleSpecs = ModuleSpecUtils.loadModuleSpecs(userModuleLibJars, false);
loadModules(userModuleSpecs, "force-flush");
}
use of com.shulie.instrument.simulator.core.CoreModule in project LinkAgent by shulieTech.
the class DefaultModuleManager method unload.
@Override
public void unload(String moduleId) throws ModuleException {
final CoreModule coreModule = coreModuleManager.getThrowsExceptionIfNull(moduleId);
coreModuleManager.unload(coreModule, false);
}
use of com.shulie.instrument.simulator.core.CoreModule in project LinkAgent by shulieTech.
the class DefaultCoreModuleManager method unloadAll.
@Override
public void unloadAll() {
if (isInfoEnabled) {
logger.info("SIMULATOR: force unloading all loaded modules:{}", loadedModuleMap.keySet());
}
// 先卸载所有有开关依赖的模块
List<CoreModule> modules = new ArrayList<CoreModule>(loadedModuleMap.values());
List<CoreModule> userModules = new ArrayList<CoreModule>();
List<CoreModule> systemModules = new ArrayList<CoreModule>();
for (CoreModule coreModule : modules) {
if (coreModule.getModuleSpec().isSystemModule()) {
systemModules.add(coreModule);
} else {
userModules.add(coreModule);
}
}
// uninstall user modules first
uninstall(userModules);
uninstall(systemModules);
}
use of com.shulie.instrument.simulator.core.CoreModule in project LinkAgent by shulieTech.
the class DefaultModuleCommandInvoker method invokeCommand.
@Override
public <T> CommandResponse<T> invokeCommand(final String moduleId, String command, Map<String, String> args) {
final CoreModule coreModule = coreModuleManager.get(moduleId);
if (coreModule == null) {
throw new ModuleRuntimeException(moduleId, ModuleRuntimeException.ErrorCode.MODULE_NOT_EXISTED);
}
// 匹配对应的方法
final Method method = matchingModuleMethod(command, coreModule.getModule().getClass());
if (method == null) {
throw new ModuleRuntimeException(moduleId, ModuleRuntimeException.ErrorCode.MODULE_COMMAND_NOT_EXISTED);
}
// 自动释放I/O资源
final List<Closeable> autoCloseResources = coreModule.append(new ReleaseResource<List<Closeable>>(new ArrayList<Closeable>()) {
@Override
public void release() {
final List<Closeable> closeables = get();
if (CollectionUtils.isEmpty(closeables)) {
return;
}
for (final Closeable closeable : get()) {
if (closeable instanceof Flushable) {
try {
((Flushable) closeable).flush();
} catch (Exception cause) {
logger.warn("SIMULATOR: moduleId={} flush I/O occur error!", moduleId, cause);
}
}
try {
closeable.close();
} catch (IOException e) {
}
}
}
});
// 生成方法调用参数
final Object[] parameterObjectArray = generateParameterObjectArray(method, args);
final boolean isAccessible = method.isAccessible();
final ClassLoader oriThreadContextClassLoader = Thread.currentThread().getContextClassLoader();
try {
method.setAccessible(true);
Thread.currentThread().setContextClassLoader(coreModule.getClassLoaderFactory().getDefaultClassLoader());
Object value = method.invoke(coreModule.getModule(), parameterObjectArray);
if (logger.isDebugEnabled()) {
logger.debug("SIMULATOR: invoke module {} method {} success.", moduleId, method.getName());
}
return (CommandResponse) value;
} catch (IllegalAccessException iae) {
logger.warn("SIMULATOR: invoke module {} method {} occur access denied.", moduleId, method.getName(), iae);
throw new SimulatorException(iae);
} catch (InvocationTargetException ite) {
logger.warn("SIMULATOR: invoke module {} method {} occur error.", moduleId, method.getName(), ite.getTargetException());
final Throwable targetCause = ite.getTargetException();
throw new SimulatorException(targetCause);
} finally {
Thread.currentThread().setContextClassLoader(oriThreadContextClassLoader);
method.setAccessible(isAccessible);
coreModule.release(autoCloseResources);
}
}
use of com.shulie.instrument.simulator.core.CoreModule in project LinkAgent by shulieTech.
the class DefaultModuleManager method frozen.
@Override
public void frozen(String moduleId) throws ModuleException {
final CoreModule coreModule = coreModuleManager.getThrowsExceptionIfNull(moduleId);
coreModuleManager.frozen(coreModule, false);
}
Aggregations