/**
  * 關閉world
  *
  * @param batchOpearVo 操作vo
  * @param dispatchServerIds 已開啟的dispatch服務Id
  * @param worldId worldID
  */
 public boolean closeWorld(
     BatchOpearVo batchOpearVo,
     WorldServer worldServer,
     List<Integer> dispatchServerIds,
     ServerService serverService)
     throws Exception {
   boolean closeResult = false;
   batchOpearVo.setRemark(worldServer.getName() + "正在关闭");
   WorldServerService worldServerService = Application.getBean(WorldServerService.class);
   Server server = serverService.get(worldServer.getServerId());
   // worldServer已关闭的情况
   if (worldServer.getState() == CommanConstant.STATE_STOP) {
     boolean result =
         SshxcuteUtils.progressIsExistNew(server, worldServer.getPath(), Global.WORLD_PID_FILE);
     if (!result) {
       return true;
     }
   }
   if (dispatchServerIds != null && dispatchServerIds.size() > 0) {
     // System.out.println("=====dispatchServerIds=====" + dispatchServerIds.toArray().toString());
     boolean dispatchCloseIsSuccess =
         worldServerService.dispatchCloseIsSuccess(
             dispatchServerIds, worldServer, server, CommanConstant.STATE_STOP);
     // 检测Dispatch服务是否关闭完成,若未完成则不关闭world服务
     if (!dispatchCloseIsSuccess) {
       batchOpearVo.isFail("分发服关闭未完成,请关闭再试");
       return closeResult;
     }
   }
   Object[] killResult = SshxcuteUtils.killExec(server, worldServer.getPath());
   if (killResult != null
       && killResult.length > 0
       && (Integer) killResult[0] != CommanConstant.RESULT_TRUE_STATE) {
     batchOpearVo.isFail(worldServer.getName() + "world关闭出错");
     return closeResult;
   }
   worldServer.setState(CommanConstant.STATE_STOP);
   worldServerService.update(worldServer);
   CacheService.getWorldServerById(worldServer.getId()).setState(CommanConstant.STATE_STOP);
   batchOpearVo.isSUCCESS(worldServer.getName() + "world关闭成功");
   closeResult = true;
   return closeResult;
 }
 @Override
 public void run() {
   try {
     batchOpearVo.setRemark("正在同步:" + Global.CONFIG_WORLD_VERSION + "配置");
     // 更新version.xml文件
     Object[] updateVersionResult =
         SshxcuteUtils.synWildcard(
             worldServer, worldServer.getMachinecode().toString(), fileName);
     if (updateVersionResult == null
         || updateVersionResult.length <= 0
         || (Integer) updateVersionResult[0] != CommanConstant.RESULT_TRUE_STATE) {
       batchOpearVo.isFail("更新" + Global.CONFIG_WORLD_VERSION + "失败"); // 失敗
     } else {
       batchOpearVo.isSUCCESS("更新" + Global.CONFIG_WORLD_VERSION + "成功");
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 public void synVersion(HttpSession session, String ids, String fileName) {
   String[] beanIds = ids.split(",");
   session.removeAttribute(Global.BATCH_UPDATE_REMOTE_CFG);
   session.removeAttribute(Global.UPDATE_CFG_BEAN_LIST);
   List<BeanInterface> beanInterfaceList = new ArrayList<BeanInterface>();
   List<BatchOpearVo> batchOpearVoList = new ArrayList<BatchOpearVo>();
   BatchOpearVo batchOpearVo = null;
   for (int i = 0; i < beanIds.length; i++) {
     batchOpearVo = new BatchOpearVo();
     batchOpearVo.setId(Integer.valueOf(beanIds[i]));
     batchOpearVo.setRemark("开始更新");
     System.out.println("更新" + beanIds[i]);
     // 更新文件操作
     Application.getManager()
         .getSimpleThreadPool()
         .execute(
             this.createSynVersionTask(
                 session, this.get(Integer.valueOf(beanIds[i])), batchOpearVo, fileName));
     beanInterfaceList.add(this.get(Integer.valueOf(beanIds[i])));
     batchOpearVoList.add(batchOpearVo);
   }
   session.setAttribute(Global.BATCH_UPDATE_REMOTE_CFG, batchOpearVoList);
   session.setAttribute(Global.UPDATE_CFG_BEAN_LIST, beanInterfaceList);
 }
 /**
  * 開啟world服務
  *
  * @param batchOpearVo 操作vo
  * @param worldServer world服務
  * @param session HttpSession
  */
 public boolean startWorld(
     BatchOpearVo batchOpearVo,
     WorldServer worldServer,
     HttpSession session,
     ServerService serverService)
     throws Exception {
   boolean startResult = false;
   batchOpearVo.setRemark(worldServer.getName() + "正在开启");
   WorldServerService worldServerService = Application.getBean(WorldServerService.class);
   Server server = serverService.get(worldServer.getServerId());
   // 判断world是否已开启
   boolean result =
       SshxcuteUtils.progressIsExistNew(server, worldServer.getPath(), Global.WORLD_PID_FILE);
   if (result) {
     batchOpearVo.isFail(worldServer.getName() + "服务已启动,请关闭重启");
     return startResult;
   }
   Object[] runResult = SshxcuteUtils.runExec(server, worldServer.getPath());
   // 启动服务出错,关闭服务
   if (runResult != null
       && runResult.length > 0
       && (Integer) runResult[0] != CommanConstant.RESULT_TRUE_STATE) {
     batchOpearVo.isFail(worldServer.getName() + "world启动出错");
     SshxcuteUtils.killExec(server, worldServer.getPath());
     return startResult;
   }
   int i = 0;
   while (true) {
     if (i == 0) {
       Thread.sleep(4000L);
     } else {
       Thread.sleep(500L);
     }
     if (i >= 120) {
       batchOpearVo.isFail(worldServer.getName() + "world启动超时");
       break;
     }
     Boolean bResult =
         SshxcuteUtils.getBatchStdout(
             session, worldServer, worldServerService, Global.WORLD_SUCCESS_RESULT);
     if (bResult != null) {
       if (bResult) {
         batchOpearVo.isSUCCESS(worldServer.getName() + "world启动成功");
         startResult = true;
       } else {
         batchOpearVo.isFail(worldServer.getName() + "world启动失败");
         SshxcuteUtils.killExec(server, worldServer.getPath());
       }
       break;
     }
     System.out.println("============check start world " + worldServer.getName() + " => " + i);
     i++;
   }
   return startResult;
 }
 /** 同步远程配置 */
 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;
 }