Esempio n. 1
0
  /**
   * inform the server about the fail
   *
   * @param e1 - uncatch exception
   * @param conf - agnet configration
   * @param net - the communicate module for sending the task
   */
  private static void unCatchException(AgentServiceException e1, AgentServiceConf conf) {
    // error while parsing send acknowledgment to the server

    Communicate net;
    try {
      net = new Communicate();
    } catch (AgentServiceException e3) {
      // the agent will be dead without notice to server because problem in connection
      return;
    }
    String errorMsg =
        conf.getAgentName() + "- Unexpected error : " + e1.getMessage() + "\n" + "agent fall - RIP";

    ACK ack = new ACK();
    ack.setOK(false);
    ack.setErrorMsg(errorMsg);
    ack.setFullExceptionString(ExceptionHelper.getCustomStackTrace(e1));
    try {
      net.sendResponse(ack, conf);
    } catch (AgentServiceException e) {
      // try again
      try {
        net.sendResponse(ack, conf);
      } catch (AgentServiceException e2) {
      }
    }
  }
Esempio n. 2
0
  /**
   * go on loop : 1.ask the server for tasks 2. execute the tasks 3. sleep x time
   *
   * @param args
   * @throws Exception
   */
  public static void main(String[] args) {

    AgentServiceLogger logger = AgentServiceLogger.getInstance();
    logger.init();

    // get the configuration  of the agent service
    try {
      getConf();

      Communicate net = new Communicate();

      // install all models
      Parser parser = new Parser();
      ImplementorManager impManager = ImplementorManager.getInstance();

      // run for ever
      while (true) {

        // get and updates from the net
        String updates = net.getNewTasks();

        if (updates != null && !updates.equals("null")) {
          ArrayList<Message> messages = null;

          // parse the string message that get from the server
          try {
            messages = parser.parseMessage(updates);
          } catch (Exception e) {
            // error while parsing send acknowledgment to the server
            ACK ack = new ACK();
            ack.setOK(false);
            ack.setErrorMsg("problem to parse update string -" + updates);
            ack.setFullExceptionString(ExceptionHelper.getCustomStackTrace(e));
            ack.setTaskId("0");
            net.sendResponse(ack, conf);
          }

          // commit all the tasks
          if (messages != null) {
            for (Message msg : messages) {
              ACK retMsg = impManager.commitTask(msg);
              net.sendResponse(retMsg);
            }
          }
        } // end of if(updates!=null)

        // commit all task
        try {
          Thread.sleep(conf.getSleepTime() * 1000);
        } catch (InterruptedException e) {
        }
      } // end of while(true)

    } catch (AgentServiceException e1) {
      unCatchException(e1, conf);
    }
  }