Example #1
0
 /** Get a list of all VitroBackgroundThreads that have not died. */
 public static List<VitroBackgroundThread> getLivingThreads() {
   List<VitroBackgroundThread> list = new ArrayList<VitroBackgroundThread>();
   for (VitroBackgroundThread t : getThreads()) {
     if (t.isAlive()) {
       list.add(t);
     }
   }
   return list;
 }
  protected ResponseValues processRequest(VitroRequest vreq) {
    Map<String, Object> body = new HashMap<String, Object>();

    String messageStr = "";
    try {

      Object sr = getServletContext().getAttribute(SimpleReasoner.class.getName());

      if (!(sr instanceof SimpleReasoner)) {
        messageStr = "No SimpleReasoner has been set up.";

      } else {
        SimpleReasoner simpleReasoner = (SimpleReasoner) sr;
        if (simpleReasoner.isABoxReasoningAsynchronous()) {
          messageStr =
              "Reasoning is currently in asynchronous mode so a recompute cannot be started. Please try again later.";
        } else if (simpleReasoner.isRecomputing()) {
          messageStr = "The system is currently in the process of " + "recomputing inferences.";
        } else {
          String submit = (String) vreq.getParameter("submit");
          if (submit != null) {
            VitroBackgroundThread thread =
                new VitroBackgroundThread(
                    new Recomputer((simpleReasoner)),
                    "SimpleReasonerRecomputController.Recomputer");
            thread.setWorkLevel(WORKING);
            thread.start();
            messageStr = "Recompute of inferences started. See log for further details.";
          } else {
            body.put("formAction", UrlBuilder.getUrl("/RecomputeInferences"));
          }
        }
      }

    } catch (Exception e) {
      log.error("Error recomputing inferences with SimpleReasoner", e);
      body.put(
          "errorMessage", "There was an error while recomputing inferences: " + e.getMessage());
      return new ExceptionResponseValues(RECOMPUTE_INFERENCES_FTL, body, e);
    }

    body.put("message", messageStr);
    return new TemplateResponseValues(RECOMPUTE_INFERENCES_FTL, body);
  }