コード例 #1
0
 /**
  * 開啟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;
 }
コード例 #2
0
 /**
  * 關閉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;
 }
コード例 #3
0
 /** 批量关闭World */
 public void batchCloseWorldNew(
     String worldIds, HttpSession session, Map<Integer, List<Integer>> openDispatchIdMap)
     throws Exception {
   System.out.println("worldIds=" + worldIds);
   if (!StringUtils.isEmpty(worldIds)) {
     WorldServerService worldServerService = Application.getBean(WorldServerService.class);
     String[] worldIdArray = worldIds.split(",");
     for (int i = 0; i < worldIdArray.length; i++) {
       System.out.println("worldIdArray[i]=" + worldIdArray[i]);
       Application.getManager()
           .getSimpleThreadPool()
           .execute(
               this.createCloseTaskNew(
                   Integer.valueOf(worldIdArray[i]),
                   session,
                   worldServerService,
                   openDispatchIdMap));
     }
   }
 }
コード例 #4
0
 /**
  * 获取运行结果信息
  *
  * @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;
 }