/**
  * 获取运行结果信息
  *
  * @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;
 }
 /** 同步远程配置 */
 public boolean synCfgByDeploy(
     BeanInterface beanInterface, BatchOpearVo batchOpearVo, HttpSession session)
     throws Exception {
   boolean result = false;
   WorldServer worldServer = (WorldServer) beanInterface;
   String wildcards = this.getWildcard(worldServer.getId());
   batchOpearVo.setRemark("正在同步:" + Global.CONFIG_WORLD_PROPERTIES + "配置");
   // 更新world配置文件
   Object[] updateResult =
       SshxcuteUtils.synWildcard(beanInterface, wildcards, Global.CONFIG_WORLD_PROPERTIES);
   if (updateResult == null
       || updateResult.length <= 0
       || (Integer) updateResult[0] != CommanConstant.RESULT_TRUE_STATE) {
     batchOpearVo.isFail("更新" + Global.CONFIG_WORLD_PROPERTIES + "失败"); // 失敗
     return result;
   }
   // 更新jdbc配置
   batchOpearVo.setRemark("正在同步:" + Global.CONFIG_WORLD_JDBC + "配置");
   // 获取jdbc路径
   String jdbcPath = CommonUtil.getJdbcPath(session.getAttribute("worldJdbcType").toString());
   // 同步jdbc配置文件
   Object[] updateJdbcResult =
       SshxcuteUtils.synWildcard(beanInterface, jdbcPath, Global.CONFIG_WORLD_JDBC);
   if (updateJdbcResult == null
       || updateJdbcResult.length <= 0
       || (Integer) updateJdbcResult[0] != CommanConstant.RESULT_TRUE_STATE) {
     batchOpearVo.isFail("更新" + Global.CONFIG_WORLD_JDBC + "失败"); // 失敗
     return result;
   }
   // 更新run.sh配置
   batchOpearVo.setRemark("正在同步:" + Global.CONFIG_WORLD_RUN + "配置");
   // 获取run
   String run = "";
   if ("1".equals(session.getAttribute("worldMemory").toString())) {
     run = Global.RUN_1G;
   } else if ("2".equals(session.getAttribute("worldMemory").toString())) {
     run = Global.RUN_2G;
   } else if ("4".equals(session.getAttribute("worldMemory").toString())) {
     run = Global.RUN_4G;
   } else if ("6".equals(session.getAttribute("worldMemory").toString())) {
     run = Global.RUN_6G;
   }
   // 同步run.sh配置文件
   Object[] updateRunResult =
       SshxcuteUtils.synWildcard(beanInterface, run, Global.CONFIG_WORLD_RUN);
   if (updateRunResult == null
       || updateRunResult.length <= 0
       || (Integer) updateRunResult[0] != CommanConstant.RESULT_TRUE_STATE) {
     batchOpearVo.isFail("更新" + Global.CONFIG_WORLD_RUN + "失败"); // 失敗
     return result;
   }
   batchOpearVo.setRemark("正在同步:" + Global.CONFIG_WORLD_VERSION + "配置");
   // 更新version.xml文件
   Object[] updateVersionResult =
       SshxcuteUtils.synWildcard(
           beanInterface, worldServer.getMachinecode().toString(), Global.CONFIG_WORLD_VERSION);
   if (updateVersionResult == null
       || updateVersionResult.length <= 0
       || (Integer) updateVersionResult[0] != CommanConstant.RESULT_TRUE_STATE) {
     batchOpearVo.isFail("更新" + Global.CONFIG_WORLD_VERSION + "失败"); // 失敗
     return result;
   } else {
     result = true;
   }
   return result;
 }