/** * 获取运行结果信息 * * @author:LKJ */ public String getStdout(Server server, WorldServer worldServer, HttpSession session) throws Exception { boolean successResult = false; boolean exceptionResult = false; String result = ""; Object[] stdResult = SshxcuteUtils.showStdout(server, worldServer.getPath()); String successStr = Global.WORLD_SUCCESS_RESULT; String exceptionStr = "Exception"; if (stdResult != null && stdResult.length > 0 && stdResult[1] != null) { successResult = CommonUtil.Pattern(successStr, stdResult[1].toString()); exceptionResult = CommonUtil.Pattern(exceptionStr, stdResult[1].toString()); } if (exceptionResult) { result = "false"; SystemLogService.worldServerLog( session, ":" + worldServer.getId() + "," + stdResult[1].toString()); } else if (successResult) { result = "true"; CacheService.getWorldServerById(worldServer.getId()).setState(CommanConstant.STATE_START); worldServer.setState(CommanConstant.STATE_START); Application.getBean(WorldServerService.class).update(worldServer); } return result; }
/** * 检测Dispatch是否关闭完成 * * @author:LKJ @2015-3-17 * @param openDispatchIds 要关闭的Dispatch标识号 * @param worldServer 世界服务 * @param server * @param num 循环次数 * @return 返回true时表示已开启的Dispatch服务已经关闭完成 * @throws Exception */ public boolean dispatchCloseIsSuccess( List<Integer> openDispatchIds, WorldServer worldServer, Server server, int num) throws Exception { if (openDispatchIds.size() == 0) { return false; } // System.out.println("=====openDispatchIds.Size====="+openDispatchIds.size()); // System.out.println("=====openDispatchIds1====="+openDispatchIds.get(0)); // System.out.println("=====openDispatchIds2====="+openDispatchIds.get(openDispatchIds.size()-1)); // boolean dispatchCloseIsSuccess = false; // boolean successResult = false; // int number = 0; // if (num > 0) { // number = num; // } // Object[] stdResult = SshxcuteUtils.showStdoutLast(server, worldServer.getPath()); // System.out.println("=====openDispatchIds3====="+openDispatchIds.get(0)); // for (int i = 0; i < openDispatchIds.size(); i++) { // System.out.println("=====openDispatchIdsssss"+i+"====="+openDispatchIds.get(i)); // } // for (int dispatchId : openDispatchIds) { // if (number > 100) { // return false; // } // System.out.println("========================检测Dispatch是否关闭完成number=" + number); // if (stdResult != null && stdResult.length > 0 && stdResult[1] != null) { // successResult = CommonUtil.Pattern(Global.DISPATCH_SUCCESS_CLOSE_RESULT.replace("{0}", // String.valueOf(dispatchId)), stdResult[1].toString()); // if (!successResult) { // Thread.sleep(1000); // ++number; // this.dispatchCloseIsSuccess(openDispatchIds, worldServer, server, number); // } // } else { // Thread.sleep(1000); // ++number; // this.dispatchCloseIsSuccess(openDispatchIds, worldServer, server, number); // } // } boolean dispatchCloseIsSuccess = false; int i = 1; while (true) { if (i == 1) { // dispatch关闭时会停500毫秒 Thread.sleep(600L); } else { Thread.sleep(500L); } Object[] stdResult = SshxcuteUtils.showStdoutLast(server, worldServer.getPath()); if (stdResult != null && stdResult.length > 0 && stdResult[1] != null) { if (CommonUtil.Pattern(Global.ALL_DISPATCH_SUCCESS_CLOSE_RESULT, stdResult[1].toString())) { System.out.println("检测All DispatchServer Is Closed成功"); dispatchCloseIsSuccess = true; break; } } System.out.println("=====================检测All DispatchServer Is Closed:" + i); // 如果两分钟内world还没有关闭完成,则退出检测 if (i >= 240) { break; } i++; } return dispatchCloseIsSuccess; }