Example usage for weka.experiment TaskStatusInfo FINISHED

List of usage examples for weka.experiment TaskStatusInfo FINISHED

Introduction

In this page you can find the example usage for weka.experiment TaskStatusInfo FINISHED.

Prototype

int FINISHED

To view the source code for weka.experiment TaskStatusInfo FINISHED.

Click Source Link

Usage

From source file:core.utils.ui.RemoteEngine.java

License:Open Source License

/**
 * Returns status information on a particular task
 *
 * @param taskId the ID of the task to check
 * @return a <code>TaskStatusInfo</code> encapsulating task status info
 * @exception Exception if an error occurs
 *//*from   ww w .ja  v a  2 s  . c om*/
public Object checkStatus(Object taskId) throws Exception {

    TaskStatusInfo inf = (TaskStatusInfo) m_TaskStatus.get(taskId);

    if (inf == null) {
        throw new Exception("RemoteEngine (" + m_HostName + ") : Task not found.");
    }

    TaskStatusInfo result = new TaskStatusInfo();
    result.setExecutionStatus(inf.getExecutionStatus());
    result.setStatusMessage(inf.getStatusMessage());
    result.setTaskResult(inf.getTaskResult());

    if (inf.getExecutionStatus() == TaskStatusInfo.FINISHED
            || inf.getExecutionStatus() == TaskStatusInfo.FAILED) {
        System.err.println("Finished/failed Task id : " + taskId + " checked by client. Removing.");
        inf.setTaskResult(null);
        inf = null;
        m_TaskStatus.remove(taskId);
    }
    inf = null;
    return result;
}

From source file:core.utils.ui.RemoteEngine.java

License:Open Source License

/**
 * Checks the hash table for failed/finished tasks. Any that have been
 * around for an @seeCLEANUPTIMEOUT or more are removed. Clients are expected to check
 * on the status of their remote tasks. Checking on the status of a
 * finished/failed task will remove it from the hash table, therefore
 * any failed/finished tasks left lying around for more than an hour
 * suggest that their client has died../*from  w  ww.  j a v a 2  s.c  om*/
 *
 */
private void purge() {
    Enumeration keys = m_TaskStatus.keys();
    long currentTime = System.currentTimeMillis();
    System.err.println("RemoteEngine purge. Current time : " + currentTime);
    while (keys.hasMoreElements()) {
        String taskId = (String) keys.nextElement();
        System.err.print("Examining task id : " + taskId + "... ");
        String timeString = taskId.substring(0, taskId.indexOf(':'));
        long ts = Long.valueOf(timeString).longValue();
        if (currentTime - ts > CLEANUPTIMEOUT) {
            TaskStatusInfo tsi = (TaskStatusInfo) m_TaskStatus.get(taskId);
            if ((tsi != null) && (tsi.getExecutionStatus() == TaskStatusInfo.FINISHED
                    || tsi.getExecutionStatus() == TaskStatusInfo.FAILED)) {
                System.err.println("\nTask id : " + taskId + " has gone stale. Removing.");
                m_TaskStatus.remove(taskId);
                tsi.setTaskResult(null);
                tsi = null;
            }
        } else {
            System.err.println("ok.");
        }
    }
    if (m_TaskStatus.size() == 0) {
        purgeClasses();
    }
}

From source file:milk.experiment.MIRemoteExperiment.java

License:Open Source License

