use of com.shulie.instrument.simulator.api.CommandResponse in project LinkAgent by shulieTech.
the class ConfigFetcherModule method getSimulatorDetail.
/**
* 获取simulator配置的接口,目前只获取静默开关状态
* @param args
* @return
*/
@Command("getSimulatorDetail")
public CommandResponse<Object> getSimulatorDetail(Map<String, String> args) {
SimulatorDetail simulatorDetail = new SimulatorDetail();
simulatorDetail.setIsSilent(PradarSwitcher.silenceSwitchOn() == true ? 1 : 0);
CommandResponse<Object> commandResponse = new CommandResponse<Object>();
commandResponse.setSuccess(true);
commandResponse.setResult(simulatorDetail);
return commandResponse;
}
use of com.shulie.instrument.simulator.api.CommandResponse in project LinkAgent by shulieTech.
the class ModuleHttpServlet method doResponse.
private void doResponse(Object content, HttpServletRequest req, HttpServletResponse resp) throws IOException {
String useApi = StringUtils.trim(req.getParameter("useApi"));
PrintWriter writer = resp.getWriter();
try {
if (Boolean.valueOf(useApi)) {
String json = JSON.toJSONString(content, SerializerFeature.DisableCircularReferenceDetect);
resp.setContentType("application/json");
writer.write(json);
writer.flush();
} else {
if (content instanceof CommandResponse) {
CommandResponse commandResponse = (CommandResponse) content;
if (commandResponse.isSuccess()) {
writer.write(commandResponse.getResult() == null ? "" : commandResponse.getResult().toString());
} else {
writer.write(commandResponse.getMessage() == null ? "" : commandResponse.getMessage());
}
} else {
writer.write(content == null ? "" : content.toString());
}
}
} finally {
writer.flush();
writer.close();
}
}
use of com.shulie.instrument.simulator.api.CommandResponse in project LinkAgent by shulieTech.
the class ThreadModule method processBlockingThread.
private CommandResponse processBlockingThread(Integer samplingInterval) {
ThreadUtil.BlockingLockInfo blockingLockInfo = ThreadUtil.findMostBlockingLock();
if (blockingLockInfo.threadInfo == null) {
CommandResponse commandResponse = new CommandResponse();
commandResponse.setSuccess(false);
commandResponse.setMessage("No most blocking thread found!\n");
return commandResponse;
} else {
CommandResponse commandResponse = new CommandResponse();
commandResponse.setSuccess(true);
Map<Long, ThreadStat> allThreadStats = ThreadUtil.getAllThreadStats(samplingInterval);
commandResponse.setResult(ThreadUtil.getThreadInfo(blockingLockInfo, allThreadStats.get(blockingLockInfo.threadInfo.getThreadId())));
return commandResponse;
}
}
use of com.shulie.instrument.simulator.api.CommandResponse 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);
}
}
Aggregations