/**
   * Launch a sub experiment on a remote host
   * @param wexp the index of the sub experiment to launch
   * @param ah the index of the available host to launch on
   *//* ww  w. j  a  v  a  2  s .co m*/
  public void launchNext(final int wexp, final int ah) {

      Thread subExpThread;
      subExpThread = new Thread() {
          public void run() {
              m_remoteHostsStatus[ah] = IN_USE;
              m_subExpComplete[wexp] = TaskStatusInfo.PROCESSING;
              MIRemoteExperimentSubTask expSubTsk = new MIRemoteExperimentSubTask();
              expSubTsk.setExperiment(m_subExperiments[wexp]);
              String subTaskType = (getSplitByDataSet())
                      ? "dataset :" + ((File) m_subExperiments[wexp].getDatasets().elementAt(0)).getName()
                      : "run :" + m_subExperiments[wexp].getRunLower();
              try {
                  String name = "//" + ((String) m_remoteHosts.elementAt(ah)) + "/RemoteEngine";
                  Compute comp = (Compute) Naming.lookup(name);
                  // assess the status of the sub-exp
                  notifyListeners(false, true, false,
                          "Starting " + subTaskType + " on host " + ((String) m_remoteHosts.elementAt(ah)));
                  Object subTaskId = comp.executeTask(expSubTsk);
                  boolean finished = false;
                  TaskStatusInfo is = null;
                  while (!finished) {
                      try {
                          Thread.sleep(2000);

                          TaskStatusInfo cs = (TaskStatusInfo) comp.checkStatus(subTaskId);
                          if (cs.getExecutionStatus() == TaskStatusInfo.FINISHED) {
                              // push host back onto queue and try launching any waiting 
                              // sub-experiments
                              notifyListeners(false, true, false, cs.getStatusMessage());
                              m_remoteHostsStatus[ah] = AVAILABLE;
                              incrementFinished();
                              availableHost(ah);
                              finished = true;
                          } else if (cs.getExecutionStatus() == TaskStatusInfo.FAILED) {
                              // a non connection related error---possibly host doesn't have
                              // access to data sets or security policy is not set up
                              // correctly or classifier(s) failed for some reason
                              notifyListeners(false, true, false, cs.getStatusMessage());
                              m_remoteHostsStatus[ah] = SOME_OTHER_FAILURE;
                              m_subExpComplete[wexp] = TaskStatusInfo.FAILED;
                              notifyListeners(false, true, false, subTaskType + " " + cs.getStatusMessage()
                                      + ". Scheduling for execution on another host.");
                              incrementFailed(ah);
                              // push experiment back onto queue
                              waitingExperiment(wexp);
                              // push host back onto queue and try launching any waiting 
                              // sub-experiments. Host is pushed back on the queue as the
                              // failure may be temporary---eg. with InstantDB using the
                              // RMI bridge, two or more threads may try to create the
                              // experiment index or results table simultaneously; all but
                              // one will throw an exception. These hosts are still usable
                              // however.
                              availableHost(ah);
                              finished = true;
                          } else {
                              if (is == null) {
                                  is = cs;
                                  notifyListeners(false, true, false, cs.getStatusMessage());
                              } else {
                                  if (cs.getStatusMessage().compareTo(is.getStatusMessage()) != 0) {

                                      notifyListeners(false, true, false, cs.getStatusMessage());
                                  }
                                  is = cs;
                              }
                          }
                      } catch (InterruptedException ie) {
                      }
                  }

              } catch (Exception ce) {
                  m_remoteHostsStatus[ah] = CONNECTION_FAILED;
                  m_subExpComplete[wexp] = TaskStatusInfo.TO_BE_RUN;
                  System.err.println(ce);
                  ce.printStackTrace();
                  notifyListeners(false, true, false, "Connection to " + ((String) m_remoteHosts.elementAt(ah))
                          + " failed. Scheduling " + subTaskType + " for execution on another host.");
                  checkForAllFailedHosts();
                  waitingExperiment(wexp);
              } finally {
                  if (isInterrupted()) {
                      System.err.println("Sub exp Interupted!");
                  }
              }
          }
      };
      subExpThread.setPriority(Thread.MIN_PRIORITY);
      subExpThread.start();
  }

From source file:milk.experiment.MIRemoteExperimentSubTask.java

License:Open Source License

/**
 * Run the experiment//from w w w  . j a v  a 2 s  .co  m
 */
public void execute() {
    //      FastVector result = new FastVector();
    m_result = new TaskStatusInfo();
    m_result.setStatusMessage("Running...");
    String goodResult = "(sub)experiment completed successfully";
    String subTaskType;
    if (m_experiment.getRunLower() != m_experiment.getRunUpper()) {
        subTaskType = "(datataset " + ((File) m_experiment.getDatasets().elementAt(0)).getName();
    } else {
        subTaskType = "(exp run # " + m_experiment.getRunLower();
    }
    try {
        System.err.println("Initializing " + subTaskType + ")...");
        m_experiment.initialize();
        System.err.println("Iterating " + subTaskType + ")...");
        m_experiment.runExperiment();
        System.err.println("Postprocessing " + subTaskType + ")...");
        m_experiment.postProcess();
    } catch (Exception ex) {
        ex.printStackTrace();
        String badResult = "(sub)experiment " + subTaskType + ") failed : " + ex.toString();
        m_result.setExecutionStatus(TaskStatusInfo.FAILED);
        //   m_result.addElement(new Integer(RemoteExperiment.FAILED));
        //   m_result.addElement(badResult);
        m_result.setStatusMessage(badResult);
        m_result.setTaskResult("Failed");
        //      return m_result;
        return;
    }
    //      m_result.addElement(new Integer(RemoteExperiment.FINISHED));
    //      m_result.addElement(goodResult);
    m_result.setExecutionStatus(TaskStatusInfo.FINISHED);
    m_result.setStatusMessage(goodResult + " " + subTaskType + ").");
    m_result.setTaskResult("No errors");
    //    return m_result;
}